GeoJSONReader.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * @module org/locationtech/jts/io/GeoJSONReader
  3. */
  4. import GeometryFactory from '../geom/GeometryFactory'
  5. import GeoJSONParser from './GeoJSONParser'
  6. /**
  7. * Converts a geometry in GeoJSON to a {@link Geometry}.
  8. */
  9. export default class GeoJSONReader {
  10. /**
  11. * A <code>GeoJSONReader</code> is parameterized by a <code>GeometryFactory</code>,
  12. * to allow it to create <code>Geometry</code> objects of the appropriate
  13. * implementation. In particular, the <code>GeometryFactory</code> determines
  14. * the <code>PrecisionModel</code> and <code>SRID</code> that is used.
  15. *
  16. * @param {GeometryFactory} geometryFactory
  17. */
  18. constructor(geometryFactory) {
  19. this.parser = new GeoJSONParser(geometryFactory || new GeometryFactory())
  20. }
  21. /**
  22. * Reads a GeoJSON representation of a {@link Geometry}
  23. *
  24. * Will also parse GeoJSON Features/FeatureCollections as custom objects.
  25. *
  26. * @param {Object|String} geoJson a GeoJSON Object or String.
  27. * @return {Geometry|Object} a <code>Geometry or Feature/FeatureCollection representation.</code>
  28. * @memberof module:org/locationtech/jts/io/GeoJSONReader#
  29. */
  30. read(geoJson) {
  31. const geometry = this.parser.read(geoJson)
  32. return geometry
  33. }
  34. }