WKTReader.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * @module org/locationtech/jts/io/WKTReader
  3. */
  4. import GeometryFactory from '../geom/GeometryFactory'
  5. import WKTParser from './WKTParser'
  6. /**
  7. * Converts a geometry in Well-Known Text format to a {@link Geometry}.
  8. * <p>
  9. * <code>WKTReader</code> supports extracting <code>Geometry</code> objects
  10. * from either {@link Reader}s or {@link String}s. This allows it to function
  11. * as a parser to read <code>Geometry</code> objects from text blocks embedded
  12. * in other data formats (e.g. XML).
  13. */
  14. export default class WKTReader {
  15. /**
  16. * A <code>WKTReader</code> is parameterized by a <code>GeometryFactory</code>,
  17. * to allow it to create <code>Geometry</code> objects of the appropriate
  18. * implementation. In particular, the <code>GeometryFactory</code> determines
  19. * the <code>PrecisionModel</code> and <code>SRID</code> that is used.
  20. * @param {GeometryFactory} geometryFactory
  21. */
  22. constructor(geometryFactory) {
  23. this.parser = new WKTParser(geometryFactory || new GeometryFactory())
  24. }
  25. /**
  26. * Reads a Well-Known Text representation of a {@link Geometry}
  27. *
  28. * @param {string}
  29. * wkt a <Geometry Tagged Text> string (see the OpenGIS Simple Features
  30. * Specification).
  31. * @return {Geometry} a <code>Geometry</code> read from
  32. * <code>string.</code>
  33. * @memberof module:org/locationtech/jts/io/WKTReader#
  34. */
  35. read(wkt) {
  36. return this.parser.read(wkt)
  37. }
  38. }