Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OAPIF Core filtering capabilities to OskariWFS3Client #816

Merged
merged 11 commits into from
Mar 21, 2022
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package org.oskari.geojson;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.store.EmptyFeatureCollection;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.geometry.jts.JTS;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.filter.Filter;
import org.opengis.geometry.MismatchedDimensionException;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;
Expand Down Expand Up @@ -49,22 +50,37 @@ public static SimpleFeatureCollection toFeatureCollection(Map<String, Object> js
public static SimpleFeatureCollection toFeatureCollection(Map<String, Object> json,
SimpleFeatureType schema, MathTransform transform)
throws MismatchedDimensionException, TransformException {
return toFeatureCollection(json, schema, null, Filter.INCLUDE);
}

public static SimpleFeatureCollection toFeatureCollection(
Map<String, Object> json,
SimpleFeatureType schema,
MathTransform transform,
Filter filter) throws MismatchedDimensionException, TransformException {
if (filter == null) {
filter = Filter.INCLUDE;
}

String type = GeoJSONUtil.getString(json, GeoJSON.TYPE);
if (!GeoJSON.FEATURE_COLLECTION.equals(type)) {
throw new IllegalArgumentException("type was not " + GeoJSON.FEATURE_COLLECTION);
}

List<Object> features = GeoJSONUtil.getList(json, GeoJSON.FEATURES);
if (features.isEmpty()) {
return new GeoJSONFeatureCollection(Collections.emptyList(), null);
return new EmptyFeatureCollection(schema);
}

SimpleFeatureBuilder builder = new SimpleFeatureBuilder(schema);
List<SimpleFeature> fc = new ArrayList<>();
for (Object f : features) {
@SuppressWarnings("unchecked")
Map<String, Object> _f = (Map<String, Object>) f;
fc.add(toFeature(_f, builder, transform));
SimpleFeature feature = toFeature(_f, builder, transform);
if (filter.evaluate(feature)) {
fc.add(feature);
}
}

return new GeoJSONFeatureCollection(fc, schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

public class OskariWFSClient {

private static final Logger LOG = LogFactory.getLogger(OskariWFS110Client.class);
private static final Logger LOG = LogFactory.getLogger(OskariWFSClient.class);
private static final String EXC_HANDLING_OUTPUTFORMAT = "outputformat";
private static final TypeReference<HashMap<String, Object>> TYPE_REF = new TypeReference<HashMap<String, Object>>() {};
private static final ObjectMapper OM = new ObjectMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public OskariWFSLoadCommand(OskariLayer layer, ReferencedEnvelope bbox,
protected SimpleFeatureCollection run() throws Exception {
switch (layer.getVersion()) {
case WFS_3_VERSION:
return OskariWFS3Client.getFeatures(layer, bbox, crs);
return OskariWFS3Client.getFeatures(layer, bbox, crs, filter);
case WFS_2_VERSION:
return OskariWFS2Client.getFeatures(layer, bbox, crs, filter);
default:
Expand Down
Loading