GeoScript

Table Of Contents

Previous topic

The process module

Next topic

The io/wkt module

The io/json module

>> var parser = require("geoscript/io/json");

Methods

read()
Arguments:
  • wktString The GeoJSON representation of a geometry or feature.
Returns:

Object() The deserialized version of the input string (one of geom.Geometry(), geom.GeometryCollection(), feature.Feature(), or feature.FeatureCollection()).

Create a geometry, a feature, or a collection of either from a JSON string.

Example of deserializing a geometry:

>> var LineString = require("geoscript/geom").LineString;
>> var line = parser.read('{"type": "LineString", "coordinates": [[1,2], [3,4]]}');
>> line instanceof LineString
true
>> line
<LineString [[1, 2], [3, 4]]>

Example of deserializing a feature:

>> var Feature = require("geoscript/feature").Feature;
>> var str = '{"type": "Feature", "properties": {"foo": "bar"}, "geometry": {"type": "Point", "coordinates": [1, 2]}}'
>> var feature = parser.read(str)
>> feature instanceof Feature
true
>> feature
<Feature foo: "bar", geometry: <Point>>
write()
Arguments:
Returns:

String The GeoJSON representation of the input object.

Generate a GeoJSON string from a geometry, a feature, or a collection of either.

Example of serializing a geometry:

>> var Point = require("geoscript/geom").Point;
>> var str = parser.write(Point([1, 2]));
>> str
{"type":"Point","coordinates":[1,2]}