From ff560ffde7079d4e39c7b96cb95a33ae623e391d Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 9 Aug 2017 18:49:59 +0200 Subject: [PATCH 1/7] add test boundingBox-polygon-counter --- test/acceptance/dataviews/polygonCount.js | 79 +++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 test/acceptance/dataviews/polygonCount.js diff --git a/test/acceptance/dataviews/polygonCount.js b/test/acceptance/dataviews/polygonCount.js new file mode 100644 index 00000000..02ff075e --- /dev/null +++ b/test/acceptance/dataviews/polygonCount.js @@ -0,0 +1,79 @@ +require('../../support/test_helper'); +var assert = require('../../support/assert'); +var TestClient = require('../../support/test-client'); + +function createMapConfig(layers, dataviews, analysis) { + return { + version: '1.5.0', + layers: layers, + dataviews: dataviews || {}, + analyses: analysis || [] + }; +} + +describe('boundingBox-polygon-counter', function() { + + afterEach(function(done) { + if (this.testClient) { + this.testClient.drain(done); + } else { + done(); + } + }); + + var mapConfig = createMapConfig( + [ + { + "type": "cartodb", + "options": { + "source": { + "id": "a0" + }, + "cartocss": "#points { marker-width: 10; marker-fill: red; }", + "cartocss_version": "2.3.0" + } + } + ], + { + val_formula: { + source: { + id: 'a0' + }, + type: 'formula', + options: { + column: "cartodb_id", + operation: "count", + } + } + }, + [ + { + "id": "a0", + "type": "source", + "params": { + "query": ` + SELECT + ST_TRANSFORM(ST_SETSRID(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[-161.015625,69.28725695167886],[-162.7734375,-7.710991655433217],[-40.78125,-8.059229627200192],[-161.015625,69.28725695167886]]]}'), 4326), 3857) AS the_geom_webmercator, 1 AS cartodb_id + UNION ALL + SELECT + ST_TRANSFORM(ST_SETSRID(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[-29.179687499999996,-7.01366792756663],[103.71093749999999,-6.664607562172573],[105.46875,69.16255790810501],[-29.179687499999996,-7.01366792756663]]]}'), 4326), 3857), 2 + UNION ALL + SELECT + ST_TRANSFORM(ST_SETSRID(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[-117.42187500000001,68.13885164925573],[-35.859375,20.96143961409684],[59.4140625,68.52823492039876],[-117.42187500000001,68.13885164925573]]]}'), 4326), 3857), 3 + ` + } + } + ] + ); + + it('should not count the polygons outside the bounding box', function(done) { + this.testClient = new TestClient(mapConfig, 1234); + params = { + bbox: '-77.34374999999999,45.82879925192134,17.578125,55.97379820507658' + } + this.testClient.getDataview('val_formula', params, function(err, dataview) { + assert.equal(dataview.result, 1); + done(); + }); + }); +}); \ No newline at end of file From 814b123b2bc594dd1aeddcaad1002af5aeeb1e8f Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 9 Aug 2017 18:55:14 +0200 Subject: [PATCH 2/7] fix 725 using the ST_Intersects function instead of && --- lib/cartodb/models/filter/bbox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cartodb/models/filter/bbox.js b/lib/cartodb/models/filter/bbox.js index dcf19e55..0f7072ae 100644 --- a/lib/cartodb/models/filter/bbox.js +++ b/lib/cartodb/models/filter/bbox.js @@ -8,7 +8,7 @@ var filterQueryTpl = dot.template([ ].join('\n')); var bboxFilterTpl = dot.template( - '{{=it._column}} && ST_Transform(ST_MakeEnvelope({{=it._bbox}}, 4326), {{=it._srid}})' + 'ST_Intersects({{=it._column}}, ST_Transform(ST_MakeEnvelope({{=it._bbox}}, 4326), {{=it._srid}}))' ); var LATITUDE_MAX_VALUE = 85.0511287798066; From 44c5eb051d692cd3c051d88812ccefa166a057a7 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 10 Aug 2017 11:05:36 +0200 Subject: [PATCH 3/7] formatting the query of polygon count test --- test/acceptance/dataviews/polygonCount.js | 46 ++++++++++++++++++++--- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/test/acceptance/dataviews/polygonCount.js b/test/acceptance/dataviews/polygonCount.js index 02ff075e..02ceef28 100644 --- a/test/acceptance/dataviews/polygonCount.js +++ b/test/acceptance/dataviews/polygonCount.js @@ -21,6 +21,36 @@ describe('boundingBox-polygon-counter', function() { } }); + var polygon1 = { + type: "Polygon", + coordinates:[[ + [-161.015625,69.28725695167886], + [-162.7734375,-7.710991655433217], + [-40.78125,-8.059229627200192], + [-161.015625,69.28725695167886] + ]] + }; + + var polygon2 = { + type: "Polygon", + coordinates: [[ + [-29.179687499999996,-7.01366792756663], + [103.71093749999999,-6.664607562172573], + [105.46875,69.16255790810501], + [-29.179687499999996,-7.01366792756663] + ]] + }; + + var polygon3 = { + type: "Polygon", + coordinates:[[ + [-117.42187500000001,68.13885164925573], + [-35.859375,20.96143961409684], + [59.4140625,68.52823492039876], + [-117.42187500000001,68.13885164925573] + ]] + }; + var mapConfig = createMapConfig( [ { @@ -53,13 +83,19 @@ describe('boundingBox-polygon-counter', function() { "params": { "query": ` SELECT - ST_TRANSFORM(ST_SETSRID(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[-161.015625,69.28725695167886],[-162.7734375,-7.710991655433217],[-40.78125,-8.059229627200192],[-161.015625,69.28725695167886]]]}'), 4326), 3857) AS the_geom_webmercator, 1 AS cartodb_id + ST_TRANSFORM(ST_SETSRID(ST_GeomFromGeoJSON( + '${JSON.stringify(polygon1)}' + ), 4326), 3857) AS the_geom_webmercator, 1 AS cartodb_id UNION ALL SELECT - ST_TRANSFORM(ST_SETSRID(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[-29.179687499999996,-7.01366792756663],[103.71093749999999,-6.664607562172573],[105.46875,69.16255790810501],[-29.179687499999996,-7.01366792756663]]]}'), 4326), 3857), 2 + ST_TRANSFORM(ST_SETSRID(ST_GeomFromGeoJSON( + '${JSON.stringify(polygon2)}' + ), 4326), 3857), 2 UNION ALL SELECT - ST_TRANSFORM(ST_SETSRID(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[-117.42187500000001,68.13885164925573],[-35.859375,20.96143961409684],[59.4140625,68.52823492039876],[-117.42187500000001,68.13885164925573]]]}'), 4326), 3857), 3 + ST_TRANSFORM(ST_SETSRID(ST_GeomFromGeoJSON( + '${JSON.stringify(polygon3)}' + ), 4326), 3857), 3 ` } } @@ -68,9 +104,9 @@ describe('boundingBox-polygon-counter', function() { it('should not count the polygons outside the bounding box', function(done) { this.testClient = new TestClient(mapConfig, 1234); - params = { + var params = { bbox: '-77.34374999999999,45.82879925192134,17.578125,55.97379820507658' - } + }; this.testClient.getDataview('val_formula', params, function(err, dataview) { assert.equal(dataview.result, 1); done(); From e678957a8f0536abb744a99c767182eb2510c152 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 10 Aug 2017 18:09:18 +0200 Subject: [PATCH 4/7] move polygon count test to widgets regression testfile, and check the only returned polygon is the expected one --- test/acceptance/dataviews/polygonCount.js | 115 ---------------------- test/acceptance/widgets/regressions.js | 97 ++++++++++++++++++ 2 files changed, 97 insertions(+), 115 deletions(-) delete mode 100644 test/acceptance/dataviews/polygonCount.js diff --git a/test/acceptance/dataviews/polygonCount.js b/test/acceptance/dataviews/polygonCount.js deleted file mode 100644 index 02ceef28..00000000 --- a/test/acceptance/dataviews/polygonCount.js +++ /dev/null @@ -1,115 +0,0 @@ -require('../../support/test_helper'); -var assert = require('../../support/assert'); -var TestClient = require('../../support/test-client'); - -function createMapConfig(layers, dataviews, analysis) { - return { - version: '1.5.0', - layers: layers, - dataviews: dataviews || {}, - analyses: analysis || [] - }; -} - -describe('boundingBox-polygon-counter', function() { - - afterEach(function(done) { - if (this.testClient) { - this.testClient.drain(done); - } else { - done(); - } - }); - - var polygon1 = { - type: "Polygon", - coordinates:[[ - [-161.015625,69.28725695167886], - [-162.7734375,-7.710991655433217], - [-40.78125,-8.059229627200192], - [-161.015625,69.28725695167886] - ]] - }; - - var polygon2 = { - type: "Polygon", - coordinates: [[ - [-29.179687499999996,-7.01366792756663], - [103.71093749999999,-6.664607562172573], - [105.46875,69.16255790810501], - [-29.179687499999996,-7.01366792756663] - ]] - }; - - var polygon3 = { - type: "Polygon", - coordinates:[[ - [-117.42187500000001,68.13885164925573], - [-35.859375,20.96143961409684], - [59.4140625,68.52823492039876], - [-117.42187500000001,68.13885164925573] - ]] - }; - - var mapConfig = createMapConfig( - [ - { - "type": "cartodb", - "options": { - "source": { - "id": "a0" - }, - "cartocss": "#points { marker-width: 10; marker-fill: red; }", - "cartocss_version": "2.3.0" - } - } - ], - { - val_formula: { - source: { - id: 'a0' - }, - type: 'formula', - options: { - column: "cartodb_id", - operation: "count", - } - } - }, - [ - { - "id": "a0", - "type": "source", - "params": { - "query": ` - SELECT - ST_TRANSFORM(ST_SETSRID(ST_GeomFromGeoJSON( - '${JSON.stringify(polygon1)}' - ), 4326), 3857) AS the_geom_webmercator, 1 AS cartodb_id - UNION ALL - SELECT - ST_TRANSFORM(ST_SETSRID(ST_GeomFromGeoJSON( - '${JSON.stringify(polygon2)}' - ), 4326), 3857), 2 - UNION ALL - SELECT - ST_TRANSFORM(ST_SETSRID(ST_GeomFromGeoJSON( - '${JSON.stringify(polygon3)}' - ), 4326), 3857), 3 - ` - } - } - ] - ); - - it('should not count the polygons outside the bounding box', function(done) { - this.testClient = new TestClient(mapConfig, 1234); - var params = { - bbox: '-77.34374999999999,45.82879925192134,17.578125,55.97379820507658' - }; - this.testClient.getDataview('val_formula', params, function(err, dataview) { - assert.equal(dataview.result, 1); - done(); - }); - }); -}); \ No newline at end of file diff --git a/test/acceptance/widgets/regressions.js b/test/acceptance/widgets/regressions.js index 1d006ac4..f3ab3aa8 100644 --- a/test/acceptance/widgets/regressions.js +++ b/test/acceptance/widgets/regressions.js @@ -218,6 +218,103 @@ describe('widgets-regressions', function() { }); }); + + it('should not count the polygons outside the bounding box', function(done) { + var notIntersectingLeftTriangle = { + type: "Polygon", + coordinates:[[ + [-161.015625,69.28725695167886], + [-162.7734375,-7.710991655433217], + [-40.78125,-8.059229627200192], + [-161.015625,69.28725695167886] + ]] + }; + + var notIntersectingRightTriangle = { + type: "Polygon", + coordinates: [[ + [-29.179687499999996,-7.01366792756663], + [103.71093749999999,-6.664607562172573], + [105.46875,69.16255790810501], + [-29.179687499999996,-7.01366792756663] + ]] + }; + + var intersectingTriangle = { + type: "Polygon", + coordinates:[[ + [-117.42187500000001,68.13885164925573], + [-35.859375,20.96143961409684], + [59.4140625,68.52823492039876], + [-117.42187500000001,68.13885164925573] + ]] + }; + + let query = ` + SELECT + ST_TRANSFORM(ST_SETSRID(ST_GeomFromGeoJSON( + '${JSON.stringify(notIntersectingLeftTriangle)}' + ), 4326), 3857) AS the_geom_webmercator, 1 AS cartodb_id, 'notIntersectingLeftTriangle' AS name + UNION + SELECT + ST_TRANSFORM(ST_SETSRID(ST_GeomFromGeoJSON( + '${JSON.stringify(notIntersectingRightTriangle)}' + ), 4326), 3857), 2, 'notIntersectingRightTriangle' + UNION + SELECT + ST_TRANSFORM(ST_SETSRID(ST_GeomFromGeoJSON( + '${JSON.stringify(intersectingTriangle)}' + ), 4326), 3857), 3, 'intersectingTriangle' + ` + + var mapConfig = { + version: '1.5.0', + layers: [ + { + "type": "cartodb", + "options": { + "source": { + "id": "a0" + }, + "cartocss": "#points { marker-width: 10; marker-fill: red; }", + "cartocss_version": "2.3.0" + } + } + ], + dataviews: { + val_formula: { + source: { + id: 'a0' + }, + type: 'aggregation', + options: { + column: "name", + aggregation: "count", + } + } + }, + analyses: [ + { + "id": "a0", + "type": "source", + "params": { + "query": query + } + } + ] + }; + + this.testClient = new TestClient(mapConfig, 1234); + var params = { + bbox: '-77.34374999999999,45.82879925192134,17.578125,55.97379820507658' + }; + this.testClient.getDataview('val_formula', params, function(err, dataview) { + assert.equal(dataview.categories.length, 1); + assert.equal(dataview.categories[0].category, 'intersectingTriangle') + done(); + }); + }); + }); }); From fab7832deedb322d68c6270abc136c45a64cfae7 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 10 Aug 2017 18:16:53 +0200 Subject: [PATCH 5/7] added ascii art for polygons count test --- test/acceptance/widgets/regressions.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/acceptance/widgets/regressions.js b/test/acceptance/widgets/regressions.js index f3ab3aa8..1527c8ae 100644 --- a/test/acceptance/widgets/regressions.js +++ b/test/acceptance/widgets/regressions.js @@ -220,6 +220,16 @@ describe('widgets-regressions', function() { it('should not count the polygons outside the bounding box', function(done) { + + // $ % $ = not intersecting left triangle + // $$ **VVVVV** %% % = not intersecting right triangle + // $$$ *VVVVV* %%% * = intersecting triangle + // $$$$ ***** %%%% V = bounding box + // $$$$$ *** %%%%% + // $$$$$$ * %%%%%% + // $$$$$$$ %%%%%%% + // $$$$$$$$ %%%%%%%% + var notIntersectingLeftTriangle = { type: "Polygon", coordinates:[[ From 92d33bf7fd7a94530e39bdd1b7cc5f6eacad8236 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 10 Aug 2017 18:20:15 +0200 Subject: [PATCH 6/7] linter details for polygons count test --- test/acceptance/widgets/regressions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/acceptance/widgets/regressions.js b/test/acceptance/widgets/regressions.js index 1527c8ae..1c2e8f45 100644 --- a/test/acceptance/widgets/regressions.js +++ b/test/acceptance/widgets/regressions.js @@ -275,7 +275,7 @@ describe('widgets-regressions', function() { ST_TRANSFORM(ST_SETSRID(ST_GeomFromGeoJSON( '${JSON.stringify(intersectingTriangle)}' ), 4326), 3857), 3, 'intersectingTriangle' - ` + `; var mapConfig = { version: '1.5.0', @@ -320,7 +320,7 @@ describe('widgets-regressions', function() { }; this.testClient.getDataview('val_formula', params, function(err, dataview) { assert.equal(dataview.categories.length, 1); - assert.equal(dataview.categories[0].category, 'intersectingTriangle') + assert.equal(dataview.categories[0].category, 'intersectingTriangle'); done(); }); }); From 175d070f09b412179f883a20739cfbae7cf6e40d Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 16 Aug 2017 10:07:27 +0200 Subject: [PATCH 7/7] using const instead of let and var and adding assert.ifError --- test/acceptance/widgets/regressions.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/acceptance/widgets/regressions.js b/test/acceptance/widgets/regressions.js index 1c2e8f45..74f4544c 100644 --- a/test/acceptance/widgets/regressions.js +++ b/test/acceptance/widgets/regressions.js @@ -230,7 +230,7 @@ describe('widgets-regressions', function() { // $$$$$$$ %%%%%%% // $$$$$$$$ %%%%%%%% - var notIntersectingLeftTriangle = { + const notIntersectingLeftTriangle = { type: "Polygon", coordinates:[[ [-161.015625,69.28725695167886], @@ -240,7 +240,7 @@ describe('widgets-regressions', function() { ]] }; - var notIntersectingRightTriangle = { + const notIntersectingRightTriangle = { type: "Polygon", coordinates: [[ [-29.179687499999996,-7.01366792756663], @@ -250,7 +250,7 @@ describe('widgets-regressions', function() { ]] }; - var intersectingTriangle = { + const intersectingTriangle = { type: "Polygon", coordinates:[[ [-117.42187500000001,68.13885164925573], @@ -260,7 +260,7 @@ describe('widgets-regressions', function() { ]] }; - let query = ` + const query = ` SELECT ST_TRANSFORM(ST_SETSRID(ST_GeomFromGeoJSON( '${JSON.stringify(notIntersectingLeftTriangle)}' @@ -277,7 +277,7 @@ describe('widgets-regressions', function() { ), 4326), 3857), 3, 'intersectingTriangle' `; - var mapConfig = { + const mapConfig = { version: '1.5.0', layers: [ { @@ -315,10 +315,11 @@ describe('widgets-regressions', function() { }; this.testClient = new TestClient(mapConfig, 1234); - var params = { + const params = { bbox: '-77.34374999999999,45.82879925192134,17.578125,55.97379820507658' }; this.testClient.getDataview('val_formula', params, function(err, dataview) { + assert.ifError(err); assert.equal(dataview.categories.length, 1); assert.equal(dataview.categories[0].category, 'intersectingTriangle'); done();