Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

turf-buffer

Package Overview
Dependencies
Maintainers
9
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turf-buffer - npm Package Compare versions

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc