diff --git a/src/main/java/org/heigit/ohsome/ohsomeapi/executor/AggregateRequestExecutor.java b/src/main/java/org/heigit/ohsome/ohsomeapi/executor/AggregateRequestExecutor.java index 2e587c70..c38305a9 100644 --- a/src/main/java/org/heigit/ohsome/ohsomeapi/executor/AggregateRequestExecutor.java +++ b/src/main/java/org/heigit/ohsome/ohsomeapi/executor/AggregateRequestExecutor.java @@ -352,10 +352,6 @@ private ElementsResult[] fillElementsResult(SortedMap filter = processingData.getFilterExpression(); - if (filter.isPresent() && ProcessingData.filterContainsGeometryTypeCheck(filter.get())) { - mapAgg = inputProcessor.filterOnGeometryType(mapAgg, filter.get()); - } preResult = mapAgg.map(OSMEntitySnapshot::getGeometry); switch (requestResource) { case COUNT: diff --git a/src/main/java/org/heigit/ohsome/ohsomeapi/executor/ElementsRequestExecutor.java b/src/main/java/org/heigit/ohsome/ohsomeapi/executor/ElementsRequestExecutor.java index 3a63e082..be3e2e50 100644 --- a/src/main/java/org/heigit/ohsome/ohsomeapi/executor/ElementsRequestExecutor.java +++ b/src/main/java/org/heigit/ohsome/ohsomeapi/executor/ElementsRequestExecutor.java @@ -196,10 +196,6 @@ public static

Response aggregateGroupByBoundary if (processingData.isContainingSimpleFeatureTypes()) { mapAgg = inputProcessor.filterOnSimpleFeatures(mapAgg); } - Optional filter = processingData.getFilterExpression(); - if (filter.isPresent() && ProcessingData.filterContainsGeometryTypeCheck(filter.get())) { - mapAgg = inputProcessor.filterOnGeometryType(mapAgg, filter.get()); - } ExecutionUtils exeUtils = new ExecutionUtils(processingData); var preResult = mapAgg.map(f -> exeUtils.mapSnapshotToTags(keysInt, valuesInt, f)) .aggregateBy(Pair::getKey, zeroFill).map(Pair::getValue) diff --git a/src/main/java/org/heigit/ohsome/ohsomeapi/executor/UsersRequestExecutor.java b/src/main/java/org/heigit/ohsome/ohsomeapi/executor/UsersRequestExecutor.java index 16b7710e..fe88228b 100644 --- a/src/main/java/org/heigit/ohsome/ohsomeapi/executor/UsersRequestExecutor.java +++ b/src/main/java/org/heigit/ohsome/ohsomeapi/executor/UsersRequestExecutor.java @@ -315,10 +315,6 @@ public static

Response countGroupByBoundary( if (processingData.isContainingSimpleFeatureTypes()) { mapAgg = inputProcessor.filterOnSimpleFeatures(mapAgg); } - Optional filter = processingData.getFilterExpression(); - if (filter.isPresent() && ProcessingData.filterContainsGeometryTypeCheck(filter.get())) { - mapAgg = inputProcessor.filterOnGeometryType(mapAgg, filter.get()); - } SortedMap, Integer> result = mapAgg.map(OSMContribution::getContributorUserId).countUniq(); SortedMap> groupByResult; diff --git a/src/main/java/org/heigit/ohsome/ohsomeapi/inputprocessing/InputProcessor.java b/src/main/java/org/heigit/ohsome/ohsomeapi/inputprocessing/InputProcessor.java index f3a6e44b..bf6b31be 100644 --- a/src/main/java/org/heigit/ohsome/ohsomeapi/inputprocessing/InputProcessor.java +++ b/src/main/java/org/heigit/ohsome/ohsomeapi/inputprocessing/InputProcessor.java @@ -263,17 +263,7 @@ public MapReducer processParameters(ComputeMode FilterParser fp = new FilterParser(DbConnData.tagTranslator); FilterExpression filterExpr = utils.parseFilter(fp, filter); processingData.setFilterExpression(filterExpr); - mapRed = optimizeFilters0(mapRed, filterExpr); - mapRed = optimizeFilters1(mapRed, filterExpr); - mapRed = mapRed.osmEntityFilter(filterExpr::applyOSM); - // execute this only if the filter has a geometry type subfilter - if (ProcessingData.filterContainsGeometryTypeCheck(filterExpr) - // skip in ratio or groupByBoundary requests -> needs to be done later in the processing - && !processingData.isRatio() && !processingData.isGroupByBoundary() - && !processingData.isFullHistory()) { - processingData.setContainingSimpleFeatureTypes(true); - mapRed = filterOnGeometryType(mapRed, filterExpr); - } + mapRed = mapRed.filter(filterExpr); } } else { mapRed = extractKeysValues(mapRed, keys, values); @@ -281,59 +271,6 @@ public MapReducer processParameters(ComputeMode return (MapReducer) mapRed; } - private MapReducer optimizeFilters0( - MapReducer mapRed, FilterExpression filter) { - // performs basic optimizations “low hanging fruit”: - // single filters, and-combination of single filters, etc. - if (filter instanceof TagFilterEquals) { - OSMTag tag = DbConnData.tagTranslator.getOSMTagOf(((TagFilterEquals) filter).getTag()); - return mapRed.osmTag(tag); - } - if (filter instanceof TagFilterEqualsAny) { - OSMTagKey key = - DbConnData.tagTranslator.getOSMTagKeyOf(((TagFilterEqualsAny) filter).getTag()); - return mapRed.osmTag(key); - } - if (filter instanceof TypeFilter) { - return mapRed.osmType(((TypeFilter) filter).getType()); - } - if (filter instanceof AndOperator) { - return optimizeFilters0(optimizeFilters0(mapRed, ((AndOperator) filter).getLeftOperand()), - ((AndOperator) filter).getRightOperand()); - } - return mapRed; - } - - private MapReducer optimizeFilters1( - MapReducer mapRed, FilterExpression filter) { - // performs more advanced optimizations that rely on analyzing the DNF of a filter expression - // 1. convert to disjunctive normal form - List> filterNormalized = filter.normalize(); - // 2. collect all OSMTypes in all of the clauses - EnumSet allTypes = EnumSet.noneOf(OSMType.class); - for (List andSubFilter : filterNormalized) { - EnumSet subTypes = EnumSet.of(OSMType.NODE, OSMType.WAY, OSMType.RELATION); - for (Filter subFilter : andSubFilter) { - if (subFilter instanceof TypeFilter) { - subTypes.retainAll(EnumSet.of(((TypeFilter) subFilter).getType())); - } else if (subFilter instanceof GeometryTypeFilter) { - subTypes.retainAll(((GeometryTypeFilter) subFilter).getOSMTypes()); - } - } - allTypes.addAll(subTypes); - } - mapRed = mapRed.osmType(allTypes); - processingData.setOsmTypes(allTypes); - // 3. (todo) intelligently group queried tags - /* - * here, we could optimize a few situations further: when a specific tag or key is used in all - * branches of the filter: run mapRed.osmTag the set of tags which are present in any branches: - * run mapRed.osmTag(list) (note that for this all branches need to have at least one - * TagFilterEquals or TagFilterEqualsAny) related: https://github.com/GIScience/oshdb/pull/210 - */ - return mapRed; - } - /** * Defines the type(s) out of the given String[]. * @@ -549,60 +486,6 @@ public > T filterOnSimpleFeature }); } - /** - * Applies respective Puntal|Lineal|Polygonal filter(s) from a given filter expression on features - * of the given MapReducer. - * - * @param mapRed the mapreducer to filter - * @param filterExpr the filter expression to apply - * @return MapReducer with filtered geometries - * @throws RuntimeException if {@link - * org.heigit.ohsome.ohsomeapi.inputprocessing.InputProcessor#filterOnGeometryType( - * Mappable, FilterExpression) filterOnGeometryType} was called on mapped entries - */ - // suppressed, as filter always returns the same mappable type T - @SuppressWarnings("unchecked") - public > T filterOnGeometryType(T mapRed, - FilterExpression filterExpr) { - return (T) mapRed.filter(data -> { - if (data instanceof OSMEntitySnapshot) { - OSMEntitySnapshot snapshot = (OSMEntitySnapshot) data; - OSMEntity snapshotEntity = snapshot.getEntity(); - Supplier snapshotGeom; - if (clipGeometry) { - snapshotGeom = snapshot::getGeometry; - } else { - snapshotGeom = snapshot::getGeometryUnclipped; - } - return filterExpr.applyOSMGeometry(snapshotEntity, snapshotGeom); - } else if (data instanceof OSMContribution) { - OSMContribution contribution = (OSMContribution) data; - OSMEntity entityBefore = contribution.getEntityBefore(); - OSMEntity entityAfter = contribution.getEntityAfter(); - Supplier contribGeomBefore; - Supplier contribGeomAfter; - if (clipGeometry) { - contribGeomBefore = contribution::getGeometryBefore; - contribGeomAfter = contribution::getGeometryAfter; - } else { - contribGeomBefore = contribution::getGeometryUnclippedBefore; - contribGeomAfter = contribution::getGeometryUnclippedAfter; - } - if (contribution.is(ContributionType.CREATION)) { - return filterExpr.applyOSMGeometry(entityAfter, contribGeomAfter); - } else if (contribution.is(ContributionType.DELETION)) { - return filterExpr.applyOSMGeometry(entityBefore, contribGeomBefore); - } else { - return filterExpr.applyOSMGeometry(entityAfter, contribGeomBefore) - && filterExpr.applyOSMGeometry(entityAfter, contribGeomAfter); - } - } else { - assert false : "geometry filter called on mapped entries"; - throw new RuntimeException("geometry filter called on mapped entries"); - } - }); - } - /** * Checks the given filter parameter if it's null or blank. Currently used for filter2 parameter * of /ratio processing.