Comparing version 0.0.126 to 0.0.128
@@ -16,108 +16,109 @@ //https://github.com/jasondavies/conrec.js | ||
t.merge = require('./merge') | ||
t.size = require('./size') | ||
t.point = require('./point') | ||
module.exports = function(points, z, resolution, breaks, done){ | ||
t.tin(points, z, function(err, tinResult){ | ||
require('fs').writeFileSync(__dirname+'/../test/testOut/tinContour.geojson', JSON.stringify(tinResult)) | ||
t.extent(points, function(err, bbox){ | ||
t.square(bbox, function(err, bbox){ | ||
t.grid(bbox, resolution, function(err, gridResult){ | ||
var data = [] | ||
_(gridResult.features).each(function(pt){ | ||
_(tinResult.features).each(function(triangle){ | ||
t.inside(pt, triangle, function(err, isInside){ | ||
if(isInside){ | ||
t.planepoint(pt, triangle, function(err, zValue){ | ||
pt.properties = {} | ||
pt.properties[z] = zValue | ||
}) | ||
addEdges(points, z, resolution, function(){ | ||
t.tin(points, z, function(err, tinResult){ | ||
t.extent(points, function(err, bbox){ | ||
t.square(bbox, function(err, bbox){ | ||
t.grid(bbox, resolution, function(err, gridResult){ | ||
var data = [] | ||
_(gridResult.features).each(function(pt){ | ||
_(tinResult.features).each(function(triangle){ | ||
t.inside(pt, triangle, function(err, isInside){ | ||
if(isInside){ | ||
t.planepoint(pt, triangle, function(err, zValue){ | ||
pt.properties = {} | ||
pt.properties[z] = zValue | ||
}) | ||
} | ||
}) | ||
}) | ||
if(!pt.properties){ | ||
pt.properties = {} | ||
pt.properties[z] = -100 | ||
} | ||
}) | ||
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 = [] | ||
_.each(xGroup, function(verticalPoint){ | ||
if(verticalPoint.properties){ | ||
xFlat.push(verticalPoint.properties[z]) | ||
} else{ | ||
xFlat.push(0) | ||
} | ||
}) | ||
}) | ||
if(!pt.properties){ | ||
//console.log(pt) | ||
pt.properties = {} | ||
pt.properties[z] = -100 | ||
data.push(xFlat) | ||
} | ||
}) | ||
require('fs').writeFileSync(__dirname+'/../test/testOut/contourGrid.geojson', JSON.stringify(gridResult)) | ||
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 = [] | ||
_.each(xGroup, function(verticalPoint){ | ||
if(verticalPoint.properties){ | ||
xFlat.push(verticalPoint.properties[z]) | ||
} else{ | ||
xFlat.push(0) | ||
var interval = (bbox[2] - bbox[0]) / depth | ||
var xCoordinates = [] | ||
var yCoordinates = [] | ||
for (var x=0; x<depth; x++){ | ||
xCoordinates.push(x * interval + bbox[0]) | ||
yCoordinates.push(x * interval + bbox[1]) | ||
} | ||
//change zero breaks to .01 to deal with bug in conrec algorithm | ||
breaks = _.map(breaks, function(num){ | ||
if(num === 0){ | ||
return .01 | ||
} | ||
else{ | ||
return num | ||
} | ||
}) | ||
data.push(xFlat) | ||
} | ||
var interval = (bbox[2] - bbox[0]) / depth | ||
var xCoordinates = [] | ||
var yCoordinates = [] | ||
for (var x=0; x<depth; x++){ | ||
xCoordinates.push(x * interval + bbox[0]) | ||
yCoordinates.push(x * interval + bbox[1]) | ||
} | ||
//change zero breaks to .01 to deal with bug in conrec algorithm | ||
breaks = _.map(breaks, function(num){ | ||
if(num === 0){ | ||
return .01 | ||
} | ||
else{ | ||
return num | ||
} | ||
}) | ||
//deduplicate breaks | ||
breaks = _.uniq(breaks) | ||
//deduplicate breaks | ||
breaks = _.uniq(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 = t.featurecollection([]) | ||
_.each(contourList, function(c){ | ||
if(c.length > 2){ | ||
var polyCoordinates = [] | ||
_.each(c, function(coord){ | ||
polyCoordinates.push([coord.x, coord.y]) | ||
}) | ||
var poly = t.polygon([polyCoordinates]) | ||
poly.properties = {} | ||
poly.properties[z] = c.level | ||
var fc = t.featurecollection([]) | ||
_.each(contourList, function(c){ | ||
if(c.length > 2){ | ||
var polyCoordinates = [] | ||
_.each(c, function(coord){ | ||
polyCoordinates.push([coord.x, coord.y]) | ||
}) | ||
var poly = t.polygon([polyCoordinates]) | ||
poly.properties = {} | ||
poly.properties[z] = c.level | ||
fc.features.push(poly) | ||
} | ||
}) | ||
fc.features.push(poly) | ||
} | ||
}) | ||
// perform donuts function and dissolves rings before returning if donuts option is true | ||
t.donuts(fc, function(err, donutPolys){ | ||
var zGroups = [] | ||
_.each(donutPolys.features, function(ring){ | ||
var found = false | ||
_.each(zGroups, function(group){ | ||
if(group.z === ring.properties[z]){ | ||
found = true | ||
group.rings.push(ring) | ||
// perform donuts function and dissolves rings before returning if donuts option is true | ||
t.donuts(fc, function(err, donutPolys){ | ||
var zGroups = [] | ||
_.each(donutPolys.features, function(ring){ | ||
var found = false | ||
_.each(zGroups, function(group){ | ||
if(group.z === ring.properties[z]){ | ||
found = true | ||
group.rings.push(ring) | ||
} | ||
}) | ||
if(!found){ | ||
zGroups.push({z: ring.properties[z], rings: [ring]}) | ||
} | ||
}) | ||
if(!found){ | ||
zGroups.push({z: ring.properties[z], rings: [ring]}) | ||
} | ||
}) | ||
donutPolys.features = [] | ||
_.each(zGroups, function(group){ | ||
//console.log('===================================') | ||
_.each(group.rings, function(ring){ | ||
//console.log(ring.geometry.coordinates) | ||
donutPolys.features = [] | ||
_.each(zGroups, function(group){ | ||
//console.log('===================================') | ||
_.each(group.rings, function(ring){ | ||
//console.log(ring.geometry.coordinates) | ||
}) | ||
t.merge(t.featurecollection(group.rings), function(err, multiRing){ | ||
donutPolys.features.push(multiRing) | ||
}) | ||
}) | ||
t.merge(t.featurecollection(group.rings), function(err, multiRing){ | ||
donutPolys.features.push(multiRing) | ||
}) | ||
}) | ||
done(null, donutPolys) | ||
}) | ||
done(null, donutPolys) | ||
}) | ||
}) | ||
}) | ||
@@ -129,3 +130,57 @@ }) | ||
function addEdges(points, z, resolution, cb){ | ||
t.extent(points, function(err, bbox){ | ||
t.square(bbox, function(err, bbox){ | ||
t.size(bbox, 1.1, function(err, bbox){ | ||
var edgeDistance = bbox[2] - bbox[0] | ||
var extendDistance = edgeDistance / resolution | ||
var xmin = bbox[0] | ||
var ymin = bbox[1] | ||
var xmax = bbox[2] | ||
var ymax = bbox[3] | ||
//left | ||
var left = [[xmin, ymin],[xmin, ymax]] | ||
for(var i = 0; i<=resolution; i++){ | ||
var pt = t.point(xmin, ymin + (extendDistance * i)) | ||
pt.properties = {} | ||
pt.properties[z] = -100 | ||
points.features.push(pt) | ||
} | ||
//bottom | ||
var bottom = [[xmin, ymin],[xmax, ymin]] | ||
for(var i = 0; i<=resolution; i++){ | ||
var pt = t.point(xmin + (extendDistance * i), ymin) | ||
pt.properties = {} | ||
pt.properties[z] = -100 | ||
points.features.push(pt) | ||
} | ||
//right | ||
var right = [[xmax, ymin],[xmax, ymax]] | ||
for(var i = 0; i<=resolution; i++){ | ||
var pt = t.point(xmax, ymin + (extendDistance * i)) | ||
pt.properties = {} | ||
pt.properties[z] = -100 | ||
points.features.push(pt) | ||
} | ||
//top | ||
var top = [[xmin, ymax],[xmax, ymax]] | ||
for(var i = 0; i<=resolution; i++){ | ||
var pt = t.point(xmax + (extendDistance * i), ymax) | ||
pt.properties = {} | ||
pt.properties[z] = -100 | ||
points.features.push(pt) | ||
} | ||
cb(points) | ||
}) | ||
}) | ||
}) | ||
} | ||
/** | ||
@@ -132,0 +187,0 @@ * Copyright (c) 2010, Jason Davies. |
{ | ||
"name": "turf", | ||
"version": "0.0.126", | ||
"version": "0.0.128", | ||
"description": "a node.js library for performing geospatial operations with geojson", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,3 +6,3 @@ var t = require('../index'), | ||
describe('isobands', function(){ | ||
xit('should take a set of points with z values and output a set of contour polygons', function(done){ | ||
it('should take a set of points with z values and output a set of contour polygons', function(done){ | ||
t.load(__dirname+'/testIn/elevation1.geojson', function(err, points){ | ||
@@ -18,3 +18,3 @@ t.isobands(points, 'elevation', 15, [25, 45, 55, 65, 85, 95, 105, 120, 180], function(err, contours){ | ||
}) | ||
xit('should take a set of points with z values and output a set of contour polygons with jenks breaks', function(done){ | ||
it('should take a set of points with z values and output a set of contour polygons with jenks breaks', function(done){ | ||
t.load(__dirname+'/testIn/elevation1.geojson', function(err, points){ | ||
@@ -33,3 +33,3 @@ t.jenks(points, 'elevation', 5, function(err, breaks){ | ||
}) | ||
xit('should take a set of points with decimal z values and output a set of contour polygons', function(done){ | ||
it('should take a set of points with decimal z values and output a set of contour polygons', function(done){ | ||
t.load(__dirname+'/testIn/elevation2.geojson', function(err, points){ | ||
@@ -45,3 +45,3 @@ t.isobands(points, 'elevation', 15, [-1, 25, 45, 55, 65, 85, 95, 105, 120, 180], function(err, contours){ | ||
}) | ||
xit('should take a set of points with negative z values and output a set of contour polygons', function(done){ | ||
it('should take a set of points with negative z values and output a set of contour polygons', function(done){ | ||
t.load(__dirname+'/testIn/elevation3.geojson', function(err, points){ | ||
@@ -57,3 +57,3 @@ t.isobands(points, 'elevation', 15, [25, 45, 55, 65, 85, 95, 105, 120, 180], function(err, contours){ | ||
}) | ||
xit('should take a set of points lopsided edges and output a set of contour polygons', function(done){ | ||
it('should take a set of points lopsided edges and output a set of contour polygons', function(done){ | ||
t.load(__dirname+'/testIn/openContourPoints.geojson', function(err, points){ | ||
@@ -80,2 +80,15 @@ t.isobands(points, 'elevation', 15, [85, 95, 105, 120], function(err, contours){ | ||
}) | ||
it('should take a set of points with internal valleys and output a set of contour polygons', function(done){ | ||
t.load(__dirname+'/testIn/openIsoIn.geojson', function(err, points){ | ||
t.quantile(points, 'elevation', [5,20, 60, 80, 95], function(err, breaks){ | ||
t.isobands(points, 'elevation', 10, breaks, function(err, contours){ | ||
if(err) throw err | ||
fs.writeFileSync(__dirname+'/testOut/openIsoOut.geojson', JSON.stringify(contours)) | ||
contours.should.be.ok | ||
contours.features.should.be.ok | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
4414179
248
25101
28