WKT Parser
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-wkt-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)
- Used to convert a POINT, MULTIPOINT, LINESTRING, MULTILINESTRING, POLYGON
or MULTIPOLYGON
WKT string into a Terraformer.Primitive.
var geojson = Terraformer.WKT.parse('LINESTRING (30 10, 10 30, 40 40)');
Link WKT.convert(geojson) Back to Top
Terraformer.WKT.convert(geoJSON)
will turn a GeoJSON Point, MultiPoint, LineString, MultiLineString, Polygon
or MultiPolygon
geometry object or a Terraformer Primitive into 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] ]
]
});