Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Changelog
* fix returning invalid GeoJSON using empty coordinates for deletion contributions ([#129], [#131])
* fix using a proper boolean data type instead of a string for contributionType in response ([#135])
* fix NPE with createOSMFeature ([#141])
* make sure geometry filters are applied to all returned features of elementsFullHistory requests ([#109])

### Performance and Code Quality

Expand All @@ -25,6 +26,7 @@ Changelog

[#83]: https://github.com/GIScience/ohsome-api/issues/83
[#98]: https://github.com/GIScience/ohsome-api/issues/98
[#109]: https://github.com/GIScience/ohsome-api/issues/109
[#111]: https://github.com/GIScience/ohsome-api/issues/111
[#113]: https://github.com/GIScience/ohsome-api/issues/113
[#114]: https://github.com/GIScience/ohsome-api/pull/114
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.function.Supplier;
import org.heigit.bigspatialdata.oshdb.api.object.OSMContribution;
import org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot;
import org.heigit.bigspatialdata.oshdb.osm.OSMEntity;
import org.heigit.bigspatialdata.oshdb.util.celliterator.ContributionType;
import org.heigit.bigspatialdata.oshdb.util.time.TimestampFormatter;
import org.heigit.ohsome.filter.FilterExpression;
import org.heigit.ohsome.ohsomeapi.controller.dataextraction.elements.ElementsGeometry;
import org.heigit.ohsome.ohsomeapi.inputprocessing.InputProcessingUtils;
import org.heigit.ohsome.ohsomeapi.inputprocessing.SimpleFeatureType;
Expand All @@ -28,6 +28,7 @@ public class DataExtractionTransformer implements Serializable {
private final String startTimestamp;
private final InputProcessingUtils utils;
private final Set<SimpleFeatureType> simpleFeatureTypes;
private final FilterExpression filter;
private final Set<Integer> keysInt;
private final boolean includeTags;
private final boolean includeOSMMetadata;
Expand All @@ -38,8 +39,9 @@ public class DataExtractionTransformer implements Serializable {
public DataExtractionTransformer(boolean isContributionsLatestEndpoint,
boolean isContributionsEndpoint, ExecutionUtils exeUtils,
boolean clipGeometries, String startTimestamp, InputProcessingUtils utils,
Set<SimpleFeatureType> simpleFeatureTypes, Set<Integer> keysInt, boolean includeTags,
boolean includeOSMMetadata, ElementsGeometry elementsGeometry, String endTimestamp,
Set<SimpleFeatureType> simpleFeatureTypes, FilterExpression filter,
Set<Integer> keysInt, boolean includeTags, boolean includeOSMMetadata,
ElementsGeometry elementsGeometry, String endTimestamp,
boolean isContainingSimpleFeatureTypes) {
this.isContributionsLatestEndpoint = isContributionsLatestEndpoint;
this.isContributionsEndpoint = isContributionsEndpoint;
Expand All @@ -48,6 +50,7 @@ public DataExtractionTransformer(boolean isContributionsLatestEndpoint,
this.startTimestamp = startTimestamp;
this.utils = utils;
this.simpleFeatureTypes = simpleFeatureTypes;
this.filter = filter;
this.keysInt = keysInt;
this.includeTags = includeTags;
this.includeOSMMetadata = includeOSMMetadata;
Expand Down Expand Up @@ -90,9 +93,7 @@ public List<Feature> buildChangedFeatures(List<OSMContribution> contributions) {
// set valid_to of previous row
validTo = TimestampFormatter.getInstance().isoDateTime(contribution.getTimestamp());
if (!skipNext && currentGeom != null && !currentGeom.isEmpty()) {
final Geometry geomToCheck = currentGeom;
boolean addToOutput = addEntityToOutput(isContainingSimpleFeatureTypes, utils,
simpleFeatureTypes, () -> geomToCheck);
boolean addToOutput = addEntityToOutput(currentEntity, currentGeom);
if (addToOutput) {
properties = new TreeMap<>();
if (!isContributionsEndpoint) {
Expand Down Expand Up @@ -134,9 +135,7 @@ public List<Feature> buildChangedFeatures(List<OSMContribution> contributions) {
TimestampFormatter.getInstance().isoDateTime(lastContribution.getTimestamp()));
}
if (!currentGeom.isEmpty()) {
final Geometry geomToCheck = currentGeom;
boolean addToOutput = addEntityToOutput(isContainingSimpleFeatureTypes, utils,
simpleFeatureTypes, () -> geomToCheck);
boolean addToOutput = addEntityToOutput(currentEntity, currentGeom);
if (addToOutput) {
output.add(exeUtils.createOSMFeature(currentEntity, currentGeom, properties, keysInt,
includeTags, includeOSMMetadata, isContributionsEndpoint, elementsGeometry,
Expand All @@ -162,39 +161,32 @@ public List<Feature> buildUnchangedFeatures(OSMEntitySnapshot snapshot) {
if (includeOSMMetadata) {
properties.put("@lastEdit", entity.getTimestamp().toString());
}
Supplier<Geometry> geom;
Geometry geom;
if (clipGeometries) {
geom = snapshot::getGeometry;
geom = snapshot.getGeometry();
} else {
geom = snapshot::getGeometryUnclipped;
geom = snapshot.getGeometryUnclipped();
}
properties.put("@snapshotTimestamp",
TimestampFormatter.getInstance().isoDateTime(snapshot.getTimestamp()));
properties.put("@validFrom", startTimestamp);
properties.put("@validTo", endTimestamp);
boolean addToOutput = addEntityToOutput(isContainingSimpleFeatureTypes, utils,
simpleFeatureTypes, geom);
boolean addToOutput = addEntityToOutput(entity, geom);
if (addToOutput) {
return Collections.singletonList(
exeUtils.createOSMFeature(entity, geom.get(), properties, keysInt, includeTags,
exeUtils.createOSMFeature(entity, geom, properties, keysInt, includeTags,
includeOSMMetadata, isContributionsEndpoint, elementsGeometry, null));
} else {
return Collections.emptyList();
}
}

/** Checks whether the given entity should be added to the output (true) or not (false). */
public static boolean addEntityToOutput(
boolean isContainingSimpleFeatureTypes,
InputProcessingUtils utils,
final Set<SimpleFeatureType> simpleFeatureTypes,
Supplier<Geometry> currentGeom) {
boolean addToOutput;
public boolean addEntityToOutput(OSMEntity currentEntity, Geometry currentGeom) {
if (isContainingSimpleFeatureTypes) {
addToOutput = utils.checkGeometryOnSimpleFeatures(currentGeom.get(), simpleFeatureTypes);
return utils.checkGeometryOnSimpleFeatures(currentGeom, simpleFeatureTypes);
} else {
addToOutput = true;
return filter == null || filter.applyOSMGeometry(currentEntity, currentGeom);
}
return addToOutput;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ public void extract() throws Exception {
final boolean isContainingSimpleFeatureTypes = processingData.isContainingSimpleFeatureTypes();
DataExtractionTransformer dataExtractionTransformer = new DataExtractionTransformer(
isContributionsLatestEndpoint, isContributionsEndpoint, exeUtils, clipGeometries,
startTimestamp, utils, simpleFeatureTypes, keysInt, includeTags, includeOSMMetadata,
elementsGeometry, endTimestamp, isContainingSimpleFeatureTypes);
startTimestamp, utils, simpleFeatureTypes, filter.orElse(null), keysInt, includeTags,
includeOSMMetadata, elementsGeometry, endTimestamp, isContainingSimpleFeatureTypes);
MapReducer<Feature> contributionPreResult = mapRedContributions
.flatMap(dataExtractionTransformer::buildChangedFeatures)
.filter(Objects::nonNull);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public void contributionsVersionTest() {
}

@Test
public void contributionsAssociationChangeSetIdWithOsmIdAndVersion() {
public void contributionsAssociationChangeSetIdWithOsmIdAndVersionTest() {
TestRestTemplate restTemplate = new TestRestTemplate();
ResponseEntity<JsonNode> response = restTemplate.getForEntity(server + port
+ "/contributions/bbox?bboxes=8.70606,49.412150,8.70766,49.413686"
Expand Down Expand Up @@ -515,4 +515,18 @@ public void contributionsLatestCreationTest() {
assertTrue(
response.getBody().get("features").get(0).get("properties").get("@creation").asBoolean());
}

@Test
public void issue109Test() {
// see https://github.com/GIScience/ohsome-api/issues/109
TestRestTemplate restTemplate = new TestRestTemplate();
// this uses the centroid endpoint to make sure that geometry filters are even applied to
// the geometries before being transformed to, e.g., centroid points
ResponseEntity<JsonNode> response = restTemplate.getForEntity(
server + port
+ "/elementsFullHistory/centroid?bboxes=8.69525,49.40938,8.70461,49.41203&"
Comment thread
tyrasd marked this conversation as resolved.
+ "time=2011-09-05,2011-09-06&filter=geometry:polygon and id:relation/1391838",
JsonNode.class);
assertEquals(1, response.getBody().get("features").size());
Comment thread
tyrasd marked this conversation as resolved.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ public void getOrFilterTest() {
}

@Test
public void getRequestEndsByQuestionMark() {
public void getRequestEndsByQuestionMarkTest() {
TestRestTemplate restTemplate = new TestRestTemplate();
ResponseEntity<JsonNode> response =
restTemplate.getForEntity(server + port + "/users/count?", JsonNode.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ public void postUmlautFilterTest() {
}

@Test
public void postQueryRequestEndsByQuestionMark() {
public void postQueryRequestEndsByQuestionMarkTest() {
TestRestTemplate restTemplate = new TestRestTemplate();
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
ResponseEntity<JsonNode> response =
Expand Down