WKTWriter.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * @module org/locationtech/jts/io/WKTWriter
  3. */
  4. import WKTParser from './WKTParser'
  5. /**
  6. * Writes the Well-Known Text representation of a {@link Geometry}. The
  7. * Well-Known Text format is defined in the <A
  8. * HREF="http://www.opengis.org/techno/specs.htm"> OGC Simple Features
  9. * Specification for SQL</A>.
  10. * <p>
  11. * The <code>WKTWriter</code> outputs coordinates rounded to the precision
  12. * model. Only the maximum number of decimal places necessary to represent the
  13. * ordinates to the required precision will be output.
  14. * <p>
  15. * The SFS WKT spec does not define a special tag for {@link LinearRing}s.
  16. * Under the spec, rings are output as <code>LINESTRING</code>s.
  17. */
  18. export default class WKTWriter {
  19. /**
  20. * @param {GeometryFactory} geometryFactory
  21. */
  22. constructor(geometryFactory) {
  23. this.parser = new WKTParser(geometryFactory)
  24. }
  25. /**
  26. * Converts a <code>Geometry</code> to its Well-known Text representation.
  27. *
  28. * @param {Geometry} geometry a <code>Geometry</code> to process.
  29. * @return {string} a <Geometry Tagged Text> string (see the OpenGIS Simple
  30. * Features Specification).
  31. * @memberof module:org/locationtech/jts/io/WKTWriter#
  32. */
  33. write(geometry) {
  34. return this.parser.write(geometry)
  35. }
  36. /**
  37. * Generates the WKT for a <tt>LINESTRING</tt> specified by two
  38. * {@link Coordinate}s.
  39. *
  40. * @param p0 the first coordinate.
  41. * @param p1 the second coordinate.
  42. *
  43. * @return the WKT.
  44. * @private
  45. */
  46. static toLineString(p0, p1) {
  47. if (arguments.length !== 2) throw new Error('Not implemented')
  48. return 'LINESTRING ( ' + p0.x + ' ' + p0.y + ', ' + p1.x + ' ' + p1.y + ' )'
  49. }
  50. }