Skip to Main Content Skip to Search
Product Documentation

shapewrite - Write geographic data structure to shapefile

Syntax

shapewrite(S, filename)
shapewrite(S, filename, 'DbfSpec', dbfspec)

Description

shapewrite(S, filename) writes a geographic data structure to disk in shapefile format. shapewrite creates three output files: [basename '.shp'], [basename '.shx'], and [basename '.dbf'], where basename is filename without its extension. If a given attribute is integer-valued for all features, then it is written to the [basename '.dbf'] file as an integer. If an attribute is non-integer-valued for any feature, then it is written as a fixed point decimal value with six digits to the right of the decimal place.

shapewrite(S, filename, 'DbfSpec', dbfspec) writes a shapefile in which the content and layout of the DBF file is controlled by a DBF specification, indicated here by the parameter value dbfspec.

Tips

Input Arguments

S

A valid mapstruct or geostruct with specific restrictions on its attribute fields:

  • Each attribute field value must be either a real, finite, scalar double or a character string.

  • The type of a given attribute must be consistent across all features.

filename

A character string specifying the output file name and location. If an extension is included, it must be '.shp' or '.SHP'.

'DbfSpec', dbfspec

A scalar MATLAB structure containing one field for each feature attribute to be included in the output shapefile. To include an attribute in the output, provide a field in dbfspec with a name identical to the attribute name as given in S. Assign to that field a scalar structure with the following four fields:

  • FieldName — The field name to be used in the file

  • FieldType — The field type to be used in the file ('N' or 'C')

  • FieldLength — The field length in the file, in bytes

  • FieldDecimalCount — For numeric fields, the number of digits to the right of the decimal place

Call makedbfspec to construct a DBF spec. Modify the output to remove attributes or change the FieldName, FieldLength, or FieldDecimalCount for one or more attributes.

Examples

Derive a shapefile from concord_roads.shp in which roads of CLASS 5 and greater are omitted. Note the use of the 'Selector' option in shaperead, together with an anonymous function, to read only the main roads from the original shapefile.

shapeinfo('concord_roads')  % 609 features

ans = 
       Filename: [3x67 char]
      ShapeType: 'PolyLine'
    BoundingBox: [2x2 double]
    NumFeatures: 609
     Attributes: [5x1 struct]

S = shaperead('concord_roads', 'Selector', ...
    {@(roadclass) roadclass < 4, 'CLASS'});
shapewrite(S, 'main_concord_roads.shp')
shapeinfo('main_concord_roads')  % 107 features

ans = 
       Filename: [3x24 char]
      ShapeType: 'PolyLine'
    BoundingBox: [2x2 double]
    NumFeatures: 107
     Attributes: [5x1 struct]

See Also

makedbfspec | shapeinfo | shaperead

How To

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS