Skip to content

Commit

Permalink
integrating weighted breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
dnomadb committed Jan 6, 2016
1 parent eee59e0 commit 9cd5eab
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/raster.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,11 @@ Raster.prototype.getZooms = function(callback) {
var pixelSize = utils.convertToMeters(this.details.pixelSize, utils.getUnitType(this.projection));

var spatialResolutions = utils.getSpatialResolutions();

// Threshold weight = the amount to shift the break;
// 0 = no shift (always upsamples), 1 = full shift (always downsamples)
var thresholdWeight = 0.25;
var _this = this;
var validSpatialResolutions = utils.getValidSpatialResolutions(spatialResolutions, _this.details.pixelSize[0]);
var validSpatialResolutions = utils.getValidSpatialResolutions(spatialResolutions, _this.details.pixelSize[0], thresholdWeight);

this.details.pixelSize = pixelSize;
return callback(
Expand Down
7 changes: 4 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ module.exports.getSpatialResolutions = function() {
});
};

module.exports.getValidSpatialResolutions = function(spatialResolutions, pixelSize) {
return spatialResolutions.filter(function(res) {
return res > pixelSize;
module.exports.getValidSpatialResolutions = function(spatialResolutions, pixelSize, thresholdWeight) {
return spatialResolutions.filter(function(res, i) {
var zBreak = res - spatialResolutions[Math.min(i + 1, spatialResolutions.length - 1)] * thresholdWeight;
return zBreak > pixelSize;
});
};
14 changes: 13 additions & 1 deletion test/raster.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,21 @@ tape('[SPATIAL RESOLUTIONS] Get spatial resolutions / valid spatial resolutions'
var expectedResolutions = JSON.parse('[156542.96875,78271.484375,39135.7421875,19567.87109375,9783.935546875,4891.9677734375,2445.98388671875,1222.991943359375,611.4959716796875,305.74798583984375,152.87399291992188,76.43699645996094,38.21849822998047,19.109249114990234,9.554624557495117,4.777312278747559,2.3886561393737793,1.1943280696868896,0.5971640348434448,0.2985820174217224]');
assert.deepLooseEqual(spatialResolutions, expectedResolutions);

var validSpatialResolutions = utils.getValidSpatialResolutions(spatialResolutions, 30.20012);
var validSpatialResolutions = utils.getValidSpatialResolutions(spatialResolutions, 30.20012, 0);
var expectedValidResolutions = JSON.parse('[156542.96875,78271.484375,39135.7421875,19567.87109375,9783.935546875,4891.9677734375,2445.98388671875,1222.991943359375,611.4959716796875,305.74798583984375,152.87399291992188,76.43699645996094,38.21849822998047]');
assert.deepLooseEqual(validSpatialResolutions, expectedValidResolutions);

assert.end();
});

tape('[SPATIAL RESOLUTIONS] Get spatial resolutions / valid spatial resolutions with weight', function(assert) {
var spatialResolutions = utils.getSpatialResolutions();
var expectedResolutions = JSON.parse('[156542.96875,78271.484375,39135.7421875,19567.87109375,9783.935546875,4891.9677734375,2445.98388671875,1222.991943359375,611.4959716796875,305.74798583984375,152.87399291992188,76.43699645996094,38.21849822998047,19.109249114990234,9.554624557495117,4.777312278747559,2.3886561393737793,1.1943280696868896,0.5971640348434448,0.2985820174217224]');
assert.deepLooseEqual(spatialResolutions, expectedResolutions);

var validSpatialResolutions = utils.getValidSpatialResolutions(spatialResolutions, 40.20012, 0.25);
var expectedValidResolutions = JSON.parse('[156542.96875,78271.484375,39135.7421875,19567.87109375,9783.935546875,4891.9677734375,2445.98388671875,1222.991943359375,611.4959716796875,305.74798583984375,152.87399291992188,76.43699645996094]');
assert.deepLooseEqual(validSpatialResolutions, expectedValidResolutions);

assert.end();
});

0 comments on commit 9cd5eab

Please sign in to comment.