Skip to content

Commit 7a476ce

Browse files
authored
Merge pull request #139 from GIScience/fix-issue-138
round output coordinates to 7 decimal places closes #138
2 parents c0772d3 + e3bfa46 commit 7a476ce

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Changelog
1717
* update all tests using the filter parameter instead of deprecated types, keys, values ([#98])
1818
* update some default parameter values in swagger UI to slightly more sensible examples ([#113])
1919
* restructure packages and classes within the controller and output packages ([#117])
20+
* round coordinates of returned OSM features to 7 decimal places ([#138])
2021

2122
[#98]: https://github.com/GIScience/ohsome-api/issues/98
2223
[#111]: https://github.com/GIScience/ohsome-api/issues/111
@@ -25,6 +26,7 @@ Changelog
2526
[#117]: https://github.com/GIScience/ohsome-api/issues/117
2627
[#129]: https://github.com/GIScience/ohsome-api/issues/129
2728
[#131]: https://github.com/GIScience/ohsome-api/issues/131
29+
[#138]: https://github.com/GIScience/ohsome-api/issues/138
2830

2931

3032
## 1.3.2

docs/endpoints.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ Get the changes of pharmacies with opening hours in a certain area of Heidelberg
13501350
"type" : "Point",
13511351
"coordinates" : [
13521352
8.6902451,
1353-
49.408015899999995
1353+
49.4080159
13541354
]
13551355
},
13561356
"properties" : {
@@ -1426,7 +1426,7 @@ Get the changes of pharmacies with opening hours in a certain area of Heidelberg
14261426
"type" : "Point",
14271427
"coordinates" : [
14281428
8.6902451,
1429-
49.408015899999995
1429+
49.4080159
14301430
]
14311431
},
14321432
"properties" : {
@@ -1502,7 +1502,7 @@ Get the changes of pharmacies with opening hours in a certain area of Heidelberg
15021502
"type" : "Point",
15031503
"coordinates" : [
15041504
8.6902451,
1505-
49.408015899999995
1505+
49.4080159
15061506
]
15071507
},
15081508
"properties" : {
@@ -1578,7 +1578,7 @@ Get the changes of pharmacies with opening hours in a certain area of Heidelberg
15781578
"type" : "Point",
15791579
"coordinates" : [
15801580
8.6902451,
1581-
49.408015899999995
1581+
49.4080159
15821582
]
15831583
},
15841584
"properties" : {

src/main/lombok/org/heigit/ohsome/ohsomeapi/executor/DataRequestExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ public void extract() throws Exception {
120120
metadata = new Metadata(null, requestResource.getDescription(),
121121
inputProcessor.getRequestUrlIfGetRequest(servletRequest));
122122
}
123-
ExtractionResponse osmData = new ExtractionResponse(ATTRIBUTION, Application.API_VERSION, metadata,
124-
"FeatureCollection", Collections.emptyList());
123+
ExtractionResponse osmData = new ExtractionResponse(ATTRIBUTION, Application.API_VERSION,
124+
metadata, "FeatureCollection", Collections.emptyList());
125125
MapReducer<Feature> snapshotPreResult = null;
126126
if (!isContributionsEndpoint) {
127127
// handles cases where valid_from = t_start, valid_to = t_end; i.e. non-modified data

src/main/lombok/org/heigit/ohsome/ohsomeapi/executor/ExecutionUtils.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@
7070
import org.heigit.ohsome.ohsomeapi.oshdb.DbConnData;
7171
import org.heigit.ohsome.ohsomeapi.oshdb.ExtractMetadata;
7272
import org.heigit.ohsome.ohsomeapi.output.Attribution;
73-
import org.heigit.ohsome.ohsomeapi.output.ExtractionResponse;
7473
import org.heigit.ohsome.ohsomeapi.output.Description;
74+
import org.heigit.ohsome.ohsomeapi.output.ExtractionResponse;
7575
import org.heigit.ohsome.ohsomeapi.output.Metadata;
7676
import org.heigit.ohsome.ohsomeapi.output.Response;
7777
import org.heigit.ohsome.ohsomeapi.output.Result;
@@ -89,7 +89,9 @@
8989
import org.locationtech.jts.geom.Geometry;
9090
import org.locationtech.jts.geom.Lineal;
9191
import org.locationtech.jts.geom.Polygonal;
92+
import org.locationtech.jts.geom.PrecisionModel;
9293
import org.locationtech.jts.geom.Puntal;
94+
import org.locationtech.jts.precision.GeometryPrecisionReducer;
9395
import org.wololo.jts2geojson.GeoJSONWriter;
9496

9597
/** Holds helper methods that are used by the executor classes. */
@@ -98,6 +100,7 @@ public class ExecutionUtils {
98100
private AtomicReference<Boolean> isFirst;
99101
private final ProcessingData processingData;
100102
private final DecimalFormat ratioDf = defineDecimalFormat("#.######");
103+
private final GeometryPrecisionReducer gpr = createGeometryPrecisionReducer();
101104

102105
/** Applies a filter on the given MapReducer object using the given parameters. */
103106
public MapReducer<OSMEntitySnapshot> snapshotFilter(MapReducer<OSMEntitySnapshot> mapRed,
@@ -414,7 +417,8 @@ public org.wololo.geojson.Feature createOSMFeature(OSMEntity entity, Geometry ge
414417
default:
415418
outputGeometry = geometry;
416419
}
417-
return new org.wololo.geojson.Feature(gjw.write(outputGeometry), properties);
420+
return new org.wololo.geojson.Feature(gjw.write(gpr.reduce(outputGeometry)),
421+
properties);
418422
}
419423

420424
/**
@@ -958,6 +962,17 @@ private Map<String, Object> addAdditionalProperties(OSMEntity entity,
958962
return properties;
959963
}
960964

965+
/**
966+
* returns a new geometry precision reducer using a precision of 7 digits, having an activated
967+
* point-wise mode and a deactivated remove-collapsed-components mode
968+
*/
969+
private GeometryPrecisionReducer createGeometryPrecisionReducer() {
970+
var gpr = new GeometryPrecisionReducer(new PrecisionModel(1E7));
971+
gpr.setPointwise(true);
972+
gpr.setRemoveCollapsedComponents(false);
973+
return gpr;
974+
}
975+
961976
static Set<Integer> keysToKeysInt(String[] keys, TagTranslator tt) {
962977
final Set<Integer> keysInt;
963978
if (keys.length != 0) {

src/test/java/org/heigit/ohsome/ohsomeapi/controller/DataExtractionTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ public void elementsCentroidTest() {
158158
* ./elementsFullHistory/geometry|bbox|centroid tests
159159
*/
160160

161+
@Test
162+
public void elementsGeometryCoordinateTest() {
163+
TestRestTemplate restTemplate = new TestRestTemplate();
164+
ResponseEntity<JsonNode> response = restTemplate.getForEntity(server + port
165+
+ "/elements/geometry?bboxes=8.68641,49.41642,8.69499,49.42112&filter=id:node/3429511451&"
166+
+ "time=2019-01-01", JsonNode.class);
167+
JsonNode feature = Helper.getFeatureByIdentifier(response, "@osmId", "node/3429511451");
168+
assertEquals(49.418466, feature.get("geometry").get("coordinates").get(1).asDouble(), 0);
169+
}
170+
161171
@Test
162172
public void elementsFullHistoryGeometryTest() {
163173
TestRestTemplate restTemplate = new TestRestTemplate();
@@ -428,6 +438,16 @@ public void contributionsAssociationChangeSetIdWithOsmIdAndVersion() {
428438
&& featureProperties.get("@osmId").asText().equals("way/96054443"));
429439
}
430440

441+
@Test
442+
public void contributionsGeometryCoordinateTest() {
443+
TestRestTemplate restTemplate = new TestRestTemplate();
444+
ResponseEntity<JsonNode> response = restTemplate.getForEntity(server + port
445+
+ "/contributions/geometry?bboxes=8.68641,49.41642,8.69499,49.42112"
446+
+ "&filter=id:node/3429511451&time=2017-01-01,2019-01-01", JsonNode.class);
447+
JsonNode feature = Helper.getFeatureByIdentifier(response, "@osmId", "node/3429511451");
448+
assertEquals(49.418466, feature.get("geometry").get("coordinates").get(1).asDouble(), 0);
449+
}
450+
431451
/*
432452
* ./contributions/latest tests
433453
*/

0 commit comments

Comments
 (0)