turf-buffer
Advanced tools
Comparing version 1.1.0 to 3.0.0-canary.2f5f7167
110
index.js
@@ -5,3 +5,4 @@ // http://stackoverflow.com/questions/839899/how-do-i-calculate-a-point-on-a-circles-circumference | ||
var featurecollection = require('turf-featurecollection'); | ||
var helpers = require('turf-helpers'); | ||
var featureCollection = helpers.featureCollection; | ||
var jsts = require('jsts'); | ||
@@ -11,69 +12,52 @@ var normalize = require('geojson-normalize'); | ||
/** | ||
* Calculates a buffer for input features for a given radius. Units supported are miles, kilometers, and degrees. | ||
* | ||
* @module turf/buffer | ||
* @category transformation | ||
* @param {(Feature|FeatureCollection)} feature input to be buffered | ||
* @param {Number} distance distance to draw the buffer | ||
* @param {String} unit 'miles', 'feet', 'kilometers', 'meters', or 'degrees' | ||
* @return {FeatureCollection<Polygon>|FeatureCollection<MultiPolygon>|Polygon|MultiPolygon} buffered features | ||
* | ||
* @example | ||
* var pt = { | ||
* "type": "Feature", | ||
* "properties": {}, | ||
* "geometry": { | ||
* "type": "Point", | ||
* "coordinates": [-90.548630, 14.616599] | ||
* } | ||
* }; | ||
* var unit = 'miles'; | ||
* | ||
* var buffered = turf.buffer(pt, 500, unit); | ||
* var result = turf.featurecollection([buffered, pt]); | ||
* | ||
* //=result | ||
*/ | ||
* Calculates a buffer for input features for a given radius. Units supported are miles, kilometers, and degrees. | ||
* | ||
* @name buffer | ||
* @category transformation | ||
* @param {(Feature|FeatureCollection)} feature input to be buffered | ||
* @param {Number} distance distance to draw the buffer | ||
* @param {String} unit any of the options supported by turf units | ||
* @return {FeatureCollection<Polygon>|FeatureCollection<MultiPolygon>|Polygon|MultiPolygon} buffered features | ||
* | ||
* @example | ||
* var pt = { | ||
* "type": "Feature", | ||
* "properties": {}, | ||
* "geometry": { | ||
* "type": "Point", | ||
* "coordinates": [-90.548630, 14.616599] | ||
* } | ||
* }; | ||
* var unit = 'miles'; | ||
* | ||
* var buffered = turf.buffer(pt, 500, unit); | ||
* var result = turf.featurecollection([buffered, pt]); | ||
* | ||
* //=result | ||
*/ | ||
module.exports = function(feature, radius, units) { | ||
module.exports = function (feature, radius, units) { | ||
switch (units) { | ||
case 'miles': | ||
radius = radius / 69.047; | ||
break; | ||
case 'feet': | ||
radius = radius / 364568.0; | ||
break; | ||
case 'kilometers': | ||
radius = radius / 111.12; | ||
break; | ||
case 'meters': | ||
case 'metres': | ||
radius = radius / 111120.0; | ||
break; | ||
case 'degrees': | ||
break; | ||
} | ||
var degrees = helpers.distanceToDegrees(radius, units); | ||
var fc = normalize(feature); | ||
var buffered = normalize(featureCollection(fc.features.map(function (f) { | ||
return bufferOp(f, degrees); | ||
}))); | ||
var fc = normalize(feature); | ||
var buffered = normalize(featurecollection(fc.features.map(function(f) { | ||
return bufferOp(f, radius); | ||
}))); | ||
if(buffered.features.length > 1) return buffered; | ||
else if(buffered.features.length === 1) return buffered.features[0]; | ||
if (buffered.features.length > 1) return buffered; | ||
else if (buffered.features.length === 1) return buffered.features[0]; | ||
}; | ||
var bufferOp = function(feature, radius) { | ||
var reader = new jsts.io.GeoJSONReader(); | ||
var geom = reader.read(JSON.stringify(feature.geometry)); | ||
var buffered = geom.buffer(radius); | ||
var parser = new jsts.io.GeoJSONParser(); | ||
buffered = parser.write(buffered); | ||
function bufferOp(feature, radius) { | ||
var reader = new jsts.io.GeoJSONReader(); | ||
var geom = reader.read(feature.geometry); | ||
var buffered = geom.buffer(radius); | ||
var writer = new jsts.io.GeoJSONWriter(); | ||
buffered = writer.write(buffered); | ||
return { | ||
type: 'Feature', | ||
geometry: buffered, | ||
properties: {} | ||
}; | ||
}; | ||
return { | ||
type: 'Feature', | ||
geometry: buffered, | ||
properties: {} | ||
}; | ||
} |
{ | ||
"name": "turf-buffer", | ||
"version": "1.1.0", | ||
"version": "3.0.0-canary.2f5f7167", | ||
"description": "turf buffer module", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node ./test/test.js", | ||
"doc": "dox -r < index.js | doxme --readme > README.md" | ||
"test": "node ./test/test.js" | ||
}, | ||
@@ -31,17 +30,14 @@ "repository": { | ||
"benchmark": "^1.0.0", | ||
"dox": "^0.7.0", | ||
"doxme": "^1.8.2", | ||
"glob": "^5.0.3", | ||
"tape": "^3.5.0", | ||
"turf-distance": "^1.0.1", | ||
"turf-extent": "^1.0.4", | ||
"turf-point": "^2.0.1" | ||
"turf-distance": "^3.0.0-canary.2f5f7167", | ||
"turf-bbox": "^3.0.0-canary.2f5f7167", | ||
"turf-helpers": "^3.0.0-canary.2f5f7167" | ||
}, | ||
"dependencies": { | ||
"geojson-normalize": "0.0.0", | ||
"jsts": "^0.15.0", | ||
"turf-combine": "^1.0.2", | ||
"turf-featurecollection": "^1.0.1", | ||
"turf-polygon": "^1.0.3" | ||
"jsts": "1.1.1", | ||
"turf-combine": "^3.0.0-canary.2f5f7167", | ||
"turf-helpers": "^3.0.0-canary.2f5f7167" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
NPM Shrinkwrap
Supply chain riskPackage contains a shrinkwrap file. This may allow the package to bypass normal install procedures.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
4
6
0
0
1
6325
6
80
1
+ Addedjsts@1.1.1(transitive)
+ Addedturf-combine@3.0.12(transitive)
+ Addedturf-helpers@3.0.12(transitive)
+ Addedturf-meta@3.0.12(transitive)
- Removedturf-featurecollection@^1.0.1
- Removedturf-polygon@^1.0.3
- Removedjavascript.util@0.12.12(transitive)
- Removedjsts@0.15.0(transitive)
- Removedturf-combine@1.1.0(transitive)
- Removedturf-featurecollection@1.0.1(transitive)
- Removedturf-polygon@1.0.3(transitive)
Updatedjsts@1.1.1