diff --git a/contribs/application/src/main/java/org/matsim/application/options/LanduseOptions.java b/contribs/application/src/main/java/org/matsim/application/options/LanduseOptions.java index f1afcf2b63e..a4623c14237 100644 --- a/contribs/application/src/main/java/org/matsim/application/options/LanduseOptions.java +++ b/contribs/application/src/main/java/org/matsim/application/options/LanduseOptions.java @@ -8,6 +8,7 @@ import javax.annotation.Nullable; import java.nio.charset.StandardCharsets; import java.nio.file.Path; +import java.util.Objects; import java.util.Set; import java.util.function.Supplier; @@ -49,7 +50,7 @@ public synchronized ShpOptions.Index getIndex(String queryCRS) { ShpOptions landShp = new ShpOptions(landuse, null, StandardCharsets.UTF_8); - index = landShp.createIndex(queryCRS, attr, filter); + index = landShp.createIndex(queryCRS, attr, ft-> filter == null || filter.contains(Objects.toString(ft.getAttribute(attr)))); log.info("Read {} features for landuse", index.size()); diff --git a/contribs/application/src/main/java/org/matsim/application/options/ShpOptions.java b/contribs/application/src/main/java/org/matsim/application/options/ShpOptions.java index ab40fd1f3c8..79069264296 100644 --- a/contribs/application/src/main/java/org/matsim/application/options/ShpOptions.java +++ b/contribs/application/src/main/java/org/matsim/application/options/ShpOptions.java @@ -38,6 +38,7 @@ import java.util.Collection; import java.util.List; import java.util.Set; +import java.util.function.Predicate; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -203,7 +204,7 @@ public Geometry getGeometry() { * @param attr the attribute to query from the shape file * @param filter filter features by attribute values */ - public Index createIndex(String queryCRS, String attr, Set filter) { + public Index createIndex(String queryCRS, String attr, Predicate filter) { if (!isDefined()) throw new IllegalStateException("Shape file path not specified"); @@ -308,7 +309,7 @@ public final class Index { * @param ct coordinate transform from query to target crs * @param attr attribute for the result of {@link #query(Coord)} */ - Index(CoordinateTransformation ct, ShapefileDataStore ds, String attr, @Nullable Set filter) throws IOException { + Index(CoordinateTransformation ct, ShapefileDataStore ds, String attr, @Nullable Predicate filter) throws IOException { if (shpCharset != null) ds.setCharset(shpCharset); @@ -321,7 +322,7 @@ public final class Index { continue; } - if (filter != null && !filter.contains(ft.getAttribute(attr))) + if (filter != null && !filter.test(ft)) continue; Geometry geom = (Geometry) ft.getDefaultGeometry(); diff --git a/contribs/application/src/main/java/org/matsim/application/prepare/freight/tripGeneration/DefaultLocationCalculator.java b/contribs/application/src/main/java/org/matsim/application/prepare/freight/tripGeneration/DefaultLocationCalculator.java index 81d4782f2a6..2cffcf00170 100644 --- a/contribs/application/src/main/java/org/matsim/application/prepare/freight/tripGeneration/DefaultLocationCalculator.java +++ b/contribs/application/src/main/java/org/matsim/application/prepare/freight/tripGeneration/DefaultLocationCalculator.java @@ -56,7 +56,10 @@ private void prepareMapping() throws IOException { } } } - ShpOptions.Index index = shp.createIndex("EPSG:25832", "NUTS_ID", relevantNutsIds); // network CRS: EPSG:25832 + + // network CRS: EPSG:25832 + ShpOptions.Index index = shp.createIndex("EPSG:25832", "NUTS_ID", + ft -> relevantNutsIds.contains(Objects.toString(ft.getAttribute("NUTS_ID")))); logger.info("Reading land use data..."); ShpOptions.Index landIndex = landUse.getIndex("EPSG:25832"); //TODO