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

turf-combine

Package Overview
Dependencies
Maintainers
9
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turf-combine - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

26

index.js

@@ -6,4 +6,4 @@ /**

* @category misc
* @param {FeatureCollection} fc a FeatureCollection of any type
* @return {FeatureCollection} a FeatureCollection of corresponding type to input
* @param {FeatureCollection<(Point|LineString|Polygon)>} fc a FeatureCollection of any type
* @return {FeatureCollection<(MultiPoint|MultiLineString|MultiPolygon)>} a FeatureCollection of corresponding type to input
* @example

@@ -39,3 +39,6 @@ * var fc = {

var geometries = fc.features.map(function(f) {
return f.geometry;
if (f.geometry.type === 'Point' ||
f.geometry.type === 'LineString' ||
f.geometry.type === 'Polygon') return [f.geometry.coordinates];
return f.geometry.coordinates;
});

@@ -45,2 +48,3 @@

case 'Point':
case 'MultiPoint':
return {

@@ -51,6 +55,7 @@ type: 'Feature',

type: 'MultiPoint',
coordinates: pluckCoods(geometries)
coordinates: pluckCoords(geometries)
}
};
case 'LineString':
case 'MultiLineString':
return {

@@ -61,6 +66,7 @@ type: 'Feature',

type: 'MultiLineString',
coordinates: pluckCoods(geometries)
coordinates: pluckCoords(geometries)
}
};
case 'Polygon':
case 'MultiPolygon':
return {

@@ -71,3 +77,3 @@ type: 'Feature',

type: 'MultiPolygon',
coordinates: pluckCoods(geometries)
coordinates: pluckCoords(geometries)
}

@@ -80,6 +86,6 @@ };

function pluckCoods(multi){
return multi.map(function(geom){
return geom.coordinates;
});
function pluckCoords(multi) {
return multi.reduce(function(memo, coords) {
return memo.concat(coords);
}, []);
}
{
"name": "turf-combine",
"version": "1.0.2",
"version": "1.1.0",
"description": "turf combine module",

@@ -29,10 +29,13 @@ "main": "index.js",

"benchmark": "^1.0.0",
"dox": "^0.6.1",
"doxme": "^1.4.3",
"tape": "^3.5.0",
"turf-featurecollection": "^1.0.0",
"turf-linestring": "^1.0.1",
"turf-multilinestring": "^1.0.2",
"turf-multipoint": "^1.0.0",
"turf-multipolygon": "^1.0.1",
"turf-point": "^2.0.0",
"turf-polygon": "^1.0.2",
"dox": "^0.6.1",
"doxme": "^1.4.3"
"turf-polygon": "^1.0.2"
}
}

@@ -15,5 +15,5 @@ # turf-combine

| parameter | type | description |
| --------- | ----------------- | ------------------------------- |
| `fc` | FeatureCollection | a FeatureCollection of any type |
| parameter | type | description |
| --------- | ----------------------------------------------- | ------------------------------- |
| `fc` | FeatureCollection\.\<Point|LineString|Polygon\> | a FeatureCollection of any type |

@@ -24,6 +24,22 @@

```js
var fc = turf.featurecollection([
turf.point([19.026432, 47.49134]),
turf.point([19.074497, 47.509548])
]);
var fc = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [19.026432, 47.49134]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [19.074497, 47.509548]
}
}
]
};

@@ -35,2 +51,5 @@ var combined = turf.combine(fc);

**Returns** `FeatureCollection.<MultiPoint|MultiLineString|MultiPolygon>`, a FeatureCollection of corresponding type to input
## Installation

@@ -50,1 +69,2 @@

@@ -1,9 +0,13 @@

var test = require('tape')
var point = require('turf-point')
var linestring = require('turf-linestring')
var polygon = require('turf-polygon')
var featurecollection = require('turf-featurecollection')
var test = require('tape'),
point = require('turf-point'),
multipoint = require('turf-multipoint'),
linestring = require('turf-linestring'),
multilinestring = require('turf-multilinestring'),
polygon = require('turf-polygon'),
multipolygon = require('turf-multipolygon'),
featurecollection = require('turf-featurecollection');
var combine = require('./')
test('combine', function(t){
test('combine -- points', function(t) {
// MultiPoint

@@ -15,5 +19,20 @@ var pt1 = point([50, 51])

t.ok(multiPt, 'should should combine two points into a MultiPoint')
t.ok(multiPt, 'should combine two Points into a MultiPoint')
t.deepEqual(multiPt.geometry.coordinates, [[50, 51], [100, 101]])
t.end();
});
test('combine -- mixed multipoint & point', function(t) {
// MultiPoint
var pt1 = point([50, 51])
var pt2 = multipoint([[100, 101], [101, 102]])
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.end();
});
test('combine -- linestrings', function(t) {
// MultiLineString

@@ -33,7 +52,34 @@ var l1 = linestring([

t.ok(multiLine, 'should should combine two LineStrings into a MultiLineString')
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.end();
});
test('combine -- mixed multilinestring & linestring', function(t) {
// MultiLineString
var l1 = linestring([
[102.0, -10.0],
[130.0, 4.0]
]);
var l2 = multilinestring([
[
[40.0, -20.0],
[150.0, 18.0]
],
[
[50, -10],
[160, 28]
]
]);
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.end();
});
test('combine -- polygons', function(t) {
// MultiPolygon

@@ -60,10 +106,57 @@ var p1 = polygon( [

t.ok(multiPoly, 'should should combine two Polygons into a MultiPolygon')
t.ok(multiPoly, 'should combine two Polygons into a MultiPolygon')
t.equal(multiPoly.geometry.type, 'MultiPolygon')
t.deepEqual(multiPoly.geometry.coordinates,
[[[[20,0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0],[20,0]]],
t.deepEqual(multiPoly.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]]]])
t.end()
});
test('combine -- polygons', 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 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,
[[[[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()
})
});
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