Verified Commit 933b631c authored by Martin Raifer's avatar Martin Raifer
Browse files

allow to filter by tags

uses the filtering (parser) library developed for the ohsome-api.

closes #1
parent e0208155
......@@ -23,6 +23,13 @@
<type>jar</type>
</dependency>
<dependency>
<groupId>org.heigit.ohsome</groupId>
<artifactId>ohsome-filter</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
......@@ -52,6 +59,15 @@
<name>Heigit/GIScience repository (releases)</name>
<url>http://repo.heigit.org/artifactory/libs-release-local</url>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>oshdb-snapshopts</id>
<name>Heigit/GIScience repository (snapshots)</name>
<url>http://repo.heigit.org/artifactory/libs-snapshot-local</url>
</repository>
</repositories>
<build>
......
......@@ -55,6 +55,8 @@ import org.heigit.bigspatialdata.oshdb.util.OSHDBTagKey;
import org.heigit.bigspatialdata.oshdb.util.TableNames;
import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder;
import org.heigit.bigspatialdata.oshdb.util.tagtranslator.TagTranslator;
import org.heigit.ohsome.filter.FilterExpression;
import org.heigit.ohsome.filter.FilterParser;
import org.locationtech.jts.geom.Geometry;
import org.wololo.jts2geojson.GeoJSONReader;
import org.wololo.jts2geojson.GeoJSONWriter;
......@@ -129,6 +131,7 @@ public class CreateH2Extract {
Set<OSHDBTag> tags = new HashSet<>();
Set<OSHDBRole> roles = new HashSet<>();
TagTranslator tt = new TagTranslator(keytables.getConnection());
FilterExpression filter = (new FilterParser(tt)).parse(cmdArgs.filter != null ? cmdArgs.filter : "type:node or type:way or type:relation");
ScanQuery<Long, GridOSHEntity> scanQuery = new ScanQuery<>((key, cell) -> {
CellId cellId = CellId.fromLevelId(key);
......@@ -159,6 +162,7 @@ public class CreateH2Extract {
StreamSupport.stream(gridEntry.getEntities().spliterator(), false)
.map(x -> (OSHNode) x)
.filter(osh -> osh.getBoundingBox().intersects(bbox))
.filter(filter::applyOSH)
.collect(Collectors.toList())
);
} catch (IOException e) {
......@@ -187,6 +191,7 @@ public class CreateH2Extract {
StreamSupport.stream(gridEntry.getEntities().spliterator(), false)
.map(x -> (OSHWay) x)
.filter(osh -> osh.getBoundingBox().intersects(bbox))
.filter(filter::applyOSH)
.collect(Collectors.toList())
);
} catch (IOException e) {
......@@ -217,6 +222,7 @@ public class CreateH2Extract {
StreamSupport.stream(gridEntry.getEntities().spliterator(), false)
.map(x -> (OSHRelation) x)
.filter(osh -> osh.getBoundingBox().intersects(bbox))
.filter(filter::applyOSH)
.filter(oshRel -> !cmdArgs.skipLargeRelations ||
StreamSupport.stream(oshRel.getVersions().spliterator(), false)
.flatMap(osmrel -> Arrays.stream(osmrel.getMembers()))
......@@ -347,7 +353,10 @@ public class CreateH2Extract {
@Parameter(names = {"-b", "--bbox"}, description = "bounding box to cut out; list of 4 coordinate endpoints: min-lon, min-lat, max-lon, max-lat", required = true, order = 3)
public String bbox;
@Parameter(names = {"-o", "--output"}, description = "Path to output H2 file", required = true, order = 4)
@Parameter(names = {"-f", "--filter"}, description = "filter to check against every osh entity", required = false, order = 4)
public String filter;
@Parameter(names = {"-o", "--output"}, description = "Path to output H2 file", required = true, order = 5)
public File outputH2;
//@Parameter(names = {"--output-prefix"}, description = "output table prefix", required = false)
......
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