Class ShapefileWriter

  • All Implemented Interfaces:
    JUMPWriter

    public class ShapefileWriter
    extends Object
    implements JUMPWriter
    ShapefileWriter is a JUMPWriter specialized to write Shapefiles.

    DataProperties for the ShapefileWriter write(DataProperties) interface:

    Parameter Meaning
    OutputFile or DefaultValue File name for the output .shp file
    ShapeType Dimentionality of the Shapefile - 'xy', 'xym' or 'xyz'. 'xymz' and 'xyzm' are the same as 'xyz'

    NOTE: The input .dbf and .shx is assumed to be 'beside' (in the same directory) as the .shp file.

    The shapefile writer consists of two parts: writing attributes (.dbf) and writing geometries (.shp).

    JUMP columns are converted to DBF columns by:

    JUMP Column DBF column
    STRING Type 'C' length is size of longest string in the FeatureCollection
    DOUBLE Type 'N' length is 33, with 16 digits right of the decimal
    INTEGER Type 'N' length is 16, with 0 digits right of the decimal

    For more information on the DBF file format, see the DBF Specification FAQ

    Since shape files may contain only one type of geometry (POINT, MULTPOINT, POLYLINE, POLYGON, POINTM, MULTPOINTM, POLYLINEM, POLYGONM, POINTZ, MULTPOINTZ, POLYLINEZ, or POLYGONZ), the FeatureCollection must be first be normalized to one type:

    First non-NULL geometry in FeatureCollection Coordinate Dimensionality Shape Type
    POINT/MULTIPOINT xy xym xyzm MULTIPOINT MULTIPOINTM MULTIPOINTZ
    LINESTRING/MULTILINESTRING xy xym xyzm POLYLINE POLYLINEM POLYLINEZ
    POLYGON/MULTIPOLYGON xy xym xyzm POLYGON POLYGONM POLYGONZ

    During this normalization process any non-consistent geometry will be replaced by a NULL geometry.

    For example, if the shapetype is determined to be 'POLYLINE' any POINT, MULTIPOINT, or POLYGON geometries in the FeatureCollection will be replaced with a NULL geometry.

    The coordinate dimensionality can be explicitly set with a DataProperties tag of 'ShapeType': 'xy', 'xym', or 'xyz' ('xymz' and 'xyzm' are pseudonyms for 'xyz'). If this DataProperties is unspecified, it will be auto set to 'xy' or 'xyz' based on the first non-NULL geometry having a Z coordinate.

    Since JUMP and JTS do not currently support a M (measure) coordinate, it will always be set to 10E40 in the shape file (type 'xym' or 'xyzm'). This value represents the Measure "no data" value (page 2, ESRI Shapefile Technical Description). Since the 'NaN' DOUBLE values for Z coordinates is invalid in a shapefile, it is converted to '0.0'.

    For more information on the shapefile format, see the ESRI Shapefile Spec

    • Field Detail

      • cga

        protected static org.locationtech.jts.algorithm.CGAlgorithms cga
    • Constructor Detail

      • ShapefileWriter

        public ShapefileWriter()
        Creates new ShapefileWriter
    • Method Detail

      • guessCoorinateDims

        public int guessCoorinateDims​(org.locationtech.jts.geom.Geometry g)
        Returns:
        2 for 2d (default)
        4 for 3d - one of the oordinates has a non-NaN z value
        (3 is for x,y,m but thats not supported yet)
        Parameters:
        g - geometry to test - looks at 1st coordinate
      • makeSHAPEGeometryCollection

        public org.locationtech.jts.geom.GeometryCollection makeSHAPEGeometryCollection​(FeatureCollection fc)
                                                                                 throws Exception
        return a single geometry collection
        result.GeometryN(i) = the i-th feature in the FeatureCollection
        All the geometry types will be the same type (ie. all polygons) - or they will be set to
        NULL geometries

        GeometryN(i) = {Multipoint,Multilinestring, or Multipolygon)
        Parameters:
        fc - feature collection to make homogeneous
        Throws:
        Exception