public class ShapefileWriter extends java.lang.Object implements JUMPWriter
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 non-Point geometry in FeatureCollection | Coordinate Dimensionality | Shape Type |
---|---|---|
MULTIPOINT | xy xym xyzm | MULTIPOINT MULTIPOINTM MULTIPOINTZ |
LINESTRING/MULTILINESTRING | xy xym xyzm | POLYLINE POLYLINEM POLYLINEZ |
POLYGON/MULTIPOLYGON | xy xym xyzm | POLYGON POLYGONM POLYGONZ |
All geometries in FeatureCollection are | Coordinate Dimensionality | Shape Type |
POINT | xy xym xyzm | POINT POINTM POINTZ |
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
Modifier and Type | Field and Description |
---|---|
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 |
static boolean |
truncate |
Constructor and Description |
---|
ShapefileWriter()
Creates new ShapefileWriter
|
Modifier and Type | Method and Description |
---|---|
void |
checkIfGeomsAreMixed(FeatureCollection featureCollection) |
int |
guessCoordinateDims(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. all polygons) - or they will be set to NULL geometries GeometryN(i) = {Multipoint,Multilinestring, or Multipolygon) |
void |
write(FeatureCollection featureCollection,
DriverProperties dp)
Main method - write the featurecollection to a shapefile (2d, 3d or 4d).
|
public static final java.lang.String FILE_PROPERTY_KEY
public static final java.lang.String DEFAULT_VALUE_PROPERTY_KEY
public static final java.lang.String SHAPE_TYPE_PROPERTY_KEY
public static boolean truncate
protected static com.vividsolutions.jts.algorithm.CGAlgorithms cga
public void write(FeatureCollection featureCollection, DriverProperties dp) throws IllegalParametersException, java.lang.Exception
write
in interface JUMPWriter
featureCollection
- collection to writedp
- 'OutputFile' or 'DefaultValue' to specify where to write, and 'ShapeType' to specify dimentionality.IllegalParametersException
java.lang.Exception
public int guessCoordinateDims(com.vividsolutions.jts.geom.Geometry g)
g
- geometry to test - looks at 1st coordinatepublic void checkIfGeomsAreMixed(FeatureCollection featureCollection) throws IllegalParametersException, java.lang.Exception
IllegalParametersException
java.lang.Exception
public com.vividsolutions.jts.geom.GeometryCollection makeSHAPEGeometryCollection(FeatureCollection fc) throws java.lang.Exception
fc
- feature collection to make homogeneousjava.lang.Exception