Package org.locationtech.jts.io.geojson
Class GeoJsonWriter
java.lang.Object
org.locationtech.jts.io.geojson.GeoJsonWriter
Writes
Geometry
s as JSON fragments in GeoJSON format.
The current GeoJSON specification is https://tools.ietf.org/html/rfc7946.
The GeoJSON specification states that polygons should be emitted using the counter-clockwise shell orientation. This is not enforced by this writer.
The GeoJSON specification does not state how to represent empty geometries of specific type.
The writer emits empty typed geometries using an empty array for the coordinates
property.
- Author:
- Martin Davis, Paul Howells, Vivid Solutions
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The prefix for EPSG codes in thecrs
property. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a GeoJsonWriter instance.GeoJsonWriter
(int decimals) Constructs a GeoJsonWriter instance specifying the number of decimals to use when encoding floating point numbers. -
Method Summary
Modifier and TypeMethodDescriptionvoid
setEncodeCRS
(boolean isEncodeCRS) Sets whether the GeoJSONcrs
property should be output.void
setForceCCW
(boolean isForceCCW) Sets whether the GeoJSON should be output following counter-clockwise orientation aka Right Hand Rule defined in RFC7946 See RFC 7946 Specification for more context.Writes aGeometry
in GeoJson format to a String.void
-
Field Details
-
EPSG_PREFIX
The prefix for EPSG codes in thecrs
property.- See Also:
-
-
Constructor Details
-
GeoJsonWriter
public GeoJsonWriter()Constructs a GeoJsonWriter instance. -
GeoJsonWriter
public GeoJsonWriter(int decimals) Constructs a GeoJsonWriter instance specifying the number of decimals to use when encoding floating point numbers.- Parameters:
decimals
- the number of decimal places to output
-
-
Method Details
-
setEncodeCRS
public void setEncodeCRS(boolean isEncodeCRS) Sets whether the GeoJSONcrs
property should be output. The value of the property is taken from geometry SRID.- Parameters:
isEncodeCRS
- true if the crs property should be output
-
setForceCCW
public void setForceCCW(boolean isForceCCW) Sets whether the GeoJSON should be output following counter-clockwise orientation aka Right Hand Rule defined in RFC7946 See RFC 7946 Specification for more context.- Parameters:
isForceCCW
- true if the GeoJSON should be output following the RFC7946 counter-clockwise orientation aka Right Hand Rule
-
write
Writes aGeometry
in GeoJson format to a String.- Parameters:
geometry
- the geometry to write- Returns:
- String GeoJson Encoded Geometry
-
write
- Parameters:
geometry
- Geometry to encodewriter
- Stream to encode to.- Throws:
IOException
- throws an IOException when unable to write the JSON string
-