@turf/buffer
Advanced tools
Comparing version 4.7.3 to 4.7.4
43
index.js
@@ -6,4 +6,8 @@ var d3 = require('d3-geo'); | ||
var helpers = require('@turf/helpers'); | ||
var turfBbox = require('@turf/bbox'); | ||
var projection = require('@turf/projection'); | ||
var toWgs84 = projection.toWgs84; | ||
var feature = helpers.feature; | ||
var geomEach = meta.geomEach; | ||
var toMercator = projection.toMercator; | ||
var featureEach = meta.featureEach; | ||
@@ -43,5 +47,2 @@ var featureCollection = helpers.featureCollection; | ||
// prevent input mutation | ||
// geojson = JSON.parse(JSON.stringify(geojson)); | ||
// default params | ||
@@ -88,4 +89,3 @@ steps = steps || 64; | ||
// Geometry Types faster than jsts | ||
switch (geometry.type) { | ||
case 'GeometryCollection': | ||
if (geometry.type === 'GeometryCollection') { | ||
var results = []; | ||
@@ -100,12 +100,20 @@ geomEach(geojson, function (geometry) { | ||
// Project GeoJSON to Transverse Mercator projection (convert to Meters) | ||
var distance = radiansToDistance(distanceToRadians(radius, units), 'meters'); | ||
var projection = defineProjection(geojson); | ||
var projected = { | ||
type: geometry.type, | ||
coordinates: projectCoords(geometry.coordinates, projection) | ||
}; | ||
var projected; | ||
var bbox = turfBbox(geojson); | ||
var needsTransverseMercator = bbox[1] > 50 && bbox[3] > 50; | ||
if (needsTransverseMercator) { | ||
var projection = defineProjection(geometry); | ||
projected = { | ||
type: geometry.type, | ||
coordinates: projectCoords(geometry.coordinates, projection) | ||
}; | ||
} else { | ||
projected = toMercator(geometry); | ||
} | ||
// JSTS buffer operation | ||
var reader = new jsts.io.GeoJSONReader(); | ||
var geom = reader.read(projected); | ||
var distance = radiansToDistance(distanceToRadians(radius, units), 'meters'); | ||
var buffered = geom.buffer(distance); | ||
@@ -119,4 +127,13 @@ var writer = new jsts.io.GeoJSONWriter(); | ||
// Unproject coordinates (convert to Degrees) | ||
buffered.coordinates = unprojectCoords(buffered.coordinates, projection); | ||
return feature(buffered, properties); | ||
var result; | ||
if (needsTransverseMercator) { | ||
result = { | ||
type: buffered.type, | ||
coordinates: unprojectCoords(buffered.coordinates, projection) | ||
}; | ||
} else { | ||
result = toWgs84(buffered); | ||
} | ||
return (result.geometry) ? result : feature(result, properties); | ||
} | ||
@@ -123,0 +140,0 @@ |
{ | ||
"name": "@turf/buffer", | ||
"version": "4.7.3", | ||
"version": "4.7.4", | ||
"description": "turf buffer module", | ||
@@ -31,3 +31,4 @@ "main": "index.js", | ||
"Tom MacWright <@tmcw>", | ||
"Denis Carriere <@DenisCarriere>" | ||
"Denis Carriere <@DenisCarriere>", | ||
"Stefano Borghi <@stebogit>" | ||
], | ||
@@ -47,5 +48,7 @@ "license": "MIT", | ||
"dependencies": { | ||
"@turf/center": "^4.7.3", | ||
"@turf/helpers": "^4.7.3", | ||
"@turf/meta": "^4.7.3", | ||
"@turf/bbox": "^4.7.1", | ||
"@turf/center": "4.7.1", | ||
"@turf/helpers": "4.7.1", | ||
"@turf/meta": "4.7.1", | ||
"@turf/projection": "^4.7.1", | ||
"d3-geo": "^1.6.3", | ||
@@ -52,0 +55,0 @@ "jsts": "1.3.0" |
13063
205
7
+ Added@turf/bbox@^4.7.1
+ Added@turf/projection@^4.7.1
+ Added@turf/bbox@4.7.1(transitive)
+ Added@turf/center@4.7.1(transitive)
+ Added@turf/clone@4.7.3(transitive)
+ Added@turf/helpers@4.7.1(transitive)
+ Added@turf/meta@4.7.1(transitive)
+ Added@turf/projection@4.7.3(transitive)
- Removed@turf/center@4.7.3(transitive)
- Removed@turf/helpers@4.7.3(transitive)
Updated@turf/center@4.7.1
Updated@turf/helpers@4.7.1
Updated@turf/meta@4.7.1