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

turf

Package Overview
Dependencies
Maintainers
1
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turf - npm Package Compare versions

Comparing version 0.0.88 to 0.0.89

test/testIn/bufferPolygonIn.geojson

47

lib/buffer.js
//http://stackoverflow.com/questions/839899/how-do-i-calculate-a-point-on-a-circles-circumference
//radians = degrees * (pi/180)
var _ = require('lodash')
// https://github.com/bjornharrtell/jsts/blob/master/examples/buffer.html
module.exports = function(point, radius, units, done){
var geometry = point.geometry
var type = geometry.type
var polygon = {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": []
}
}
var _ = require('lodash'),
jsts = require('jsts')
var t = {}
t.featurecollection = require('./featurecollection')
t.polygon = require('./polygon')
module.exports = function(feature, radius, units, union, done){
switch(units){

@@ -27,24 +23,11 @@ case 'miles':

}
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)
switch(type){
case 'Point':
var coordinates = []
var x = geometry.coordinates[0]
var y = geometry.coordinates[1]
var range = _.range(-180, 180, 1)
for(var i in _.range(0, 360)){
var xC = x + radius * Math.cos(range[i] * (Math.PI / 180))
var yC = y + radius * Math.sin(range[i] * (Math.PI / 180))
coordinates.push([xC, yC])
}
polygon.geometry.coordinates = [coordinates]
done(null, polygon)
break
case 'LineString':
done(new Error('LineString not implemented'))
break
case 'Polygon':
done(new Error('Polygon not implemented'))
break
}
buffered = t.featurecollection([t.polygon(buffered.coordinates)])
done(null, buffered)
}

@@ -11,3 +11,6 @@ module.exports = function(coordinates, properties){

}
if(!polygon.properties){
polygon.properties = {}
}
return polygon

@@ -14,0 +17,0 @@ }

{
"name": "turf",
"version": "0.0.88",
"version": "0.0.89",
"description": "a node.js library for performing geospatial operations with geojson",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -417,3 +417,3 @@ turf

Buffers a point feature to a given radius. Lines and Polygons support coming soon. Unit selection coming soon too (degrees, miles, km).
Buffers a point, linestring, or polygon feature to a given radius. Units supported are miles, kilometers, and degrees.

@@ -420,0 +420,0 @@

@@ -1,2 +0,3 @@

var t = require('../index'), fs = require('fs')
var t = require('../index'),
fs = require('fs')

@@ -6,3 +7,3 @@ describe('buffer', function(){

t.load('../test/testIn/Point1.geojson', function(err, pt){
t.buffer(pt, 10, 'miles', function(err, buffered){
t.buffer(pt, 10, 'miles', false, function(err, buffered){
fs.writeFileSync('./testOut/buffered.geojson',JSON.stringify(buffered))

@@ -15,5 +16,5 @@ if(err) throw err

it('should buffer a LineString', function(done){
t.load('../test/testIn/Point1.geojson', function(err, pt){
t.buffer(pt, 10, 'miles', function(err, buffered){
fs.writeFileSync('./testOut/buffered.geojson',JSON.stringify(buffered))
t.load('../test/testIn/bezierIn.geojson', function(err, pt){
t.buffer(pt, 10, 'miles', false, function(err, buffered){
fs.writeFileSync('./testOut/bufferedLine.geojson',JSON.stringify(buffered))
if(err) throw err

@@ -25,5 +26,5 @@ done()

it('should buffer a Polygon', function(done){
t.load('../test/testIn/Point1.geojson', function(err, pt){
t.buffer(pt, 10, 'miles', function(err, buffered){
fs.writeFileSync('./testOut/buffered.geojson',JSON.stringify(buffered))
t.load('../test/testIn/bufferPolygonIn.geojson', function(err, pt){
t.buffer(pt, 10, 'miles', false, function(err, buffered){
fs.writeFileSync('./testOut/bufferedPolygon.geojson',JSON.stringify(buffered))
if(err) throw err

@@ -36,3 +37,3 @@ done()

t.load('../test/testIn/Point1.geojson', function(err, pt){
t.buffer(pt, 10, 'miles', function(err, buffered){
t.buffer(pt, 10, 'miles', false, function(err, buffered){
fs.writeFileSync('./testOut/buffered.geojson',JSON.stringify(buffered))

@@ -46,3 +47,3 @@ if(err) throw err

t.load('../test/testIn/Point1.geojson', function(err, pt){
t.buffer(pt, 10, 'miles', function(err, buffered){
t.buffer(pt, 10, 'miles', true, function(err, buffered){
fs.writeFileSync('./testOut/buffered.geojson',JSON.stringify(buffered))

@@ -49,0 +50,0 @@ if(err) throw err

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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