Skip to content

Commit c4dda06

Browse files
author
Hugo Mercier
authored
Merge pull request #16 from opendatasoft/7.x
Fix consistency between agg simplify and script simplify
2 parents 6dddfdc + 9151a95 commit c4dda06

File tree

5 files changed

+67
-23
lines changed

5 files changed

+67
-23
lines changed

README.md

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -353,30 +353,14 @@ Result:
353353

354354
## Installation
355355

356+
Current supported version is Elasticsearch 7.x (7.17.1).
357+
You can find past releases [here](https://github.com/opendatasoft/elasticsearch-plugin-geoshape/releases).
358+
356359
The first 3 digits of the plugin version is the corresponding Elasticsearch version. The last digit is used for plugin versioning.
357360

358361
To install it, launch this command in Elasticsearch directory replacing the url by the correct link for your Elasticsearch version (see table)
359362
`bin/elasticsearch-plugin https://github.com/opendatasoft/elasticsearch-plugin-geoshape/releases/download/v7.17.1.0/elasticsearch-plugin-geoshape-7.17.1.0.zip"`
360363

361-
| elasticsearch version | plugin version | plugin url |
362-
| --------------------- | -------------- | ---------- |
363-
| 1.6.0 | 1.6.0.5 | https://github.com/opendatasoft/elasticsearch-plugin-geoshape/releases/download/v1.6.0.5/elasticsearch-geo-plugin-1.6.0.5.zip|
364-
| 6.3.2 | 6.3.2.0 | https://github.com/opendatasoft/elasticsearch-plugin-geoshape/releases/download/v6.3.2.0/elasticsearch-plugin-geoshape-6.3.2.0.zip |
365-
| 6.4.3 | 6.4.3.0 | https://github.com/opendatasoft/elasticsearch-plugin-geoshape/releases/download/v6.4.3.0/elasticsearch-plugin-geoshape-6.4.3.0.zip |
366-
| 6.5.4 | 6.5.4.2 | https://github.com/opendatasoft/elasticsearch-plugin-geoshape/releases/download/v6.5.4.2/elasticsearch-plugin-geoshape-6.5.4.2.zip |
367-
| 6.6.2 | 6.6.2.0 | https://github.com/opendatasoft/elasticsearch-plugin-geoshape/releases/download/v6.6.2.0/elasticsearch-plugin-geoshape-6.6.2.0.zip |
368-
| 6.7.1 | 6.7.1.0 | https://github.com/opendatasoft/elasticsearch-plugin-geoshape/releases/download/v6.7.1.0/elasticsearch-plugin-geoshape-6.7.1.0.zip |
369-
| 6.8.2 | 6.8.2.0 | https://github.com/opendatasoft/elasticsearch-plugin-geoshape/releases/download/v6.8.2.0/elasticsearch-plugin-geoshape-6.8.2.0.zip |
370-
| 7.0.1 | 7.0.1.2 | https://github.com/opendatasoft/elasticsearch-plugin-geoshape/releases/download/v7.0.1.2/elasticsearch-plugin-geoshape-7.0.1.2.zip |
371-
| 7.1.1 | 7.1.1.0 | https://github.com/opendatasoft/elasticsearch-plugin-geoshape/releases/download/v7.1.1.0/elasticsearch-plugin-geoshape-7.1.1.0.zip |
372-
| 7.2.0 | 7.2.0.0 | https://github.com/opendatasoft/elasticsearch-plugin-geoshape/releases/download/v7.2.0.0/elasticsearch-plugin-geoshape-7.2.0.0.zip |
373-
| 7.3.2 | 7.3.2.0 | https://github.com/opendatasoft/elasticsearch-plugin-geoshape/releases/download/v7.3.2.0/elasticsearch-plugin-geoshape-7.3.2.0.zip |
374-
| 7.4.0 | 7.4.0.0 | https://github.com/opendatasoft/elasticsearch-plugin-geoshape/releases/download/v7.4.0.0/elasticsearch-plugin-geoshape-7.4.0.0.zip |
375-
| 7.5.1 | 7.5.1.0 | https://github.com/opendatasoft/elasticsearch-plugin-geoshape/releases/download/v7.5.1.0/elasticsearch-plugin-geoshape-7.5.1.0.zip |
376-
| 7.6.0 | 7.6.0.0 | https://github.com/opendatasoft/elasticsearch-plugin-geoshape/releases/download/v7.6.0.0/elasticsearch-plugin-geoshape-7.6.0.0.zip |
377-
| 7.17.1 | 7.17.1.0 | https://github.com/opendatasoft/elasticsearch-plugin-geoshape/releases/download/v7.17.1.0/elasticsearch-plugin-geoshape-7.17.1.0.zip |
378-
379-
380364

381365
## Development Environment Setup
382366

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
elastic_version = 7.17.1
2-
plugin_version = 7.17.1.1
2+
plugin_version = 7.17.1.2

src/main/java/org/opendatasoft/elasticsearch/script/ScriptGeoSimplify.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,19 @@ private static class GeoSearchLeafFactory implements FieldScript.LeafFactory {
6161
private final Map<String, Object> params;
6262
private final SearchLookup lookup;
6363
private final String field;
64-
private final double tolerance;
64+
private final int zoom;
6565
GeoUtils.OutputFormat output_format;
6666
GeoUtils.SimplifyAlgorithm algorithm;
6767
// private final int geojson_decimals;
6868
GeoJsonWriter geoJsonWriter;
6969

7070

7171
private Geometry getSimplifiedShape(Geometry geometry) {
72+
double lat = geometry.getCentroid().getCoordinate().y;
73+
double meterByPixel = GeoUtils.getMeterByPixel(zoom, lat);
74+
75+
// double tolerance = 360 / (256 * Math.pow(zoom, 3));
76+
double tolerance = GeoUtils.getDecimalDegreeFromMeter(meterByPixel, lat);
7277
if (algorithm == GeoUtils.SimplifyAlgorithm.TOPOLOGY_PRESERVING)
7378
return TopologyPreservingSimplifier.simplify(geometry, tolerance);
7479
else
@@ -91,8 +96,7 @@ private GeoSearchLeafFactory(
9196
this.params = params;
9297
this.lookup = lookup;
9398
field = params.get("field").toString();
94-
int zoom = (int) params.get("zoom");
95-
tolerance = GeoUtils.getToleranceFromZoom(zoom);
99+
zoom = (int) params.get("zoom");
96100

97101
output_format = GeoUtils.OutputFormat.GEOJSON;
98102
if (params.containsKey("output_format")) {

src/yamlRestTest/resources/rest-api-spec/test/GeoExtension/30_simplify_script.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@
116116
}
117117
}
118118

119+
- do:
120+
index:
121+
index: test_index
122+
pipeline: "geo_extension"
123+
body: {
124+
"id": 3,
125+
"name": "Le BHV Marais - Paris",
126+
"geo_shape_0": {"type": "Polygon", "coordinates": [[[2.3525621, 48.857395999727686], [2.3525681, 48.85737839972767], [2.3525818, 48.8573607997277], [2.3526161, 48.85734039972769], [2.3526682, 48.857330099727704], [2.3527051, 48.85733319972769], [2.3527095, 48.85732729972771], [2.3527088, 48.85732179972772], [2.3527346, 48.8573134997277], [2.3528807, 48.85728029972772], [2.3530401, 48.857241799727724], [2.3531794, 48.85720819972773], [2.3532811, 48.85718359972775], [2.3534759, 48.85713659972777], [2.3536211, 48.857101599727756], [2.3537783, 48.85706359972777], [2.3538754, 48.85709369972776], [2.3538906, 48.85712099972776], [2.3539385, 48.857206799727734], [2.3540005, 48.857317999727705], [2.3540525, 48.857411199727686], [2.3540721, 48.857446399727685], [2.3540668, 48.85744779972767], [2.3540707, 48.857472599727664], [2.3540622, 48.857497599727665], [2.3540541, 48.857508299727655], [2.3540239, 48.857528399727634], [2.3540001, 48.85753509972766], [2.3540023, 48.85753889972765], [2.3539471, 48.857558899727636], [2.3538824, 48.85758219972763], [2.3538218, 48.85760409972764], [2.3537725, 48.85762189972764], [2.3537123, 48.85764369972763], [2.3536506, 48.85766599972763], [2.3536151, 48.85767879972762], [2.3535832, 48.85769029972763], [2.3535222, 48.8577123997276], [2.3534533, 48.8577372997276], [2.3533762, 48.85776509972759], [2.3532997, 48.8577927997276], [2.353232, 48.85781719972759], [2.3531528, 48.857845799727585], [2.3531009, 48.85786459972756], [2.3530659, 48.857872399727576], [2.3530474, 48.85787309972757], [2.3530175, 48.85787069972757], [2.3529784, 48.857856999727574], [2.3529624, 48.85784619972758], [2.3529494, 48.857833299727574], [2.3529439, 48.857834699727576], [2.3529125, 48.857800499727595], [2.3528479, 48.8577299997276], [2.3527546, 48.85762839972763], [2.3526549, 48.857519699727646], [2.3526422, 48.85750589972766], [2.3526216, 48.85748359972768], [2.3526279, 48.85747989972768], [2.352624, 48.857477099727674], [2.3526301, 48.85747449972769], [2.3526191, 48.85746599972768], [2.3525904, 48.857452299727655], [2.3525766, 48.85744089972767], [2.352564, 48.85741979972767], [2.3525621, 48.857395999727686]]]}
127+
}
128+
119129
- do:
120130
indices.refresh: {}
121131

@@ -176,3 +186,23 @@
176186
algorithm: DOUGLAS_PEUCKER
177187

178188
- match: {hits.hits.0.fields.simplified.0.shape: "{\"type\":\"LineString\",\"coordinates\":[[-3.38057041,47.7575746],[-3.38311851,47.75758181]],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:0\"}}}"}
189+
190+
# test with high zoom and TOPOLOGY_PRESERVING (exact same test as 40_geoshape_aggregation.yml one!)
191+
- do:
192+
search:
193+
body:
194+
query:
195+
term:
196+
id: 3
197+
script_fields:
198+
simplified:
199+
script:
200+
source: geo_simplify
201+
lang: geo_extension_scripts
202+
params:
203+
field: "geo_shape_0.wkb"
204+
zoom: 20
205+
algorithm: TOPOLOGY_PRESERVING
206+
207+
# coordinates length must be 37. it's not possible to test this length because the shape is dumped as a text, so we're testing the full shape length here instead
208+
- length: {hits.hits.0.fields.simplified.0.shape: 935}

src/yamlRestTest/resources/rest-api-spec/test/GeoExtension/40_geoshape_aggregation.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@
116116
}
117117
}
118118

119+
- do:
120+
index:
121+
index: test_index
122+
pipeline: "geo_extension"
123+
body: {
124+
"id": 3,
125+
"name": "Le BHV Marais - Paris",
126+
"geo_shape_0": {"type": "Polygon", "coordinates": [[[2.3525621, 48.857395999727686], [2.3525681, 48.85737839972767], [2.3525818, 48.8573607997277], [2.3526161, 48.85734039972769], [2.3526682, 48.857330099727704], [2.3527051, 48.85733319972769], [2.3527095, 48.85732729972771], [2.3527088, 48.85732179972772], [2.3527346, 48.8573134997277], [2.3528807, 48.85728029972772], [2.3530401, 48.857241799727724], [2.3531794, 48.85720819972773], [2.3532811, 48.85718359972775], [2.3534759, 48.85713659972777], [2.3536211, 48.857101599727756], [2.3537783, 48.85706359972777], [2.3538754, 48.85709369972776], [2.3538906, 48.85712099972776], [2.3539385, 48.857206799727734], [2.3540005, 48.857317999727705], [2.3540525, 48.857411199727686], [2.3540721, 48.857446399727685], [2.3540668, 48.85744779972767], [2.3540707, 48.857472599727664], [2.3540622, 48.857497599727665], [2.3540541, 48.857508299727655], [2.3540239, 48.857528399727634], [2.3540001, 48.85753509972766], [2.3540023, 48.85753889972765], [2.3539471, 48.857558899727636], [2.3538824, 48.85758219972763], [2.3538218, 48.85760409972764], [2.3537725, 48.85762189972764], [2.3537123, 48.85764369972763], [2.3536506, 48.85766599972763], [2.3536151, 48.85767879972762], [2.3535832, 48.85769029972763], [2.3535222, 48.8577123997276], [2.3534533, 48.8577372997276], [2.3533762, 48.85776509972759], [2.3532997, 48.8577927997276], [2.353232, 48.85781719972759], [2.3531528, 48.857845799727585], [2.3531009, 48.85786459972756], [2.3530659, 48.857872399727576], [2.3530474, 48.85787309972757], [2.3530175, 48.85787069972757], [2.3529784, 48.857856999727574], [2.3529624, 48.85784619972758], [2.3529494, 48.857833299727574], [2.3529439, 48.857834699727576], [2.3529125, 48.857800499727595], [2.3528479, 48.8577299997276], [2.3527546, 48.85762839972763], [2.3526549, 48.857519699727646], [2.3526422, 48.85750589972766], [2.3526216, 48.85748359972768], [2.3526279, 48.85747989972768], [2.352624, 48.857477099727674], [2.3526301, 48.85747449972769], [2.3526191, 48.85746599972768], [2.3525904, 48.857452299727655], [2.3525766, 48.85744089972767], [2.352564, 48.85741979972767], [2.3525621, 48.857395999727686]]]}
127+
}
128+
119129
- do:
120130
indices.refresh: {}
121131

@@ -177,3 +187,19 @@
177187

178188
- match: {aggregations.g.buckets.0.key: "{\"type\":\"Polygon\",\"coordinates\":[[[-3.3889389,47.73770713],[-3.37778091,47.73851525],[-3.385849,47.74428718],[-3.3889389,47.73770713]]],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:0\"}}}"}
179189

190+
# test with high zoom and TOPOLOGY_PRESERVING (exact same test as 30_simplify_script.yml one!)
191+
- do:
192+
search:
193+
body:
194+
size: 0
195+
aggs:
196+
g:
197+
geoshape:
198+
field: "geo_shape_0.wkb"
199+
output_format: geojson
200+
simplify:
201+
zoom: 20
202+
algorithm: TOPOLOGY_PRESERVING
203+
204+
# coordinates length must be 37. it's not possible to test this length because the shape is dumped as a text, so we're testing the full shape length here instead
205+
- length: {aggregations.g.buckets.1.key: 935}

0 commit comments

Comments
 (0)