Main Content

makedbfspec

Create DBF specification

Description

example

dbfspec = makedbfspec(S) creates a DBF specification for use with the shapewrite function based on the vector geographic features stored in S.

The shapewrite function creates a main file (.shp), an index file (.shx), and an attribute file (.dbf). Use a DBF specification with the shapewrite function and DbfSpec name-value argument to specify which attribute fields to include in the DBF file, the length of each field, and the numerical precision of each field.

Examples

collapse all

Import a shapefile representing a network of road segments in Concord, MA, as a geospatial table. Create a DBF specification from the table.

GT = readgeotable("concord_roads.shp");
dbfspec = makedbfspec(GT)
dbfspec = struct with fields:
    STREETNAME: [1x1 struct]
     RT_NUMBER: [1x1 struct]
         CLASS: [1x1 struct]
    ADMIN_TYPE: [1x1 struct]
        LENGTH: [1x1 struct]

Remove the ADMIN_TYPE field from the specification, rename the STREETNAME field to Street Name, and reduce the number of decimal places used to store road lengths.

dbfspec = rmfield(dbfspec,"ADMIN_TYPE");
dbfspec.STREETNAME.FieldName = "Street Name";
dbfspec.LENGTH.FieldDecimalCount = 1;

Export the road network to a new shapefile.

shapewrite(GT,"concord_roads_new.shp","DbfSpec",dbfspec)

Input Arguments

collapse all

Vector geographic features, specified as one of these:

  • A geospatial table. The makedbfspec function does not support geospatial tables containing more than one type of shape object. For more information about geospatial tables, see Create Geospatial Tables.

  • A mappoint vector.

  • A mapshape vector.

  • A map structure array (mapstruct) with X and Y coordinate fields.

  • A geopoint vector.

  • A geoshape vector.

  • A geographic structure array (geostruct) with Lat and Lon fields.

Output Arguments

collapse all

DBF specification, returned as a structure array with two levels. The top level contains a field for each attribute in S. Each field in the top level contains a scalar structure with four fields.

Field

Description

FieldName

Field name for the shapewrite function to use in the DBF file. By default, the field name is identical to the name of the corresponding attribute.

FieldType

Field type for the shapewrite function to use in the DBF file, specified as 'N' (numeric) or 'C' (character).

FieldLength

Number of bytes each instance of the field occupies in the file.

FieldDecimalCount

Number of digits to the right of the decimal place. Specify the number of digits as 0 for integer-valued fields and character fields. The default value for noninteger numeric fields is 6.

You can change the structure array before using it with the shapewrite function. For example, you can remove attributes from the structure or change the FieldName field to include spaces.

Version History

Introduced before R2006a

expand all

See Also

Functions