| Mapping Toolbox™ | ![]() |
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:
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 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,
[basename '.shp']
[basename '.shx']
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 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:
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
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.
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.
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]makedbfspec, shapeinfo, shaperead, updategeostruct
![]() | shaperead | showaxes | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |