Skip to content

Commit

Permalink
Finish turf-combine rethink
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Apr 23, 2016
1 parent 4dcb9a1 commit a4813f3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/turf-combine/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ module.exports = function (fc) {
.filter(function (key) {
return groups[key].coordinates.length;
})
.sort()
.map(function (key) {
return {
type: 'Feature',
Expand Down
71 changes: 61 additions & 10 deletions packages/turf-combine/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test('combine -- points', function(t) {
var multiPt = combine(featurecollection([pt1, pt2]))

t.ok(multiPt, 'should combine two Points into a MultiPoint')
t.deepEqual(multiPt.geometry.coordinates, [[50, 51], [100, 101]])
t.deepEqual(multiPt.features[0].geometry.coordinates, [[50, 51], [100, 101]])
t.end();
});

Expand All @@ -29,7 +29,7 @@ test('combine -- mixed multipoint & point', function(t) {
var multiPt = combine(featurecollection([pt1, pt2]))

t.ok(multiPt, 'should combine Points + MultiPoint into a MultiPoint')
t.deepEqual(multiPt.geometry.coordinates, [[50, 51], [100, 101], [101, 102]])
t.deepEqual(multiPt.features[0].geometry.coordinates, [[50, 51], [100, 101], [101, 102]])
t.end();
});

Expand All @@ -49,8 +49,8 @@ test('combine -- linestrings', function(t) {
var multiLine = combine(featurecollection([l1, l2]))

t.ok(multiLine, 'should combine two LineStrings into a MultiLineString')
t.equal(multiLine.geometry.type, 'MultiLineString')
t.deepEqual(multiLine.geometry.coordinates, [[[102, -10], [130, 4]], [[40, -20], [150, 18]]])
t.equal(multiLine.features[0].geometry.type, 'MultiLineString')
t.deepEqual(multiLine.features[0].geometry.coordinates, [[[102, -10], [130, 4]], [[40, -20], [150, 18]]])
t.end();
});

Expand All @@ -74,8 +74,8 @@ test('combine -- mixed multilinestring & linestring', function(t) {
var multiLine = combine(featurecollection([l1, l2]))

t.ok(multiLine, 'should combine LineString + MultiLineString into a MultiLineString')
t.equal(multiLine.geometry.type, 'MultiLineString')
t.deepEqual(multiLine.geometry.coordinates, [[[102, -10], [130, 4]], [[40, -20], [150, 18]], [[50, -10], [160, 28]]])
t.equal(multiLine.features[0].geometry.type, 'MultiLineString')
t.deepEqual(multiLine.features[0].geometry.coordinates, [[[102, -10], [130, 4]], [[40, -20], [150, 18]], [[50, -10], [160, 28]]])
t.end();
});

Expand All @@ -102,8 +102,8 @@ test('combine -- polygons', function(t) {
var multiPoly = combine(featurecollection([p1, p2]))

t.ok(multiPoly, 'should combine two Polygons into a MultiPolygon')
t.equal(multiPoly.geometry.type, 'MultiPolygon')
t.deepEqual(multiPoly.geometry.coordinates,
t.equal(multiPoly.features[0].geometry.type, 'MultiPolygon')
t.deepEqual(multiPoly.features[0].geometry.coordinates,
[[[[20,0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0],[20,0]]],
[[[30.0,0.0],[102.0,0.0],[103.0,1.0],[30.0,0.0]]]])

Expand Down Expand Up @@ -147,8 +147,59 @@ test('combine -- polygons', function(t) {
var multiPoly = combine(featurecollection([p1, p2]))

t.ok(multiPoly, 'should combine two Polygon + MultiPolygon into a MultiPolygon')
t.equal(multiPoly.geometry.type, 'MultiPolygon')
t.deepEqual(multiPoly.geometry.coordinates,
t.equal(multiPoly.features[0].geometry.type, 'MultiPolygon')
t.deepEqual(multiPoly.features[0].geometry.coordinates,
[[[[20,0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0],[20,0]]],
[[[30.0,0.0],[102.0,0.0],[103.0,1.0],[30.0,0.0]]],
[[[20.0,5.0],[92.0,5.0],[93.0,6.0],[20.0,5.0]],
[[25, 5],[30, 5],[30, 5.5],[25, 5]]]
])

t.end()
});

test('combine -- heterogenous', function(t) {
// MultiPolygon
var p1 = polygon( [
[
[20.0,0.0],
[101.0,0.0],
[101.0,1.0],
[100.0,1.0],
[100.0,0.0],
[20.0,0.0]
]
]);
var p2 = multipolygon([
[[
[30.0,0.0],
[102.0,0.0],
[103.0,1.0],
[30.0,0.0]
]],
[
[
[20.0,5.0],
[92.0,5.0],
[93.0,6.0],
[20.0,5.0]
],
[
[25, 5],
[30, 5],
[30, 5.5],
[25, 5]
]
]
]);
var pt1 = point([50, 51])
var multiPoly = combine(featurecollection([p1, p2, pt1]))

t.ok(multiPoly, 'should combine two Polygon + MultiPolygon into a MultiPolygon')
t.equal(multiPoly.features[0].geometry.type, 'MultiPoint')

t.equal(multiPoly.features[1].geometry.type, 'MultiPolygon')
t.deepEqual(multiPoly.features[1].geometry.coordinates,
[[[[20,0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0],[20,0]]],
[[[30.0,0.0],[102.0,0.0],[103.0,1.0],[30.0,0.0]]],
[[[20.0,5.0],[92.0,5.0],[93.0,6.0],[20.0,5.0]],
Expand Down
4 changes: 2 additions & 2 deletions packages/turf-meta/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"license": "ISC",
"devDependencies": {
"tape": "^3.4.0",
"turf-random": "^1.0.2"
"turf-random": "^3.0.0"
},
"repository": {
"type": "git",
"url": "[email protected]:Turfjs/turf-meta.git"
}
}
}

0 comments on commit a4813f3

Please sign in to comment.