turf-isobands
Advanced tools
Comparing version 0.1.1 to 1.0.0
99
index.js
//https://github.com/jasondavies/conrec.js | ||
//http://stackoverflow.com/questions/263305/drawing-a-topographical-map | ||
var tin = require('turf-tin') | ||
var inside = require('turf-inside') | ||
var grid = require('turf-grid') | ||
var extent = require('turf-extent') | ||
var planepoint = require('turf-planepoint') | ||
var featurecollection = require('turf-featurecollection') | ||
var linestring = require('turf-linestring') | ||
var polygon = require('turf-polygon') | ||
var point = require('turf-point') | ||
var square = require('turf-square') | ||
var size = require('turf-size') | ||
var tin = require('turf-tin'); | ||
var inside = require('turf-inside'); | ||
var grid = require('turf-grid'); | ||
var extent = require('turf-extent'); | ||
var planepoint = require('turf-planepoint'); | ||
var featurecollection = require('turf-featurecollection'); | ||
var linestring = require('turf-linestring'); | ||
var polygon = require('turf-polygon'); | ||
var point = require('turf-point'); | ||
var square = require('turf-square'); | ||
var size = require('turf-size'); | ||
@@ -18,45 +18,40 @@ module.exports = function(points, z, resolution, breaks){ | ||
if (typeof addEdgesResult === 'Error') { | ||
done(addEdgesResult); | ||
return addEdgesResult; | ||
} | ||
var tinResult = tin(points, z); | ||
var extentBBox = extent(points); | ||
var squareBBox = square(extentBBox); | ||
var gridResult = grid(squareBBox, resolution); | ||
var data = []; | ||
var tinResult = tin(points, z) | ||
var extentBBox = extent(points) | ||
var squareBBox = square(extentBBox) | ||
var gridResult = grid(squareBBox, resolution) | ||
var data = [] | ||
gridResult.features.forEach(function(pt){ | ||
tinResult.features.forEach(function(triangle){ | ||
if (inside(pt, triangle)) { | ||
pt.properties = {} | ||
pt.properties = {}; | ||
pt.properties[z] = planepoint(pt, triangle); | ||
} | ||
}) | ||
}); | ||
if(!pt.properties){ | ||
pt.properties = {} | ||
pt.properties[z] = -100 | ||
pt.properties = {}; | ||
pt.properties[z] = -100; | ||
} | ||
}) | ||
}); | ||
var depth = Math.sqrt(gridResult.features.length) | ||
var depth = Math.sqrt(gridResult.features.length); | ||
for (var x=0; x<depth; x++){ | ||
var xGroup = gridResult.features.slice(x * depth, (x + 1) * depth) | ||
var xFlat = [] | ||
var xGroup = gridResult.features.slice(x * depth, (x + 1) * depth); | ||
var xFlat = []; | ||
xGroup.forEach(function(verticalPoint){ | ||
if(verticalPoint.properties){ | ||
xFlat.push(verticalPoint.properties[z]) | ||
xFlat.push(verticalPoint.properties[z]); | ||
} else{ | ||
xFlat.push(0) | ||
xFlat.push(0); | ||
} | ||
}) | ||
data.push(xFlat) | ||
data.push(xFlat); | ||
} | ||
var interval = (squareBBox[2] - squareBBox[0]) / depth | ||
var xCoordinates = [] | ||
var yCoordinates = [] | ||
var interval = (squareBBox[2] - squareBBox[0]) / depth; | ||
var xCoordinates = []; | ||
var yCoordinates = []; | ||
for (var x=0; x<depth; x++){ | ||
xCoordinates.push(x * interval + squareBBox[0]) | ||
yCoordinates.push(x * interval + squareBBox[1]) | ||
xCoordinates.push(x * interval + squareBBox[0]); | ||
yCoordinates.push(x * interval + squareBBox[1]); | ||
} | ||
@@ -67,29 +62,29 @@ | ||
if(num === 0){ | ||
return .01 | ||
return .01; | ||
} | ||
else{ | ||
return num | ||
return num; | ||
} | ||
}) | ||
//deduplicate breaks | ||
breaks = unique(breaks) | ||
breaks = unique(breaks); | ||
var c = new Conrec | ||
c.contour(data, 0, resolution, 0, resolution, xCoordinates, yCoordinates, breaks.length, breaks) | ||
var contourList = c.contourList() | ||
var c = new Conrec; | ||
c.contour(data, 0, resolution, 0, resolution, xCoordinates, yCoordinates, breaks.length, breaks); | ||
var contourList = c.contourList(); | ||
var fc = featurecollection([]) | ||
var fc = featurecollection([]); | ||
contourList.forEach(function(c){ | ||
if(c.length > 2){ | ||
var polyCoordinates = [] | ||
var polyCoordinates = []; | ||
c.forEach(function(coord){ | ||
polyCoordinates.push([coord.x, coord.y]) | ||
}) | ||
var poly = polygon([polyCoordinates]) | ||
poly.properties = {} | ||
poly.properties[z] = c.level | ||
polyCoordinates.push([coord.x, coord.y]); | ||
}); | ||
var poly = polygon([polyCoordinates]); | ||
poly.properties = {}; | ||
poly.properties[z] = c.level; | ||
fc.features.push(poly) | ||
fc.features.push(poly); | ||
} | ||
}) | ||
}); | ||
@@ -96,0 +91,0 @@ return fc; |
{ | ||
"name": "turf-isobands", | ||
"version": "0.1.1", | ||
"version": "1.0.0", | ||
"description": "turf isobands module", | ||
@@ -29,17 +29,18 @@ "main": "index.js", | ||
"devDependencies": { | ||
"tape": "^2.13.4" | ||
"benchmark": "^1.0.0", | ||
"tape": "^3.0.3" | ||
}, | ||
"dependencies": { | ||
"turf-extent": "^0.1.4", | ||
"turf-featurecollection": "^0.1.0", | ||
"turf-extent": "^1.0.0", | ||
"turf-featurecollection": "^1.0.0", | ||
"turf-grid": "0.1.0", | ||
"turf-inside": "^0.1.4", | ||
"turf-linestring": "^0.1.1", | ||
"turf-inside": "^1.1.2", | ||
"turf-linestring": "^1.0.0", | ||
"turf-planepoint": "0.1.0", | ||
"turf-point": "^0.1.1", | ||
"turf-polygon": "^0.1.1", | ||
"turf-size": "^0.1.3", | ||
"turf-square": "^0.1.3", | ||
"turf-point": "^1.2.0", | ||
"turf-polygon": "^1.0.0", | ||
"turf-size": "^1.1.0", | ||
"turf-square": "^1.0.0", | ||
"turf-tin": "0.1.0" | ||
} | ||
} |
18
test.js
@@ -1,15 +0,15 @@ | ||
var test = require('tape') | ||
var fs = require('fs') | ||
var isobands = require('./') | ||
var test = require('tape'); | ||
var fs = require('fs'); | ||
var isobands = require('./'); | ||
test('isobands', function(t){ | ||
var points = JSON.parse(fs.readFileSync(__dirname+'/geojson/Points.geojson')) | ||
var points = JSON.parse(fs.readFileSync(__dirname+'/geojson/Points.geojson')); | ||
var isobanded = isobands(points, 'elevation', 15, [5, 45, 55, 65, 85, 95, 105, 120, 180], false) | ||
var isobanded = isobands(points, 'elevation', 15, [5, 45, 55, 65, 85, 95, 105, 120, 180], false); | ||
t.ok(isobanded.features, 'should take a set of points with z values and output a set of filled contour polygons') | ||
t.equal(isobanded.features[0].geometry.type, 'Polygon') | ||
t.ok(isobanded.features, 'should take a set of points with z values and output a set of filled contour polygons'); | ||
t.equal(isobanded.features[0].geometry.type, 'Polygon'); | ||
fs.writeFileSync(__dirname+'/geojson/isobands.geojson', JSON.stringify(isobanded)) | ||
t.end() | ||
fs.writeFileSync(__dirname+'/geojson/isobands.geojson', JSON.stringify(isobanded)); | ||
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
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
47361
10
646
0
2
2
+ Addedminimist@1.2.8(transitive)
+ Addedturf-distance@1.1.0(transitive)
+ Addedturf-extent@1.0.4(transitive)
+ Addedturf-featurecollection@1.0.1(transitive)
+ Addedturf-inside@1.1.4(transitive)
+ Addedturf-invariant@1.0.3(transitive)
+ Addedturf-linestring@1.0.2(transitive)
+ Addedturf-meta@1.0.2(transitive)
+ Addedturf-midpoint@1.0.1(transitive)
+ Addedturf-point@1.2.12.0.1(transitive)
+ Addedturf-polygon@1.0.3(transitive)
+ Addedturf-size@1.1.1(transitive)
+ Addedturf-square@1.0.1(transitive)
- Removedflatten@0.0.1(transitive)
- Removedturf-extent@0.1.4(transitive)
- Removedturf-featurecollection@0.1.0(transitive)
- Removedturf-inside@0.1.4(transitive)
- Removedturf-linestring@0.1.1(transitive)
- Removedturf-midpoint@0.1.3(transitive)
- Removedturf-size@0.1.3(transitive)
- Removedturf-square@0.1.3(transitive)
Updatedturf-extent@^1.0.0
Updatedturf-inside@^1.1.2
Updatedturf-linestring@^1.0.0
Updatedturf-point@^1.2.0
Updatedturf-polygon@^1.0.0
Updatedturf-size@^1.1.0
Updatedturf-square@^1.0.0