Comparing version 0.0.79 to 0.0.80
// look here for help http://svn.osgeo.org/grass/grass/branches/releasebranch_6_4/vector/v.overlay/main.c | ||
//must be array of polygons | ||
// depend on jsts for now https://github.com/bjornharrtell/jsts/blob/master/examples/overlay.html | ||
var jsts = require('jsts') | ||
var t = {} | ||
t.featurecollection = require('./featurecollection') | ||
module.exports = function(polys1, polys2, done){ | ||
var reader = new jsts.io.GeoJSONReader() | ||
var a = reader.read(JSON.stringify(polys1.features[0].geometry)) | ||
var b = reader.read(JSON.stringify(polys2.features[0].geometry)) | ||
var union = a.union(b); | ||
var parser = new jsts.io.GeoJSONParser() | ||
union = parser.write(union) | ||
union = t.featurecollection([union]) | ||
done(null, union) | ||
} |
{ | ||
"name": "turf", | ||
"version": "0.0.79", | ||
"version": "0.0.80", | ||
"description": "a node.js library for performing geospatial operations with geojson", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -72,2 +72,4 @@ turf | ||
- [aggregate](#aggregate) | ||
- [union](#union) | ||
- [intersect](#intersect) | ||
@@ -83,4 +85,2 @@ **Planned Features** | ||
- area | ||
- intersect | ||
- union | ||
- erase | ||
@@ -832,2 +832,38 @@ - smooth | ||
###union | ||
Calculates the union of two polygon features or feature collections. | ||
```javascript | ||
var t = require('turf') | ||
t.load(__dirname + '/testIn/Intersect1.geojson', function(err, polys1){ | ||
t.load(__dirname + '/testIn/Intersect2.geojson', function(err, polys2){ | ||
t.union(polys1, polys2, function(err, unioned){ | ||
if(err) throw err | ||
console.log(unioned) | ||
}) | ||
}) | ||
}) | ||
``` | ||
###intersect | ||
Calculates the intersection of two polygon features or feature collections. | ||
```javascript | ||
var t = require('turf') | ||
t.load(__dirname + '/testIn/Intersect1.geojson', function(err, polys1){ | ||
t.load(__dirname + '/testIn/Intersect2.geojson', function(err, polys2){ | ||
t.intersect(polys1, polys2, function(err, intersected){ | ||
if(err) throw err | ||
console.log(intersected) | ||
}) | ||
}) | ||
}) | ||
``` | ||
- - - | ||
@@ -834,0 +870,0 @@ |
@@ -1,8 +0,30 @@ | ||
var t = require('../lib/intersect') | ||
var t = require('../index'), | ||
should = require('should'), | ||
fs = require('fs') | ||
describe('intersect', function(){ | ||
xit('should ', function(done){ | ||
throw new Error('not implemented') | ||
done() | ||
it('should return the overlap of two polygons', function(done){ | ||
t.load(__dirname + '/testIn/Intersect1.geojson', function(err, polys1){ | ||
t.load(__dirname + '/testIn/Intersect2.geojson', function(err, polys2){ | ||
t.intersect(polys1, polys2, function(err, intersected){ | ||
if(err) throw err | ||
intersected.features[0].should.be.ok | ||
fs.writeFileSync(__dirname + '/testOut/intersected1.geojson', JSON.stringify(intersected)) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
it('should return the overlap of two polygons', function(done){ | ||
t.load(__dirname + '/testIn/Intersect1.geojson', function(err, polys1){ | ||
t.load(__dirname + '/testIn/Intersect3.geojson', function(err, polys2){ | ||
t.intersect(polys1, polys2, function(err, intersected){ | ||
if(err) throw err | ||
intersected.features[0].should.be.ok | ||
fs.writeFileSync(__dirname + '/testOut/intersected2.geojson', JSON.stringify(intersected)) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
@@ -1,8 +0,18 @@ | ||
var t = require('../lib/union') | ||
var t = require('../index'), | ||
should = require('should'), | ||
fs = require('fs') | ||
describe('union', function(){ | ||
xit('should ', function(done){ | ||
throw new Error('not implemented') | ||
done() | ||
it('should return the union of two polygons', function(done){ | ||
t.load(__dirname + '/testIn/Intersect1.geojson', function(err, polys1){ | ||
t.load(__dirname + '/testIn/Intersect2.geojson', function(err, polys2){ | ||
t.union(polys1, polys2, function(err, unioned){ | ||
if(err) throw err | ||
unioned.features[0].should.be.ok | ||
fs.writeFileSync(__dirname + '/testOut/unioned.geojson', JSON.stringify(unioned)) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
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
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
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
3248541
216
21407
874
28