Commit 64051e7b authored by Martin Raifer's avatar Martin Raifer

Merge branch 'geometry-supplier' into 'master'

allow geometry suppliers

Closes #8

See merge request !22
parents 8c450609 f70f1b5b
package org.heigit.ohsome.filter;
import java.util.function.Supplier;
import org.heigit.bigspatialdata.oshdb.osh.OSHEntity;
import org.heigit.bigspatialdata.oshdb.osm.OSMEntity;
import org.locationtech.jts.geom.Geometry;
......@@ -23,8 +24,9 @@ public class AndOperator extends BinaryOperator {
}
@Override
public boolean applyOSMGeometry(OSMEntity entity, Geometry geometry) {
return op1.applyOSMGeometry(entity, geometry) && op2.applyOSMGeometry(entity, geometry);
public boolean applyOSMGeometry(OSMEntity entity, Supplier<Geometry> geometrySupplier) {
return op1.applyOSMGeometry(entity, geometrySupplier)
&& op2.applyOSMGeometry(entity, geometrySupplier);
}
@Override
......
......@@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Supplier;
import org.heigit.bigspatialdata.oshdb.osh.OSHEntity;
import org.heigit.bigspatialdata.oshdb.osm.OSMEntity;
import org.jetbrains.annotations.Contract;
......@@ -42,6 +43,21 @@ public interface FilterExpression extends Serializable {
return Streams.stream(entity.getVersions()).anyMatch(this::applyOSM);
}
/**
* Apply the filter to an "OSM feature" (i.e. an entity with a geometry).
*
* <p>The default implementation doesn't perform a geometry type check, but any Filter can
* override it to do so.</p>
*
* @param entity the OSM entity to check.
* @param geometrySupplier a function returning the geometry of this OSM feature to check.
* @return true if the OSM feature fulfills the specified filter, otherwise false.
*/
@Contract(pure = true)
default boolean applyOSMGeometry(OSMEntity entity, Supplier<Geometry> geometrySupplier) {
return applyOSM(entity);
}
/**
* Apply the filter to an "OSM feature" (i.e. an entity with a geometry).
*
......@@ -54,7 +70,7 @@ public interface FilterExpression extends Serializable {
*/
@Contract(pure = true)
default boolean applyOSMGeometry(OSMEntity entity, Geometry geometry) {
return applyOSM(entity);
return applyOSMGeometry(entity, () -> geometry);
}
/**
......
package org.heigit.ohsome.filter;
import java.io.Serializable;
import java.util.function.Supplier;
import java.util.function.ToDoubleFunction;
import javax.annotation.Nonnull;
import org.heigit.bigspatialdata.oshdb.osh.OSHEntity;
......@@ -77,8 +78,8 @@ public abstract class GeometryFilter extends NegatableFilter {
}
@Override
public boolean applyOSMGeometry(OSMEntity entity, Geometry geometry) {
return valueRange.test(metricEvaluator.applyAsDouble(geometry));
public boolean applyOSMGeometry(OSMEntity entity, Supplier<Geometry> geometrySupplier) {
return valueRange.test(metricEvaluator.applyAsDouble(geometrySupplier.get()));
}
@Override
......
......@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;
import javax.annotation.Nonnull;
import org.heigit.bigspatialdata.oshdb.osh.OSHEntity;
import org.heigit.bigspatialdata.oshdb.osm.OSMEntity;
......@@ -151,9 +152,9 @@ public class GeometryTypeFilter implements Filter {
}
@Override
public boolean applyOSMGeometry(OSMEntity entity, Geometry geometry) {
public boolean applyOSMGeometry(OSMEntity entity, Supplier<Geometry> geometrySupplier) {
return checkOSMType(entity.getType())
&& checkGeometryType(geometry);
&& checkGeometryType(geometrySupplier.get());
}
@Override
......
package org.heigit.ohsome.filter;
import java.util.function.Supplier;
import javax.annotation.Nonnull;
import org.heigit.bigspatialdata.oshdb.osh.OSHEntity;
import org.heigit.bigspatialdata.oshdb.osm.OSMEntity;
......@@ -39,8 +40,8 @@ class NegatableFilter implements Filter {
}
@Override
public boolean applyOSMGeometry(OSMEntity entity, Geometry geometry) {
return this.filter.applyOSMGeometry(entity, geometry) ^ this.negated;
public boolean applyOSMGeometry(OSMEntity entity, Supplier<Geometry> geometrySupplier) {
return this.filter.applyOSMGeometry(entity, geometrySupplier) ^ this.negated;
}
@Override
......
package org.heigit.ohsome.filter;
import java.util.function.Supplier;
import org.heigit.bigspatialdata.oshdb.osh.OSHEntity;
import org.heigit.bigspatialdata.oshdb.osm.OSMEntity;
import org.locationtech.jts.geom.Geometry;
......@@ -23,8 +24,9 @@ public class OrOperator extends BinaryOperator {
}
@Override
public boolean applyOSMGeometry(OSMEntity entity, Geometry geometry) {
return op1.applyOSMGeometry(entity, geometry) || op2.applyOSMGeometry(entity, geometry);
public boolean applyOSMGeometry(OSMEntity entity, Supplier<Geometry> geometrySupplier) {
return op1.applyOSMGeometry(entity, geometrySupplier)
|| op2.applyOSMGeometry(entity, geometrySupplier);
}
@Override
......
......@@ -11,6 +11,7 @@ import org.heigit.bigspatialdata.oshdb.osm.OSMType;
import org.heigit.bigspatialdata.oshdb.util.OSHDBTag;
import org.heigit.bigspatialdata.oshdb.util.tagtranslator.OSMTag;
import org.heigit.bigspatialdata.oshdb.util.tagtranslator.OSMTagKey;
import org.heigit.ohsome.filter.GeometryFilter.ValueRange;
import org.heigit.ohsome.filter.GeometryTypeFilter.GeometryType;
import org.junit.Test;
import org.locationtech.jts.geom.GeometryFactory;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment