GeoJSONWriter

Members

Calculates a buffer for input features for a given radius. Units supported are miles, kilometers, and degrees. When using a negative radius, the resulting geometry may be invalid if it's too small compared to the radius magnitude. If the input is a FeatureCollection, only valid members will be returned in the output FeatureCollection - i.e., the output collection may have fewer members than the input, or even be empty.
Example:
var point = turfEx.point([-90.548630, 14.616599]);
var buffered = turfEx.buffer(point, 500, {units: 'miles'});

//addToMap
var addToMap = [point, buffered]
Finds the difference between two polygons by clipping the second polygon from the first.
Example:
var polygon1 = turfEx.polygon([[
  [128, -26],
  [141, -26],
  [141, -21],
  [128, -21],
  [128, -26]
]], {
  "fill": "#F00",
  "fill-opacity": 0.1
});
var polygon2 = turfEx.polygon([[
  [126, -28],
  [140, -28],
  [140, -20],
  [126, -20],
  [126, -28]
]], {
  "fill": "#00F",
  "fill-opacity": 0.1
});

var difference = turfEx.difference(polygon1, polygon2);

//addToMap
var addToMap = [polygon1, polygon2, difference];
Dissolves a FeatureCollection of polygon features, filtered by an optional property name:value. Note that mulitpolygon features within the collection are not supported
Example:
var features = turfEx.featureCollection([
  turfEx.polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], {combine: 'yes'}),
  turfEx.polygon([[[0, -1], [0, 0], [1, 0], [1, -1], [0,-1]]], {combine: 'yes'}),
  turfEx.polygon([[[1,-1],[1, 0], [2, 0], [2, -1], [1, -1]]], {combine: 'no'}),
]);

var dissolved = turfEx.dissolve(features, {propertyName: 'combine'});

//addToMap
var addToMap = [features, dissolved]
Takes a bounding box and the diameter of the cell and returns a FeatureCollection of flat-topped hexagons or triangles (Polygon features) aligned in an "odd-q" vertical grid as described in [Hexagonal Grids](http://www.redblobgames.com/grids/hexagons/).
Example:
var bbox = [-96,31,-84,40];
var cellSide = 50;
var options = {units: 'miles'};

var hexgrid = turfEx.hexGrid(bbox, cellSide, options);

//addToMap
var addToMap = [hexgrid];
Takes a set of points and estimates their 'property' values on a grid using the [Inverse Distance Weighting (IDW) method](https://en.wikipedia.org/wiki/Inverse_distance_weighting).
Example:
var points = turfEx.randomPoint(30, {bbox: [50, 30, 70, 50]});

// add a random property to each point
turfEx.featureEach(points, function(point) {
    point.properties.solRad = Math.random() * 50;
});
var options = {gridType: 'points', property: 'solRad', units: 'miles'};
var grid = turfEx.interpolate(points, 100, options);

//addToMap
var addToMap = [grid];
Takes two polygons and finds their intersection. If they share a border, returns the border; if they don't intersect, returns undefined.
Example:
var poly1 = turfEx.polygon([[
  [-122.801742, 45.48565],
  [-122.801742, 45.60491],
  [-122.584762, 45.60491],
  [-122.584762, 45.48565],
  [-122.801742, 45.48565]
]]);

var poly2 = turfEx.polygon([[
  [-122.520217, 45.535693],
  [-122.64038, 45.553967],
  [-122.720031, 45.526554],
  [-122.669906, 45.507309],
  [-122.723464, 45.446643],
  [-122.532577, 45.408574],
  [-122.487258, 45.477466],
  [-122.520217, 45.535693]
]]);

var intersection = turfEx.intersect(poly1, poly2);

//addToMap
var addToMap = [poly1, poly2, intersection];
Takes any type of polygon and an optional mask and returns a polygon exterior ring with holes.
Example:
var polygon = turfEx.polygon([[[112, -21], [116, -36], [146, -39], [153, -24], [133, -10], [112, -21]]]);
var mask = turfEx.polygon([[[90, -55], [170, -55], [170, 10], [90, 10], [90, -55]]]);

var masked = turfEx.mask(polygon, mask);

//addToMap
var addToMap = [masked]
Creates a square grid from a bounding box, Feature or FeatureCollection.
Example:
var bbox = [-95, 30 ,-85, 40];
var cellSide = 50;
var options = {units: 'miles'};

var squareGrid = turfEx.squareGrid(bbox, cellSide, options);

//addToMap
var addToMap = [squareGrid]
Takes a bounding box and a cell depth and returns a set of triangular polygons in a grid.
Example:
var bbox = [-95, 30 ,-85, 40];
var cellSide = 50;
var options = {units: 'miles'};

var triangleGrid = turfEx.triangleGrid(bbox, cellSide, options);

//addToMap
var addToMap = [triangleGrid];
Takes two or more polygons and returns a combined polygon. If the input polygons are not contiguous, this function returns a MultiPolygon feature.
Example:
var poly1 = turfEx.polygon([[
    [-82.574787, 35.594087],
    [-82.574787, 35.615581],
    [-82.545261, 35.615581],
    [-82.545261, 35.594087],
    [-82.574787, 35.594087]
]], {"fill": "#0f0"});
var poly2 = turfEx.polygon([[
    [-82.560024, 35.585153],
    [-82.560024, 35.602602],
    [-82.52964, 35.602602],
    [-82.52964, 35.585153],
    [-82.560024, 35.585153]
]], {"fill": "#00f"});

var union = turfEx.union(poly1, poly2);

//addToMap
var addToMap = [poly1, poly2, union];

Methods

write(geometry)Object

Converts a Geometry to its GeoJSON representation.
Name Type Description
geometry Geometry a Geometry to process.
Returns:
The GeoJSON representation of the Geometry.