shapewrite - Write geographic data structure to shapefile

Syntax

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

shapewrite(S, filename) writes a geographic data structure to disk in shapefile format. S must be a valid mapstruct or geostruct with specific restrictions on its attribute fields:

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

shapewrite creates three output files,

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 noninteger 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. A DBF specification is a scalar MATLAB® structure with one field for each feature attribute to be included in the output shapefile. To include an attribute in the output, make sure to provide a field in dbfspec with a field name identical to the attribute name (the corresponding field name in S), and assign to that field a scalar structure with the following four fields:

When a DBF spec is provided, a given attribute will be included in the output file only if it matches the name of a field in the spec.

The easiest way to construct a DBF spec is to call makedbfspec, then modify the output to remove attributes or change the FieldName, FieldLength, or FieldDecimalCount for one or more attributes. See the help for makedbfspec for more details and an example.

Remarks

geostruct and mapstruct attribute names that are longer than 11 characters are truncated to 11 characters in copying as DBF field names in order to adhere to dBASE (.dbf) file specifications. Consider shortening long field names in your data structure before calling shapewrite to make field names in the DBF file more readable and to avoid introducing duplicate names as a result of truncation.

Example

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, updategeostruct

  


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