Socket
Socket
Sign inDemoInstall

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.73 to 0.0.79

docco/area.html

4

index.js
module.exports = {
min: require('./lib/min'),
max: require('./lib/max'),
aggregate: require('./lib/aggregate'),
flip: require('./lib/flip'),
simplify: require('./lib/simplify'),

@@ -3,0 +7,0 @@ sum: require('./lib/sum'),

25

lib/average.js
var t = {}
var _ = require('lodash')
t.tag = require('./tag')
var _ = require('lodash'),
ss = require('simple-statistics')
t.inside = require('./inside')
module.exports = function(polyFC, PtFC, field, outField, polyID, done){
t.tag(ptFC, polyFC, polyID, function(err, taggedPts){
_.groupBy(taggedPts9)
module.exports = function(polyFC, ptFC, inField, outField, done){
_.each(polyFC.features, function(poly){
if(!poly.properties){
poly.properties = {}
}
var values = []
_.each(ptFC.features, function(pt){
t.inside(pt, poly, function(err, isInside){
if(isInside){
values.push(pt.properties[inField])
}
})
})
poly.properties[outField] = ss.average(values)
})
done(new Error('not implemented'))
done(null, polyFC)
}

@@ -1,5 +0,22 @@

var _ = require('lodash')
var t = {}
var _ = require('lodash'),
ss = require('simple-statistics')
t.inside = require('./inside')
module.exports = function(polyFC, ptFC, field, outField, done){
done(new Error('not implemented'))
module.exports = function(polyFC, ptFC, inField, outField, done){
_.each(polyFC.features, function(poly){
if(!poly.properties){
poly.properties = {}
}
var values = []
_.each(ptFC.features, function(pt){
t.inside(pt, poly, function(err, isInside){
if(isInside){
values.push(pt.properties[inField])
}
})
})
poly.properties[outField] = ss.sum(values)
})
done(null, polyFC)
}

@@ -5,3 +5,3 @@ var t = {}

module.exports = function(points, polygons, field, done){
module.exports = function(points, polygons, field, outField, done){
_.each(points.features, function(pt){

@@ -12,9 +12,9 @@ if(!pt.properties){

_.each(polygons.features, function(poly){
if(!pt.properties[field]){
if(!pt.properties[outField]){
t.inside(pt, poly, function(err, isInside){
if(isInside){
pt.properties[field] = poly.properties[field]
pt.properties[outField] = poly.properties[field]
}
else{
pt.properties[field] = null
pt.properties[outField] = null
}

@@ -21,0 +21,0 @@ })

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

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

@@ -9,2 +9,6 @@ turf

- - -
##Installation
```bash

@@ -26,45 +30,46 @@ npm install turf

- - -
*note: This module is under active development and is in a pre-release form. The first official release is planned mid November 2013. Most features are pretty stable, but expect some changes periodically up until then.*
##Features
- - -
- [load](#load)
- [save](#save)
- [point](#point)
- [linestring](#linestring)
- [polygon](#polygon)
- [featurecollection](#featurecollection)
- [extent](#extent)
- [square](#square)
- [size](#size)
- [center](#center)
- [bboxPolygon](#bboxPolygon)
- [envelope](#envelope)
- [centroid](#centroid)
- [flip](#flip)
- [explode](#explode)
- [combine](#combine)
- [remove](#remove)
- [filter](#filter)
- [distance](#distance)
- [buffer](#buffer)
- [nearest](#nearest)
- [tin](#tin)
- [grid](#grid)
- [planepoint](#planepoint)
- [inside](#inside)
- [midpoint](#midpoint)
- [quantile](#quantile)
- [jenks](#jenks)
- [reclass](#reclass)
- [contour](#contour)
- [sample](#sample)
- [tag](#tag)
- [bezier](#bezier)
- [simplify](#simplify)
- [average](#average)
- [sum](#sum)
- [min](#min)
- [max](#max)
- [aggregate](#aggregate)
**Features**
- load
- save
- point
- linestring
- polygon
- featurecollection
- extent
- square
- size
- center
- bboxPolygon
- envelope
- centroid
- explode
- combine
- remove
- filter
- distance
- buffer
- nearest
- tin
- grid
- planepoint
- inside
- midpoint
- quantile
- jenks
- reclass
- contour
- sample
- tag
- bezier
- simplify
**Planned Features**

@@ -74,5 +79,2 @@

- sum
- average
- aggregate
- krige

@@ -90,5 +92,5 @@ - interval

***Examples:***
##Examples:
**load**
###load

@@ -108,3 +110,3 @@ Loads a Feature or FeaturCollection from a file.

**save**
###save

@@ -125,3 +127,3 @@ Saves out a feature or feature collection. 'geojson' and 'topojson' are currently supported.

**point**
###point

@@ -140,3 +142,3 @@ Creates a geojson point Feature based on an x and a y coordinate. Properties can be added optionally.

**linestring**
###linestring

@@ -156,3 +158,3 @@ Creates a geojson linestring Feature based on a coordinate array. Properties can be added optionally.

**polygon**
###polygon

@@ -172,3 +174,3 @@ Creates a geojson polygon Feature based on a coordinate array. Properties can be added optionally.

**featurecollection**
###featurecollection

@@ -188,3 +190,3 @@ Creates a geojson FeatureCollection based on an array of features.

**extent**
###extent

@@ -205,3 +207,3 @@ Calculates the extent of all features and returns a bounding box.

**square**
###square

@@ -221,3 +223,3 @@ Calculates the minimum square bounding box for another bounding box.

**size**
###size

@@ -236,3 +238,3 @@ Takes a bbox and returns a new bbox with a size expanded or contracted by a factor of X.

**center**
###center

@@ -253,3 +255,3 @@ Calculates the absolute center point of all features.

**bboxPolygon**
###bboxPolygon

@@ -269,3 +271,3 @@ Takes a bbox and returns the equivalent polygon feature.

**envelope**
###envelope

@@ -288,3 +290,3 @@ Takes a Feature or FeatureCollection and returns a rectangular polygon feature that encompasses all vertices.

**centroid**
###centroid

@@ -304,4 +306,19 @@ Calculates the centroid of a polygon Feature or FeatureCollection using the geometric mean of all vertices. This lessons the effect of small islands and artifacts when calculating the centroid of a set of polygons.

**explode**
###flip
Takes a point, linestring, polygon, or featurecollection, and flips all of its coordinates from [x, y] to [y, x].
```javascript
var t = require('turf')
var poly = t.polygon([[[1,0], [1,0], [1,2]], [[.2,.2], [.3,.3],[.1,.2]]])
t.flip(poly, function(err, flipped){
if(err) throw err
console.log(flipped)
})
```
###explode
Takes a Feature or FeatureCollection and return all vertices as a collection of points.

@@ -320,3 +337,3 @@

**combine**
###combine

@@ -338,3 +355,3 @@ Combines feature collection of point, linestring, or polygon features into multipoint, multilinestring, or multipolygon features.

**remove**
###remove

@@ -356,3 +373,3 @@ Removes any features from a feature collection that match a property value.

**filter**
###filter

@@ -379,3 +396,3 @@ Keeps any features from a feature collection that match a property value.

**inside**
###inside

@@ -396,3 +413,3 @@ Checks to see if a point is inside of a polygon. The polygon can be convex or concave.

**buffer**
###buffer

@@ -414,3 +431,3 @@ Buffers a point feature to a given radius. Lines and Polygons support coming soon. Unit selection coming soon too (degrees, miles, km).

**distance**
###distance

@@ -432,3 +449,3 @@ Calculates the distance between two point features in degrees, radians, miles, or kilometers. This uses the haversine formula to account for global curvature.

**nearest**
###nearest

@@ -453,3 +470,3 @@ Returns the nearest point feature.

**tin**
###tin

@@ -471,3 +488,3 @@ Takes a set of points and the name of a z-value property and creates a tin (Triangulated Irregular Network). These are often used for developing elevation contour maps or stepped heat visualizations.

**grid**
###grid

@@ -486,3 +503,3 @@ Takes a bounding box and a cell depth and outputs a feature collection of points in a grid.

**planepoint**
###planepoint

@@ -508,3 +525,3 @@ Takes a trianglular plane and calculates the z value for a point on the plane.

**midpoint**
###midpoint

@@ -526,3 +543,3 @@ Takes two point features and returns the mid point.

**quantile**
###quantile

@@ -546,3 +563,3 @@ Takes a set of features, a property name, and a set of percentiles and outputs a quantile array. This can be passed as a break array to the contour function.

**jenks**
###jenks

@@ -566,3 +583,3 @@ Takes a set of features, a property name, and the desired number of breaks and outputs an array of natural breaks. This classification can be used in the contour function or for theming.

**reclass**
###reclass

@@ -588,3 +605,3 @@ Takes a feature collection, a in field, an out field, and an array of translations and outputs an identical feature collection with the out field property populated.

**contour**
###contour

@@ -608,3 +625,3 @@ Takes a FeatureCollection of points with z values and an array of value breaks and generates contour polygons. This is a great way to visualize interpolated density on a map. It is often used for elevation maps, weather maps, and isocrones. The main advantage over a heat map is that contours allow you to see definitive value boundaries, and the polygons can be used to aggregate data. For example, you could get the 5000 ft elevation contour of a mountain and the 10000 ft elevation contour, then aggregate the number of trees in each to see how elevation affects tree survival.

**sample**
###sample

@@ -627,3 +644,3 @@ Takes a feature collection and returns N random features as a feature collection.

**tag**
###tag

@@ -637,3 +654,3 @@ Performs a spatial join on a set of points from a set of polygons.

t.load('./testIn/tagPolygons.geojson', function(err, polygons){
t.tag(points, polygons, 'polyID', function(err, taggedPoints){
t.tag(points, polygons, 'polyID', 'containingPolyID', function(err, taggedPoints){
console.log(taggedPoints)

@@ -646,3 +663,3 @@ })

**bezier**
###bezier

@@ -681,3 +698,3 @@ Takes a linestring and outputs a curved version of the line.

**simplify**
###simplify

@@ -699,2 +716,153 @@ Takes a feature collection of polygons or linestrings and returns a simplified version, preserving topology of shared boundaries.

###average
Calculates the average value of a field for points within a set of polygons.
```javascript
var t = require('turf')
var poly1 = t.polygon([[[0,0],[10,0],[10,10], [0,10]]])
var poly2 = t.polygon([[[10,0],[20,10],[20,20], [20,0]]])
var polyFC = t.featurecollection([poly1, poly2])
var pt1 = t.point(5,5, {population: 200})
var pt2 = t.point(1,3, {population: 600})
var pt3 = t.point(14,2, {population: 100})
var pt4 = t.point(13,1, {population: 200})
var pt5 = t.point(19,7, {population: 300})
var ptFC = t.featurecollection([pt1, pt2, pt3, pt4, pt5])
t.average(polyFC, ptFC, 'population', 'pop_avg', function(err, averaged){
if(err) throw err
console.log(averaged.features[0].properties.pop_avg) // 400
console.log(averaged.features[1].properties.pop_avg) // 200
})
```
###sum
Calculates the sum value of a field for points within a set of polygons.
```javascript
var t = require('turf')
var poly1 = t.polygon([[[0,0],[10,0],[10,10], [0,10]]])
var poly2 = t.polygon([[[10,0],[20,10],[20,20], [20,0]]])
var polyFC = t.featurecollection([poly1, poly2])
var pt1 = t.point(1,1, {population: 500})
var pt2 = t.point(1,3, {population: 400})
var pt3 = t.point(14,2, {population: 600})
var pt4 = t.point(13,1, {population: 500})
var pt5 = t.point(19,7, {population: 200})
var ptFC = t.featurecollection([pt1, pt2, pt3, pt4, pt5])
t.sum(polyFC, ptFC, 'population', 'pop_sum', function(err, averaged){
if(err) throw err
console.log(averaged.features[0].properties.pop_sum) // 900
console.log(averaged.features[1].properties.pop_sum) // 1300
})
```
###min
Calculates the min value of a field for points within a set of polygons.
```javascript
var t = require('turf')
var poly1 = t.polygon([[[0,0],[10,0],[10,10], [0,10]]])
var poly2 = t.polygon([[[10,0],[20,10],[20,20], [20,0]]])
var polyFC = t.featurecollection([poly1, poly2])
var pt1 = t.point(1,1, {population: 500})
var pt2 = t.point(1,3, {population: 400})
var pt3 = t.point(14,2, {population: 600})
var pt4 = t.point(13,1, {population: 500})
var pt5 = t.point(19,7, {population: 200})
var ptFC = t.featurecollection([pt1, pt2, pt3, pt4, pt5])
t.min(polyFC, ptFC, 'population', 'pop_min', function(err, minPolys){
if(err) throw err
console.log(minPolys.features[0].properties.pop_min) // 400
console.log(minPolys.features[1].properties.pop_min) // 200
})
```
###max
Calculates the min value of a field for points within a set of polygons.
```javascript
var t = require('turf')
var poly1 = t.polygon([[[0,0],[10,0],[10,10], [0,10]]])
var poly2 = t.polygon([[[10,0],[20,10],[20,20], [20,0]]])
var polyFC = t.featurecollection([poly1, poly2])
var pt1 = t.point(1,1, {population: 500})
var pt2 = t.point(1,3, {population: 400})
var pt3 = t.point(14,2, {population: 600})
var pt4 = t.point(13,1, {population: 500})
var pt5 = t.point(19,7, {population: 200})
var ptFC = t.featurecollection([pt1, pt2, pt3, pt4, pt5])
t.max(polyFC, ptFC, 'population', 'pop_max', function(err, maxPolys){
if(err) throw err
console.log(maxPolys.features[0].properties.pop_max) // 500
console.log(maxPolys.features[1].properties.pop_max) // 600
})
```
###aggregate
Takes a set of polygons, a set of points, and an array of aggregations, then perform them. Sum, average, min, and max are supported.
```javascript
var t = require('turf')
var poly1 = t.polygon([[[0,0],[10,0],[10,10],[0,10]]])
var poly2 = t.polygon([[[10,0],[20,10],[20,20], [20,0]]])
var polyFC = t.featurecollection([poly1, poly2])
var pt1 = t.point(5,5, {population: 200})
var pt2 = t.point(1,3, {population: 600})
var pt3 = t.point(14,2, {population: 100})
var pt4 = t.point(13,1, {population: 200})
var pt5 = t.point(19,7, {population: 300})
var ptFC = t.featurecollection([pt1, pt2, pt3, pt4, pt5])
var aggregations = [
{
aggregation: 'sum',
inField: 'population',
outField: 'pop_sum'
},
{
aggregation: 'average',
inField: 'population',
outField: 'pop_avg'
},
{
aggregation: 'min',
inField: 'population',
outField: 'pop_min'
},
{
aggregation: 'max',
inField: 'population',
outField: 'pop_max'
}
]
t.aggregate(polyFC, ptFC, aggregations, function(err, polys){
if(err) throw err
console.log(polys)
})
```
- - -

@@ -701,0 +869,0 @@

@@ -6,6 +6,6 @@ var t = require('../index'),

it('should create an average of field for all points within a set of polygons', function(done){
var poly1 = t.polygon([[[0,0],[0,10],[10,10],10,0]])
var poly2 = t.polygon([[[10,0],[10,10],[20,10],20,0]])
var poly1 = t.polygon([[[0,0],[10,0],[10,10], [0,10]]])
var poly2 = t.polygon([[[10,0],[20,10],[20,20], [20,0]]])
var polyFC = t.featurecollection([poly1, poly2])
var pt1 = t.point(1,1, {population: 200})
var pt1 = t.point(5,5, {population: 200})
var pt2 = t.point(1,3, {population: 600})

@@ -21,5 +21,5 @@ var pt3 = t.point(14,2, {population: 100})

averaged.features.should.be.ok
averaged.features[0].geometry.type.should.equal('polygon')
averaged.features[0].properties.population_avg.should.equal(400)
averaged.features[1].properties.population_avg.should.equal(200)
averaged.features[0].geometry.type.should.equal('Polygon')
averaged.features[0].properties.pop_avg.should.equal(400)
averaged.features[1].properties.pop_avg.should.equal(200)
done()

@@ -26,0 +26,0 @@ })

@@ -7,6 +7,6 @@ var t = require('../index'),

it('should take a set of points with z values and output a set of contour polygons', function(done){
t.load('../test/testIn/Points3.geojson', function(err, points){
t.load('../test/testIn/elevation1.geojson', function(err, points){
t.contour(points, 'elevation', 15, [25, 45, 55, 65, 85, 95, 105, 120, 180], function(err, contours){
if(err) throw err
fs.writeFileSync('./testOut/contours.geojson', JSON.stringify(contours))
fs.writeFileSync('./testOut/contours1.geojson', JSON.stringify(contours))
contours.should.be.ok

@@ -18,2 +18,38 @@ contours.features.should.be.ok

})
it('should take a set of points with z values and output a set of contour polygons with jenks breaks', function(done){
t.load('../test/testIn/elevation1.geojson', function(err, points){
t.jenks(points, 'elevation', 5, function(err, breaks){
if(err) throw err
t.contour(points, 'elevation', 15, breaks, function(err, contours){
if(err) throw err
fs.writeFileSync('./testOut/contours2.geojson', JSON.stringify(contours))
contours.should.be.ok
contours.features.should.be.ok
done()
})
})
})
})
it('should take a set of points with decimal z values and output a set of contour polygons', function(done){
t.load('../test/testIn/elevation2.geojson', function(err, points){
t.contour(points, 'elevation', 15, [-2000,-20, -5, -1, 0, 2, 5, 10, 20, 30, 500 ], function(err, contours){
if(err) throw err
fs.writeFileSync('./testOut/contours3.geojson', JSON.stringify(contours))
contours.should.be.ok
contours.features.should.be.ok
done()
})
})
})
it('should take a set of points with negative z values and output a set of contour polygons', function(done){
t.load('../test/testIn/elevation3.geojson', function(err, points){
t.contour(points, 'elevation', 15, [25, 45, 55, 65, 85, 95, 105, 120, 180], function(err, contours){
if(err) throw err
fs.writeFileSync('./testOut/contours4.geojson', JSON.stringify(contours))
contours.should.be.ok
contours.features.should.be.ok
done()
})
})
})
})

@@ -5,3 +5,3 @@ var t = require('../index'),

describe('sample', function(){
xit('should take a feature collection and a number and return a random sample of n length', function(done){
it('should take a feature collection and a number and return a random sample of n length', function(done){
var num = 10

@@ -8,0 +8,0 @@

@@ -6,10 +6,10 @@ var t = require('../index'),

describe('simplify', function(){
it('should simplify a complex polygon or linestring', function(done){
t.load('./testOut/contours.geojson', function(err, polys){
it('should simplify a featurecollection of complex polygon', function(done){
t.load('./testIn/complexPolygons.geojson', function(err, geo){
if(err) throw err
polys.should.be.ok
t.simplify(polys, 50, 0, function(err, simplified){
geo.should.be.ok
t.simplify(geo, 50, 0, function(err, simplified){
if(err) throw err
simplified.should.be.ok
fs.writeFileSync('./testOut/simplified.geojson', JSON.stringify(simplified))
fs.writeFileSync('./testOut/simplifiedPolygons.geojson', JSON.stringify(simplified))
done()

@@ -19,2 +19,38 @@ })

})
})
it('should simplify a featurecollection of complex linestrings', function(done){
t.load('./testIn/complexLines.geojson', function(err, geo){
if(err) throw err
geo.should.be.ok
t.simplify(geo, 50, 0, function(err, simplified){
if(err) throw err
simplified.should.be.ok
fs.writeFileSync('./testOut/simplifiedLines.geojson', JSON.stringify(simplified))
done()
})
})
})
it('should simplify a complex polygon', function(done){
t.load('./testIn/complexPolygon.geojson', function(err, geo){
if(err) throw err
geo.should.be.ok
t.simplify(geo, 50, 0, function(err, simplified){
if(err) throw err
simplified.should.be.ok
fs.writeFileSync('./testOut/simplifiedPolygon.geojson', JSON.stringify(simplified))
done()
})
})
})
it('should simplify a complex linestring', function(done){
t.load('./testIn/complexLine.geojson', function(err, geo){
if(err) throw err
geo.should.be.ok
t.simplify(geo, 50, 0, function(err, simplified){
if(err) throw err
simplified.should.be.ok
fs.writeFileSync('./testOut/simplifiedLine.geojson', JSON.stringify(simplified))
done()
})
})
})
})

@@ -6,21 +6,21 @@ var t = require('../index'),

it('should create a sum of field for all points within a set of polygons', function(done){
var poly1 = t.polygon([[[0,0],[0,10],[10,10],10,0]])
var poly2 = t.polygon([[[10,0],[10,10],[20,10],20,0]])
var poly1 = t.polygon([[[0,0],[10,0],[10,10],[0,10]]])
var poly2 = t.polygon([[[10,0],[20,10],[20,20], [20,0]]])
var polyFC = t.featurecollection([poly1, poly2])
var pt1 = t.point(1,1, {population: 100})
var pt2 = t.point(1,3, {population: 100})
var pt3 = t.point(14,2, {population: 100})
var pt4 = t.point(13,1, {population: 100})
var pt5 = t.point(19,7, {population: 100})
var pt1 = t.point(1,1, {population: 500})
var pt2 = t.point(1,3, {population: 400})
var pt3 = t.point(14,2, {population: 600})
var pt4 = t.point(13,1, {population: 500})
var pt5 = t.point(19,7, {population: 200})
var ptFC = t.featurecollection([pt1, pt2, pt3, pt4, pt5])
t.sum(polyFC, ptFC, 'population', 'pop_sum', function(err, summed){
t.sum(polyFC, ptFC, 'population', 'population_sum', function(err, summed){
if(err) throw err
summed.should.be.ok
summed.features.should.be.ok
summed.features[0].properties.population_sum.should.equal(200)
summed.features[1].properties.population_sum.should.equal(400)
summed.features[0].properties.population_sum.should.equal(900)
summed.features[1].properties.population_sum.should.equal(1300)
done()
})
})
})
})

@@ -11,3 +11,3 @@ var t = require('../index'),

if(err) throw err
t.tag(points, polygons, 'polyID', function(err, taggedPoints){
t.tag(points, polygons, 'polyID', 'containingPolyID', function(err, taggedPoints){
if(err) throw err

@@ -22,2 +22,2 @@ taggedPoints.should.be.ok

})
})
})

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