Class GeometryJSON
- Object
-
- GeometryJSON
-
public class GeometryJSON extends Object
Reads and writes geometry objects to and from geojson.Point point = new Point(1,2); GeometryJSON g = new GeometryJSON(); g.writePoint(point, "point.json")); Point point2 = g.readPoint("point.json"); Geometry geometry = ...; g.write(geometry, new File("geometry.json")); geometry = g.read("geometry.json");- Author:
- Justin Deoliveira, OpenGeo
-
-
Constructor Summary
Constructors Constructor Description GeometryJSON()Constructs a geometry json instance.GeometryJSON(int decimals)Constructs a geometry json 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 booleanisTrace()Tracing flag.Geometryread(InputStream input)Reads a Geometry instance from GeoJSON.Geometryread(Object input)Reads a Geometry instance from GeoJSON.GeometryCollectionreadGeometryCollection(InputStream input)Reads a GeometryCollection from GeoJSON.GeometryCollectionreadGeometryCollection(Object input)Reads a GeometryCollection from GeoJSON.LineStringreadLine(InputStream input)Reads a LineString from GeoJSON.LineStringreadLine(Object input)Reads a LineString from GeoJSON.MultiLineStringreadMultiLine(InputStream input)Reads a MultiLineString from GeoJSON.MultiLineStringreadMultiLine(Object input)Reads a MultiLineString from GeoJSON.MultiPointreadMultiPoint(InputStream input)Reads a MultiPoint from GeoJSON.MultiPointreadMultiPoint(Object input)Reads a MultiPoint from GeoJSON.MultiPolygonreadMultiPolygon(InputStream input)Reads a MultiPolygon from GeoJSON.MultiPolygonreadMultiPolygon(Object input)Reads a MultiPolygon from GeoJSON.PointreadPoint(InputStream input)Reads a Point from GeoJSON.PointreadPoint(Object input)Reads a Point from GeoJSON.PolygonreadPolygon(InputStream input)Reads a Polygon from GeoJSON.PolygonreadPolygon(Object input)Reads a Polygon from GeoJSON.voidsetTrace(boolean trace)Sets trace flag.StringtoString(BoundingBox bbox)Writes an BoundingBox instance as GeoJSON returning the result as a string.StringtoString(Envelope e)Writes an Envelope instance as GeoJSON returning the result as a string.StringtoString(Geometry geometry)Writes a Geometry instance as GeoJSON returning the result as a string.voidwrite(Geometry geometry, OutputStream output)Writes a Geometry instance as GeoJSON.voidwrite(Geometry geometry, Object output)Writes a Geometry instance as GeoJSON.voidwriteGeometryCollection(GeometryCollection gcol, OutputStream output)Writes a GeometryCollection as GeoJSON.voidwriteGeometryCollection(GeometryCollection gcol, Object output)Writes a GeometryCollection as GeoJSON.voidwriteLine(LineString line, OutputStream output)Writes a LineString as GeoJSON.voidwriteLine(LineString line, Object output)Writes a LineString as GeoJSON.voidwriteMultiLine(MultiLineString mline, OutputStream output)Writes a MultiLineString as GeoJSON.voidwriteMultiLine(MultiLineString mline, Object output)Writes a MultiLineString as GeoJSON.voidwriteMultiPoint(MultiPoint mpoint, OutputStream output)Writes a MultiPoint as GeoJSON.voidwriteMultiPoint(MultiPoint mpoint, Object output)Writes a MultiPoint as GeoJSON.voidwriteMultiPolygon(MultiPolygon mpoly, OutputStream output)Writes a MultiPolygon as GeoJSON.voidwriteMultiPolygon(MultiPolygon mpoly, Object output)Writes a MultiPolygon as GeoJSON.voidwritePoint(Point point, OutputStream output)Writes a Point as GeoJSON.voidwritePoint(Point point, Object output)Writes a Point as GeoJSON.voidwritePolygon(Polygon poly, OutputStream output)Writes a Polygon as GeoJSON.voidwritePolygon(Polygon poly, Object output)Writes a Polygon as GeoJSON.
-
-
-
Method Detail
-
setTrace
public void setTrace(boolean trace)
Sets trace flag.
-
isTrace
public boolean isTrace()
Tracing flag.When this flag is set parsed documents will be echoed to stdout during parsing.
-
write
public void write(Geometry geometry, Object output) throws IOException
Writes a Geometry instance as GeoJSON.- Parameters:
geometry- The geometry.output- The output. SeeGeoJSONUtil.toWriter(Object)for details.- Throws:
IOException
-
write
public void write(Geometry geometry, OutputStream output) throws IOException
Writes a Geometry instance as GeoJSON.This method calls through to
write(Geometry, Object)- Parameters:
geometry- The geometry.output- The output stream.- Throws:
IOException
-
toString
public String toString(Geometry geometry)
Writes a Geometry instance as GeoJSON returning the result as a string.- Parameters:
geometry- The geometry.- Returns:
- The geometry encoded as GeoJSON
-
read
public Geometry read(Object input) throws IOException
Reads a Geometry instance from GeoJSON.- Parameters:
input- The input. SeeGeoJSONUtil.toReader(Object)for details.- Returns:
- The geometry instance.
- Throws:
IOException
-
read
public Geometry read(InputStream input) throws IOException
Reads a Geometry instance from GeoJSON.This method calls through to
read(Object)- Parameters:
input- The input stream.- Returns:
- The geometry instance.
- Throws:
IOException
-
writePoint
public void writePoint(Point point, Object output) throws IOException
Writes a Point as GeoJSON.- Parameters:
point- The point.output- The output. SeeGeoJSONUtil.toWriter(Object)for details.- Throws:
IOException- In the event of a parsing error or if the input json is invalid.
-
writePoint
public void writePoint(Point point, OutputStream output) throws IOException
Writes a Point as GeoJSON.This method calls through to
writePoint(Point, Object)- Parameters:
point- The point.output- The output stream.- Throws:
IOException- In the event of a parsing error or if the input json is invalid.
-
readPoint
public Point readPoint(Object input) throws IOException
Reads a Point from GeoJSON.- Parameters:
input- The input. SeeGeoJSONUtil.toReader(Object)for details.- Returns:
- The point.
- Throws:
IOException- In the event of a parsing error or if the input json is invalid.
-
readPoint
public Point readPoint(InputStream input) throws IOException
Reads a Point from GeoJSON.This method calls through to
readPoint(Object)- Parameters:
input- The input stream.- Returns:
- The point.
- Throws:
IOException- In the event of a parsing error or if the input json is invalid.
-
writeLine
public void writeLine(LineString line, Object output) throws IOException
Writes a LineString as GeoJSON.- Parameters:
line- The line string.output- The output. SeeGeoJSONUtil.toWriter(Object)for details.- Throws:
IOException
-
writeLine
public void writeLine(LineString line, OutputStream output) throws IOException
Writes a LineString as GeoJSON.This method calls through to
writeLine(LineString, Object)- Parameters:
line- The line string.output- The output stream.- Throws:
IOException
-
readLine
public LineString readLine(Object input) throws IOException
Reads a LineString from GeoJSON.- Parameters:
input- The input. SeeGeoJSONUtil.toReader(Object)for details.- Returns:
- The line string.
- Throws:
IOException- In the event of a parsing error or if the input json is invalid.
-
readLine
public LineString readLine(InputStream input) throws IOException
Reads a LineString from GeoJSON.This method calls through to
readLine(Object)- Parameters:
input- The input stream.- Returns:
- The line string.
- Throws:
IOException- In the event of a parsing error or if the input json is invalid.
-
writePolygon
public void writePolygon(Polygon poly, Object output) throws IOException
Writes a Polygon as GeoJSON.- Parameters:
poly- The polygon.output- The output. SeeGeoJSONUtil.toWriter(Object)for details.- Throws:
IOException
-
writePolygon
public void writePolygon(Polygon poly, OutputStream output) throws IOException
Writes a Polygon as GeoJSON.This method calls through to
writePolygon(Polygon, Object)- Parameters:
poly- The polygon.output- The output stream.- Throws:
IOException
-
readPolygon
public Polygon readPolygon(Object input) throws IOException
Reads a Polygon from GeoJSON.- Parameters:
input- The input. SeeGeoJSONUtil.toReader(Object)for details.- Returns:
- The polygon.
- Throws:
IOException- In the event of a parsing error or if the input json is invalid.
-
readPolygon
public Polygon readPolygon(InputStream input) throws IOException
Reads a Polygon from GeoJSON.This method calls through to
readPolygon(Object)- Parameters:
input- The input stream.- Returns:
- The polygon.
- Throws:
IOException- In the event of a parsing error or if the input json is invalid.
-
writeMultiPoint
public void writeMultiPoint(MultiPoint mpoint, Object output) throws IOException
Writes a MultiPoint as GeoJSON.- Parameters:
mpoint- The multi point.output- The output. SeeGeoJSONUtil.toWriter(Object)for details.- Throws:
IOException
-
writeMultiPoint
public void writeMultiPoint(MultiPoint mpoint, OutputStream output) throws IOException
Writes a MultiPoint as GeoJSON.This method calls through to
writeMultiPoint(MultiPoint, Object)- Parameters:
mpoint- The multi point.output- The output stream.- Throws:
IOException
-
readMultiPoint
public MultiPoint readMultiPoint(Object input) throws IOException
Reads a MultiPoint from GeoJSON.- Parameters:
input- The input. SeeGeoJSONUtil.toReader(Object)for details.- Returns:
- The multi point.
- Throws:
IOException- In the event of a parsing error or if the input json is invalid.
-
readMultiPoint
public MultiPoint readMultiPoint(InputStream input) throws IOException
Reads a MultiPoint from GeoJSON.This method calls through to
readMultiPoint(Object)- Parameters:
input- The input stream.- Returns:
- The multi point.
- Throws:
IOException- In the event of a parsing error or if the input json is invalid.
-
writeMultiLine
public void writeMultiLine(MultiLineString mline, Object output) throws IOException
Writes a MultiLineString as GeoJSON.- Parameters:
mline- The multi line string.output- The output. SeeGeoJSONUtil.toWriter(Object)for details.- Throws:
IOException
-
writeMultiLine
public void writeMultiLine(MultiLineString mline, OutputStream output) throws IOException
Writes a MultiLineString as GeoJSON.This method calls through to
writeMultiLine(MultiLineString, Object)- Parameters:
mline- The multi line string.output- The output stream.- Throws:
IOException
-
readMultiLine
public MultiLineString readMultiLine(Object input) throws IOException
Reads a MultiLineString from GeoJSON.- Parameters:
input- The input. SeeGeoJSONUtil.toReader(Object)for details.- Returns:
- The multi line string.
- Throws:
IOException- In the event of a parsing error or if the input json is invalid.
-
readMultiLine
public MultiLineString readMultiLine(InputStream input) throws IOException
Reads a MultiLineString from GeoJSON.This method calls through to
readMultiLine(Object)- Parameters:
input- The input stream.- Returns:
- The multi line string.
- Throws:
IOException- In the event of a parsing error or if the input json is invalid.
-
writeMultiPolygon
public void writeMultiPolygon(MultiPolygon mpoly, Object output) throws IOException
Writes a MultiPolygon as GeoJSON.- Parameters:
mpoly- The multi polygon.output- The output. SeeGeoJSONUtil.toWriter(Object)for details.- Throws:
IOException
-
writeMultiPolygon
public void writeMultiPolygon(MultiPolygon mpoly, OutputStream output) throws IOException
Writes a MultiPolygon as GeoJSON.This method calls through to
writeMultiPolygon(MultiPolygon, Object)- Parameters:
mpoly- The multi polygon.output- The output stream.- Throws:
IOException
-
readMultiPolygon
public MultiPolygon readMultiPolygon(Object input) throws IOException
Reads a MultiPolygon from GeoJSON.- Parameters:
input- The input. SeeGeoJSONUtil.toReader(Object)for details.- Returns:
- The multi polygon.
- Throws:
IOException- In the event of a parsing error or if the input json is invalid.
-
readMultiPolygon
public MultiPolygon readMultiPolygon(InputStream input) throws IOException
Reads a MultiPolygon from GeoJSON.This method calls through to
readMultiPolygon(Object)- Parameters:
input- The input stream.- Returns:
- The multi polygon.
- Throws:
IOException- In the event of a parsing error or if the input json is invalid.
-
writeGeometryCollection
public void writeGeometryCollection(GeometryCollection gcol, Object output) throws IOException
Writes a GeometryCollection as GeoJSON.- Parameters:
gcol- The geometry collection.output- The output. SeeGeoJSONUtil.toWriter(Object)for details.- Throws:
IOException
-
writeGeometryCollection
public void writeGeometryCollection(GeometryCollection gcol, OutputStream output) throws IOException
Writes a GeometryCollection as GeoJSON.This method calls through to
writeGeometryCollection(GeometryCollection, Object)- Parameters:
gcol- The geometry collection.output- The output stream.- Throws:
IOException
-
readGeometryCollection
public GeometryCollection readGeometryCollection(Object input) throws IOException
Reads a GeometryCollection from GeoJSON.- Parameters:
input- The input. SeeGeoJSONUtil.toReader(Object)for details.- Returns:
- The geometry collection.
- Throws:
IOException- In the event of a parsing error or if the input json is invalid.
-
readGeometryCollection
public GeometryCollection readGeometryCollection(InputStream input) throws IOException
Reads a GeometryCollection from GeoJSON.This method calls through to
readGeometryCollection(Object)- Parameters:
input- The input stream.- Returns:
- The geometry collection.
- Throws:
IOException- In the event of a parsing error or if the input json is invalid.
-
toString
public String toString(BoundingBox bbox)
Writes an BoundingBox instance as GeoJSON returning the result as a string.- Parameters:
bbox- The bounding box.- Returns:
- The bounding box encoded as GeoJSON
-
-