com.vividsolutions.jump.io
Class ShapefileWriter

java.lang.Object
  extended bycom.vividsolutions.jump.io.ShapefileWriter
All Implemented Interfaces:
JUMPWriter

public class ShapefileWriter
extends java.lang.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 Summary
protected static com.vividsolutions.jts.algorithm.CGAlgorithms cga
           
static java.lang.String DEFAULT_VALUE_PROPERTY_KEY
           
static java.lang.String FILE_PROPERTY_KEY
           
static java.lang.String SHAPE_TYPE_PROPERTY_KEY
           
 
Constructor Summary
ShapefileWriter()
          Creates new ShapefileWriter
 
Method Summary
 int guessCoorinateDims(com.vividsolutions.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)
 com.vividsolutions.jts.geom.GeometryCollection makeSHAPEGeometryCollection(FeatureCollection fc)
          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.
 void write(FeatureCollection featureCollection, DriverProperties dp)
          Main method - write the featurecollection to a shapefile (2d, 3d or 4d).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_PROPERTY_KEY

public static final java.lang.String FILE_PROPERTY_KEY
See Also:
Constant Field Values

DEFAULT_VALUE_PROPERTY_KEY

public static final java.lang.String DEFAULT_VALUE_PROPERTY_KEY
See Also:
Constant Field Values

SHAPE_TYPE_PROPERTY_KEY

public static final java.lang.String SHAPE_TYPE_PROPERTY_KEY
See Also:
Constant Field Values

cga

protected static com.vividsolutions.jts.algorithm.CGAlgorithms cga
Constructor Detail

ShapefileWriter

public ShapefileWriter()
Creates new ShapefileWriter

Method Detail

write

public void write(FeatureCollection featureCollection,
                  DriverProperties dp)
           throws IllegalParametersException,
                  java.lang.Exception
Main method - write the featurecollection to a shapefile (2d, 3d or 4d).

Specified by:
write in interface JUMPWriter
Parameters:
featureCollection - collection to write
dp - 'OutputFile' or 'DefaultValue' to specify where to write, and 'ShapeType' to specify dimentionality.
Throws:
IllegalParametersException
java.lang.Exception

guessCoorinateDims

public int guessCoorinateDims(com.vividsolutions.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 com.vividsolutions.jts.geom.GeometryCollection makeSHAPEGeometryCollection(FeatureCollection fc)
                                                                           throws java.lang.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:
java.lang.Exception