Class GeoJsonReader

java.lang.Object
org.locationtech.jts.io.geojson.fork.GeoJsonReader

public class GeoJsonReader extends Object
Reads a GeoJSON Geometry from a JSON fragment into a Geometry.

The current GeoJSON specification is https://tools.ietf.org/html/rfc7946. An older specification is on the GeoJSON web site: http://geojson.org/geojson-spec.html.

The reader does not require a particular orientation for polygon rings.

The reader reads empty or null coordinate arrays as empty geometries.

It is the caller's responsibility to ensure that the supplied PrecisionModel matches the precision of the incoming data. If a lower precision for the data is required, a subsequent process must be run on the data to reduce its precision.

Author:
Martin Davis, Paul Howells, Vivid Solutions.
  • Constructor Summary

    Constructors
    Constructor
    Description
    The default constructor uses the SRID from the Geojson CRS and the default PrecisionModel to create a GeometryFactory.
    GeoJsonReader(org.locationtech.jts.geom.GeometryFactory geometryFactory)
    This constructor accepts a GeometryFactory that is used to create the output geometries and to override the GeoJson CRS.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.locationtech.jts.geom.Geometry
    read(Reader reader)
    Reads a GeoJson Geometry from a Reader into a single Geometry.
    org.locationtech.jts.geom.Geometry
    read(String json)
    Reads a GeoJson Geometry from a String into a single Geometry.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GeoJsonReader

      public GeoJsonReader()
      The default constructor uses the SRID from the Geojson CRS and the default PrecisionModel to create a GeometryFactory. If there is no CRS specified then the default CRS is a geographic coordinate reference system, using the WGS84 datum, and with longitude and latitude units of decimal degrees (SRID = 4326)
    • GeoJsonReader

      public GeoJsonReader(org.locationtech.jts.geom.GeometryFactory geometryFactory)
      This constructor accepts a GeometryFactory that is used to create the output geometries and to override the GeoJson CRS.
      Parameters:
      geometryFactory - a GeometryFactory
  • Method Details

    • read

      public org.locationtech.jts.geom.Geometry read(String json) throws org.locationtech.jts.io.ParseException
      Reads a GeoJson Geometry from a String into a single Geometry.
      Parameters:
      json - The GeoJson String to parse
      Returns:
      the resulting JTS Geometry
      Throws:
      org.locationtech.jts.io.ParseException - throws a ParseException if the JSON string cannot be parsed
    • read

      public org.locationtech.jts.geom.Geometry read(Reader reader) throws org.locationtech.jts.io.ParseException
      Reads a GeoJson Geometry from a Reader into a single Geometry.
      Parameters:
      reader - The input source
      Returns:
      The resulting JTS Geometry
      Throws:
      org.locationtech.jts.io.ParseException - throws a ParseException if the JSON string cannot be parsed as a Geometry