public class GeoJsonWriter extends Object
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.
Modifier and Type | Field and Description |
---|---|
static String |
EPSG_PREFIX
The prefix for EPSG codes in the
crs property. |
Constructor and Description |
---|
GeoJsonWriter()
Constructs a GeoJsonWriter instance.
|
GeoJsonWriter(int decimals)
Constructs a GeoJsonWriter instance specifying the number of decimals to
use when encoding floating point numbers.
|
Modifier and Type | Method and Description |
---|---|
void |
setEncodeCRS(boolean isEncodeCRS)
Sets whether the GeoJSON
crs 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.
|
String |
write(org.locationtech.jts.geom.Geometry geometry)
Writes a
Geometry in GeoJson format to a String. |
void |
write(org.locationtech.jts.geom.Geometry geometry,
Writer writer)
Writes a
Geometry in GeoJson format into a Writer . |
public static final String EPSG_PREFIX
crs
property.public GeoJsonWriter()
public GeoJsonWriter(int decimals)
decimals
- the number of decimal places to outputpublic void setEncodeCRS(boolean isEncodeCRS)
crs
property should
be output.
The value of the property is taken from geometry SRID.isEncodeCRS
- true if the crs property should be outputpublic void setForceCCW(boolean isForceCCW)
isForceCCW
- true if the GeoJSON should be output following the RFC7946 counter-clockwise orientation aka Right Hand Rulepublic String write(org.locationtech.jts.geom.Geometry geometry)
Geometry
in GeoJson format to a String.geometry
- the geometry to writepublic void write(org.locationtech.jts.geom.Geometry geometry, Writer writer) throws IOException
Geometry
in GeoJson format into a Writer
.geometry
- Geometry to encodewriter
- Stream to encode to.IOException
- throws an IOException when unable to write the JSON stringCopyright © 2024. All rights reserved.