WKT Parser

  1. Using the WKT Parser
    1. Using in the Browser
    2. Using in Node.js
    3. Methods
      1. WKT.parse(string)
      2. WKT.convert(geojson)

Well Known Text is a format used by databases like PostGIS. With Terraformer’s WKT parser you can convert between this format and GeoJSON.

Link Using the WKT Parser Back to Top

The WKT parser can be used client-side in a browser and server-side via Node.js.

// parse a WKT string, converting it into a Terraformer.Primitive
var geojson = Terraformer.WKT.parse('LINESTRING (30 10, 10 30, 40 40)');

// take a primitive and convert it into a WKT representation
var polygon = Terraformer.WKT.convert({
  "type": "Polygon",
  "coordinates": [
    [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ],
    [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ]
  ]
});

Link Using in the Browser Back to Top

In the browser, the core Terraformer library is required.

<script src="terraformer.min.js"></script>
<script src="terraformer-wkt-parser.min.js"></script>
<script>
  //Terraformer and Terraformer.WKT will be defined.
</script>

You can also use Bower to install the components if you like, or download them and host them yourself.

$ bower install terraformer-wkt-parser

Link Using in Node.js Back to Top

Just install the package from NPM with $ npm install terraformer-arcgis-parser. Then include it in your application.

var WKT = require('terraformer-wkt-parser');

// Start using the parse and convert methods!

Link Methods Back to Top

Link WKT.parse(string) Back to Top

Terraformer.WKT.parse(string) - Converts a GeoJSON or a Terraformer.Primitive into WKT.

var geojson = Terraformer.WKT.parse('LINESTRING (30 10, 10 30, 40 40)');

Link WKT.convert(geojson) Back to Top

Terraformer.WKT.convert(geoJSON) will convert GeoJSON or a Terraformer Primitive to WKT.

Example
var polygon = Terraformer.WKT.convert({
  "type": "Polygon",
  "coordinates": [
    [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ],
    [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ]
  ]
});