turf-explode
Advanced tools
Comparing version 0.1.3 to 1.0.0
76
index.js
@@ -1,4 +0,4 @@ | ||
var flatten = require('flatten') | ||
var featureCollection = require('turf-featurecollection') | ||
var point = require('turf-point') | ||
var flatten = require('flatten'); | ||
var featureCollection = require('turf-featurecollection'); | ||
var point = require('turf-point'); | ||
@@ -8,82 +8,82 @@ module.exports = function(fc){ | ||
for(var i in fc.features){ | ||
var coordinates | ||
var coordinates ; | ||
switch(fc.features[i].geometry.type){ | ||
case 'Point': | ||
coordinates = [fc.features[i].geometry.coordinates] | ||
coordinates = [fc.features[i].geometry.coordinates]; | ||
break | ||
case 'LineString': | ||
coordinates = fc.features[i].geometry.coordinates | ||
coordinates = fc.features[i].geometry.coordinates; | ||
break | ||
case 'Polygon': | ||
coordinates = fc.features[i].geometry.coordinates | ||
coordinates = flatCoords(coordinates) | ||
coordinates = fc.features[i].geometry.coordinates; | ||
coordinates = flatCoords(coordinates); | ||
break | ||
case 'MultiPoint': | ||
coordinates = fc.features[i].geometry.coordinates | ||
coordinates = fc.features[i].geometry.coordinates; | ||
break | ||
case 'MultiLineString': | ||
coordinates = fc.features[i].geometry.coordinates | ||
coordinates = flatCoords(coordinates) | ||
coordinates = fc.features[i].geometry.coordinates; | ||
coordinates = flatCoords(coordinates); | ||
break | ||
case 'MultiPolygon': | ||
coordinates = fc.features[i].geometry.coordinates | ||
coordinates = flatCoords(coordinates) | ||
coordinates = fc.features[i].geometry.coordinates; | ||
coordinates = flatCoords(coordinates); | ||
break | ||
} | ||
if(!fc.features[i].geometry && fc.features[i].properties){ | ||
return new Error('Unknown Geometry Type') | ||
return new Error('Unknown Geometry Type'); | ||
} | ||
} | ||
var exploded = featureCollection([]) | ||
var exploded = featureCollection([]); | ||
coordinates.forEach(function(coords){ | ||
exploded.features.push(point(coords[0], coords[1])) | ||
exploded.features.push(point(coords[0], coords[1])); | ||
}) | ||
return exploded | ||
return exploded; | ||
} | ||
else{ | ||
var coordinates | ||
var geometry | ||
var coordinates ; | ||
var geometry; | ||
if(fc.type === 'Feature'){ | ||
geometry = fc.geometry | ||
geometry = fc.geometry; | ||
} | ||
else{ | ||
geometry = fc | ||
geometry = fc; | ||
} | ||
switch(geometry.type){ | ||
case 'Point': | ||
coordinates = [geometry.coordinates] | ||
coordinates = [geometry.coordinates]; | ||
break | ||
case 'LineString': | ||
coordinates = geometry.coordinates | ||
coordinates = geometry.coordinates; | ||
break | ||
case 'Polygon': | ||
coordinates = geometry.coordinates | ||
coordinates = flatCoords(coordinates) | ||
coordinates = geometry.coordinates; | ||
coordinates = flatCoords(coordinates); | ||
break | ||
case 'MultiPoint': | ||
coordinates = geometry.coordinates | ||
coordinates = geometry.coordinates; | ||
break | ||
case 'MultiLineString': | ||
coordinates = geometry.coordinates | ||
coordinates = flatCoords(coordinates) | ||
coordinates = geometry.coordinates; | ||
coordinates = flatCoords(coordinates); | ||
break | ||
case 'MultiPolygon': | ||
coordinates = geometry.coordinates | ||
coordinates = flatCoords(coordinates) | ||
coordinates = geometry.coordinates; | ||
coordinates = flatCoords(coordinates); | ||
break | ||
} | ||
if(!geometry){ | ||
return new Error('No Geometry Found') | ||
return new Error('No Geometry Found'); | ||
} | ||
var exploded = featureCollection([]) | ||
var exploded = featureCollection([]); | ||
coordinates.forEach(function(coords){ | ||
exploded.features.push(point(coords[0], coords[1])) | ||
exploded.features.push(point(coords[0], coords[1])); | ||
}) | ||
return exploded | ||
return exploded; | ||
} | ||
@@ -93,9 +93,9 @@ } | ||
function flatCoords(coords){ | ||
var newCoords = [] | ||
coords = flatten(coords) | ||
var newCoords = []; | ||
coords = flatten(coords); | ||
coords.forEach(function(c, i){ | ||
if(i % 2 == 0) // if is even | ||
newCoords.push([c, coords[i+1]]) | ||
newCoords.push([c, coords[i+1]]); | ||
}) | ||
return newCoords | ||
return newCoords; | ||
} |
{ | ||
"name": "turf-explode", | ||
"version": "0.1.3", | ||
"version": "1.0.0", | ||
"description": "turf explode module", | ||
@@ -26,2 +26,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"benchmark": "^1.0.0", | ||
"tape": "^2.13.4", | ||
@@ -28,0 +29,0 @@ "turf-featurecollection": "^0.1.0", |
24
test.js
@@ -1,21 +0,21 @@ | ||
var test = require('tape') | ||
var polygon = require('turf-polygon') | ||
var point = require('turf-point') | ||
var featurecollection = require('turf-featurecollection') | ||
var explode = require('./') | ||
var test = require('tape'); | ||
var polygon = require('turf-polygon'); | ||
var point = require('turf-point'); | ||
var featurecollection = require('turf-featurecollection'); | ||
var explode = require('./'); | ||
test('explode', function(t){ | ||
var poly = polygon([[[0,0], [0,10], [10,10] , [10,0]]]) | ||
var poly = polygon([[[0,0], [0,10], [10,10] , [10,0]]]); | ||
var p1 = point(0,0), | ||
p2 = point(0,10), | ||
p3 = point(10,10), | ||
p4 = point(10,0) | ||
var fc = featurecollection([p1,p2,p3,p4]) | ||
p4 = point(10,0); | ||
var fc = featurecollection([p1,p2,p3,p4]); | ||
var exploded = explode(poly) | ||
var exploded = explode(poly); | ||
t.ok(exploded.features, 'should take a feature or feature collection and return all vertices') | ||
t.deepEqual(exploded, fc) | ||
t.ok(exploded.features, 'should take a feature or feature collection and return all vertices'); | ||
t.deepEqual(exploded, fc); | ||
t.end() | ||
t.end(); | ||
}) |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
7046
8
128
0
5
1