Skip to content

Commit

Permalink
more flexible filter for shp option index (#3186)
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow authored Mar 26, 2024
1 parent 00c5c30 commit 42e4d84
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String> filter) {
public Index createIndex(String queryCRS, String attr, Predicate<SimpleFeature> filter) {

if (!isDefined())
throw new IllegalStateException("Shape file path not specified");
Expand Down Expand Up @@ -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<String> filter) throws IOException {
Index(CoordinateTransformation ct, ShapefileDataStore ds, String attr, @Nullable Predicate<SimpleFeature> filter) throws IOException {
if (shpCharset != null)
ds.setCharset(shpCharset);

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 42e4d84

Please sign in to comment.