Package org.locationtech.jts.io.geojson
Class GeoJsonWriter
- java.lang.Object
-
- org.locationtech.jts.io.geojson.GeoJsonWriter
-
public class GeoJsonWriter extends java.lang.Object
WritesGeometry
s as JSON fragments in GeoJson format.- Author:
- Martin Davis, Paul Howells, Vivid Solutions
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
EPSG_PREFIX
The prefix for EPSG codes in thecrs
property.
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
setEncodeCRS(boolean isEncodeCRS)
Sets whether the GeoJSONcrs
property should be output.java.lang.String
write(Geometry geometry)
Writes aGeometry
in GeoJson format to a String.void
write(Geometry geometry, java.io.Writer writer)
Writes aGeometry
in GeoJson format into aWriter
.
-
-
-
Field Detail
-
EPSG_PREFIX
public static final java.lang.String EPSG_PREFIX
The prefix for EPSG codes in thecrs
property.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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 Detail
-
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
-
write
public java.lang.String write(Geometry geometry)
Writes aGeometry
in GeoJson format to a String.- Parameters:
geometry
- the geometry to write- Returns:
- String GeoJson Encoded Geometry
-
write
public void write(Geometry geometry, java.io.Writer writer) throws java.io.IOException
Writes aGeometry
in GeoJson format into aWriter
.- Parameters:
geometry
- Geometry to encodewriter
- Stream to encode to.- Throws:
java.io.IOException
- throws an IOException when unable to write the JSON string
-
-