Function File: status = shapewrite (shpstr, fname)
Function File: status = shapewrite (shpstr, fname, atts)

Write contents of map- or geostruct to a GIS shape file.

shpstr must be a valid mapstruct or geostruct, a struct array with an entry for each shape feature, with fields Geometry, BoundingBox, and X and Y (mapstruct) or Lat and Lon (geostruct). For geostructs, Lat and Lon field data will be written as X and Y data. Field Geometry can have data values of "Point", "MultiPoint", "Line" or "Polygon", all case-insensitive. For each shape feature, field BoundingBox should contain the minimum and maximum (X,Y) coordinates in a 2x2 array [minX, minY; maxX, maxY]. The X and Y fields should contain X (or Latitude) and Y (or Longitude) coordinates for each point or vertex as row vectors; for poly(lines) and polygons vertices of each subfeature (if present) should be separated by NaN entries.

<Geometry>M or <Geometry>Z types (e.g., PointM, PolygonZ) can also be written; shapewrite.m just checks if fields "M" and/or "Z" are present in input mapstruct.

fname should be a valid shape file name, optionally with a ’.shp’ suffix.

Optional third input argument atts is one attribute name or a cellstr array containing a list of attribute names; only those attributes will be written to the .dbf file. Alternatively a struct can be supplied with attibute names contained in field "FieldName" (preferrably camelcased as shown, but Octave treats this field’s name as case-insensitive). If argument atts is omitted all attributes will be written to the shapefile.

shapewrite produces 3 files, i.e. a .shp file (the actual shape file), a .shx file (index file), and a .dbf file (dBase type 3) with the contents of additional attribute fields other than Geometry, X/Y or Lat/Lon, M, Z, and BoundingBox. If no additional attributes are present, a .dbf file is created with the shape feature numbers as contents of field "ID".

Return argument status is set to 1 if the complete shape file set was written successfully, to 0 otherwise.

Ref: http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf

See also: shapedraw, shapeinfo, shaperead.

Package: mapping