From c07b3de43db06315c3e4ae0e5e7758afacf6eb5a Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Wed, 11 Jul 2018 10:33:58 +0200 Subject: [PATCH] Adapt tests for more accurate PROJ Fixes #994 With exact point 0,0 transformations, the point is between tiles and can appear in several --- test/acceptance/aggregation.js | 166 +++++++++++++++++++++++++-------- 1 file changed, 126 insertions(+), 40 deletions(-) diff --git a/test/acceptance/aggregation.js b/test/acceptance/aggregation.js index b674bb2d..56d3e7ca 100644 --- a/test/acceptance/aggregation.js +++ b/test/acceptance/aggregation.js @@ -27,6 +27,15 @@ describe('aggregation', function () { from generate_series(-3, 3) x `; + const POINTS_SQL_0 = ` + select + x + 4 as cartodb_id, + st_setsrid(st_makepoint(x*10+1, x*10+1), 4326) as the_geom, + st_transform(st_setsrid(st_makepoint(x*10+1, x*10+1), 4326), 3857) as the_geom_webmercator, + x as value + from generate_series(-3, 3) x + `; + const POINTS_SQL_TIMESTAMP_1 = ` select row_number() over() AS cartodb_id, @@ -2129,62 +2138,139 @@ describe('aggregation', function () { }); }); - ['default', 'centroid', 'point-sample', 'point-grid'].forEach(placement => { - it(`aggregated ids are unique for ${placement} aggregation`, function (done) { - this.mapConfig = { - version: '1.6.0', - buffersize: { 'mvt': 0 }, - layers: [ - { - type: 'cartodb', + // describe('without points between tiles', function () { + it(`aggregated ids are unique for ${placement} aggregation`, function (done) { + this.mapConfig = { + version: '1.6.0', + buffersize: { 'mvt': 0 }, + layers: [ + { + type: 'cartodb', - options: { - sql: POINTS_SQL_1, - resolution: 1, - aggregation: { - threshold: 1 + options: { + sql: POINTS_SQL_0, + resolution: 1, + aggregation: { + threshold: 1 + } } } - } - ] - }; - if (placement !== 'default') { - this.mapConfig.layers[0].options.aggregation.placement = placement; - } - - this.testClient = new TestClient(this.mapConfig); - - this.testClient.getTile(1, 0, 1, { format: 'mvt' }, (err, res, mvt) => { - if (err) { - return done(err); + ] + }; + if (placement !== 'default') { + this.mapConfig.layers[0].options.aggregation.placement = placement; } - const tile1 = JSON.parse(mvt.toGeoJSONSync(0)); + this.testClient = new TestClient(this.mapConfig); - assert.ok(Array.isArray(tile1.features)); - assert.ok(tile1.features.length > 0); - - this.testClient.getTile(1, 1, 0, { format: 'mvt' }, (err, res, mvt) => { + this.testClient.getTile(1, 0, 1, { format: 'mvt' }, (err, res, mvt) => { if (err) { return done(err); } - const tile2 = JSON.parse(mvt.toGeoJSONSync(0)); + const tile1 = JSON.parse(mvt.toGeoJSONSync(0)); - assert.ok(Array.isArray(tile2.features)); - assert.ok(tile2.features.length > 0); + assert.ok(Array.isArray(tile1.features)); + assert.ok(tile1.features.length > 0); - const tile1Ids = tile1.features.map(f => f.properties.cartodb_id); - const tile2Ids = tile2.features.map(f => f.properties.cartodb_id); - const repeatedIds = tile1Ids.filter(id => tile2Ids.includes(id)); - assert.equal(repeatedIds.length, 0); + this.testClient.getTile(1, 1, 0, { format: 'mvt' }, (err, res, mvt) => { + if (err) { + return done(err); + } + + const tile2 = JSON.parse(mvt.toGeoJSONSync(0)); + + assert.ok(Array.isArray(tile2.features)); + assert.ok(tile2.features.length > 0); + + const tile1Ids = tile1.features.map(f => f.properties.cartodb_id); + const tile2Ids = tile2.features.map(f => f.properties.cartodb_id); + const repeatedIds = tile1Ids.filter(id => tile2Ids.includes(id)); + + assert.equal(repeatedIds.length, 0); + + done(); + }); - done(); }); - }); - }); + // }); + // describe('with points between tiles', function () { + it(`aggregated ids are unique for ${placement} aggregation save for points between tiles`, function (done) { + this.mapConfig = { + version: '1.6.0', + buffersize: { 'mvt': 0 }, + layers: [ + { + type: 'cartodb', + + options: { + sql: POINTS_SQL_1, + resolution: 1, + aggregation: { + threshold: 1 + } + } + } + ] + }; + if (placement !== 'default') { + this.mapConfig.layers[0].options.aggregation.placement = placement; + } + + this.testClient = new TestClient(this.mapConfig); + + this.testClient.getTile(1, 0, 1, { format: 'mvt' }, (err, res, mvt) => { + if (err) { + return done(err); + } + + const tile1 = JSON.parse(mvt.toGeoJSONSync(0)); + + assert.ok(Array.isArray(tile1.features)); + assert.ok(tile1.features.length > 0); + + this.testClient.getTile(1, 1, 0, { format: 'mvt' }, (err, res, mvt) => { + if (err) { + return done(err); + } + + const tile2 = JSON.parse(mvt.toGeoJSONSync(0)); + + assert.ok(Array.isArray(tile2.features)); + assert.ok(tile2.features.length > 0); + + const tile1Ids = tile1.features.map(f => f.properties.cartodb_id); + const tile2Ids = tile2.features.map(f => f.properties.cartodb_id); + const repeatedIds = tile1Ids.filter(id => tile2Ids.includes(id)); + + // It is not guaranteed that features appear in a single tile: + // features on the border of tiles can appear in multiple tiles + if (repeatedIds.length > 0) { + repeatedIds.forEach(id => { + const tile1Features = tile1.features.filter(f => f.properties.cartodb_id === id); + const tile2Features = tile2.features.filter(f => f.properties.cartodb_id === id); + // repetitions cannot occur inside a tile + assert.equal(tile1Features.length, 1); + assert.equal(tile2Features.length, 1); + const feature1 = tile1Features[0]; + const feature2 = tile2Features[0]; + // features should be identical (geometry and properties) + assert.deepEqual(feature1.properties, feature2.properties); + assert.deepEqual(feature1.geometry, feature2.geometry); + // and geometry should be on the border; + // for the dataset and zoom 1, only point with cartodb_id=4 (0,0) + assert.equal(feature1.properties.cartodb_id, 4); + assert.equal(feature2.properties.cartodb_id, 4); + }); + } + done(); + }); + + }); + }); + // }); }); ['default', 'centroid', 'point-sample', 'point-grid'].forEach(placement => {