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 SummaryConstructors 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 SummaryAll 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- 
setTracepublic void setTrace(boolean trace) Sets trace flag.
 - 
isTracepublic boolean isTrace() Tracing flag.When this flag is set parsed documents will be echoed to stdout during parsing. 
 - 
writepublic void write(Geometry geometry, Object output) throws IOException Writes a Geometry instance as GeoJSON.- Parameters:
- geometry- The geometry.
- output- The output. See- GeoJSONUtil.toWriter(Object)for details.
- Throws:
- IOException
 
 - 
writepublic 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
 
 - 
toStringpublic 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
 
 - 
readpublic Geometry read(Object input) throws IOException Reads a Geometry instance from GeoJSON.- Parameters:
- input- The input. See- GeoJSONUtil.toReader(Object)for details.
- Returns:
- The geometry instance.
- Throws:
- IOException
 
 - 
readpublic 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
 
 - 
writePointpublic void writePoint(Point point, Object output) throws IOException Writes a Point as GeoJSON.- Parameters:
- point- The point.
- output- The output. See- GeoJSONUtil.toWriter(Object)for details.
- Throws:
- IOException- In the event of a parsing error or if the input json is invalid.
 
 - 
writePointpublic 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.
 
 - 
readPointpublic Point readPoint(Object input) throws IOException Reads a Point from GeoJSON.- Parameters:
- input- The input. See- GeoJSONUtil.toReader(Object)for details.
- Returns:
- The point.
- Throws:
- IOException- In the event of a parsing error or if the input json is invalid.
 
 - 
readPointpublic 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.
 
 - 
writeLinepublic void writeLine(LineString line, Object output) throws IOException Writes a LineString as GeoJSON.- Parameters:
- line- The line string.
- output- The output. See- GeoJSONUtil.toWriter(Object)for details.
- Throws:
- IOException
 
 - 
writeLinepublic 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
 
 - 
readLinepublic LineString readLine(Object input) throws IOException Reads a LineString from GeoJSON.- Parameters:
- input- The input. See- GeoJSONUtil.toReader(Object)for details.
- Returns:
- The line string.
- Throws:
- IOException- In the event of a parsing error or if the input json is invalid.
 
 - 
readLinepublic 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.
 
 - 
writePolygonpublic void writePolygon(Polygon poly, Object output) throws IOException Writes a Polygon as GeoJSON.- Parameters:
- poly- The polygon.
- output- The output. See- GeoJSONUtil.toWriter(Object)for details.
- Throws:
- IOException
 
 - 
writePolygonpublic 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
 
 - 
readPolygonpublic Polygon readPolygon(Object input) throws IOException Reads a Polygon from GeoJSON.- Parameters:
- input- The input. See- GeoJSONUtil.toReader(Object)for details.
- Returns:
- The polygon.
- Throws:
- IOException- In the event of a parsing error or if the input json is invalid.
 
 - 
readPolygonpublic 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.
 
 - 
writeMultiPointpublic void writeMultiPoint(MultiPoint mpoint, Object output) throws IOException Writes a MultiPoint as GeoJSON.- Parameters:
- mpoint- The multi point.
- output- The output. See- GeoJSONUtil.toWriter(Object)for details.
- Throws:
- IOException
 
 - 
writeMultiPointpublic 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
 
 - 
readMultiPointpublic MultiPoint readMultiPoint(Object input) throws IOException Reads a MultiPoint from GeoJSON.- Parameters:
- input- The input. See- GeoJSONUtil.toReader(Object)for details.
- Returns:
- The multi point.
- Throws:
- IOException- In the event of a parsing error or if the input json is invalid.
 
 - 
readMultiPointpublic 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.
 
 - 
writeMultiLinepublic void writeMultiLine(MultiLineString mline, Object output) throws IOException Writes a MultiLineString as GeoJSON.- Parameters:
- mline- The multi line string.
- output- The output. See- GeoJSONUtil.toWriter(Object)for details.
- Throws:
- IOException
 
 - 
writeMultiLinepublic 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
 
 - 
readMultiLinepublic MultiLineString readMultiLine(Object input) throws IOException Reads a MultiLineString from GeoJSON.- Parameters:
- input- The input. See- GeoJSONUtil.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.
 
 - 
readMultiLinepublic 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.
 
 - 
writeMultiPolygonpublic void writeMultiPolygon(MultiPolygon mpoly, Object output) throws IOException Writes a MultiPolygon as GeoJSON.- Parameters:
- mpoly- The multi polygon.
- output- The output. See- GeoJSONUtil.toWriter(Object)for details.
- Throws:
- IOException
 
 - 
writeMultiPolygonpublic 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
 
 - 
readMultiPolygonpublic MultiPolygon readMultiPolygon(Object input) throws IOException Reads a MultiPolygon from GeoJSON.- Parameters:
- input- The input. See- GeoJSONUtil.toReader(Object)for details.
- Returns:
- The multi polygon.
- Throws:
- IOException- In the event of a parsing error or if the input json is invalid.
 
 - 
readMultiPolygonpublic 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.
 
 - 
writeGeometryCollectionpublic void writeGeometryCollection(GeometryCollection gcol, Object output) throws IOException Writes a GeometryCollection as GeoJSON.- Parameters:
- gcol- The geometry collection.
- output- The output. See- GeoJSONUtil.toWriter(Object)for details.
- Throws:
- IOException
 
 - 
writeGeometryCollectionpublic 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
 
 - 
readGeometryCollectionpublic GeometryCollection readGeometryCollection(Object input) throws IOException Reads a GeometryCollection from GeoJSON.- Parameters:
- input- The input. See- GeoJSONUtil.toReader(Object)for details.
- Returns:
- The geometry collection.
- Throws:
- IOException- In the event of a parsing error or if the input json is invalid.
 
 - 
readGeometryCollectionpublic 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.
 
 - 
toStringpublic 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
 
 
- 
 
-