Skip to content

Commit e325e26

Browse files
committed
filter out the geometry attribute, unless it is a point, not needed for our demonstration and it could be overly verbose
1 parent 436c10e commit e325e26

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

src/main/java/nl/b3partners/entityresolverissues/WFSGetFeatureUtil.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
import java.io.IOException;
99
import java.lang.invoke.MethodHandles;
1010
import java.util.HashMap;
11+
import java.util.List;
1112
import java.util.Map;
1213
import org.geotools.api.data.DataStore;
1314
import org.geotools.api.data.DataStoreFinder;
1415
import org.geotools.api.data.Query;
1516
import org.geotools.api.feature.Property;
1617
import org.geotools.api.feature.simple.SimpleFeature;
18+
import org.geotools.api.feature.type.AttributeDescriptor;
1719
import org.geotools.api.feature.type.GeometryDescriptor;
20+
import org.geotools.api.feature.type.Name;
1821
import org.geotools.api.filter.Filter;
1922
import org.geotools.data.simple.SimpleFeatureIterator;
2023
import org.geotools.data.wfs.WFSDataStoreFactory;
@@ -70,24 +73,30 @@ public Map<String, String> getOneFeature(String typeName, String cqlFilter) thro
7073
GeometryDescriptor geomAttr = ds.getSchema(typeName).getGeometryDescriptor();
7174
logger.info("Geometry attribute for type {}: {}", typeName, geomAttr);
7275

76+
// filter out the geometry attribute, unless it is a point, not needed for our demonstration and it could be
77+
// overly verbose
78+
if (geomAttr != null && !(geomAttr.getType().getBinding() == org.locationtech.jts.geom.Point.class)) {
79+
List<String> attributeList = ds.getSchema(typeName).getAttributeDescriptors().stream()
80+
.map(AttributeDescriptor::getName)
81+
.filter(name -> !name.equals(geomAttr.getName()))
82+
.map(Name::getLocalPart)
83+
.toList();
84+
q.setPropertyNames(attributeList);
85+
}
86+
7387
try (SimpleFeatureIterator it =
7488
ds.getFeatureSource(typeName).getFeatures(q).features()) {
7589
if (it.hasNext()) {
7690
SimpleFeature feature = it.next();
77-
Map<String, String> attributes = new HashMap<>();
91+
Map<String, String> attributesMap = new HashMap<>();
7892
for (Property property : feature.getProperties()) {
79-
if (property.getDescriptor() == geomAttr) {
80-
// Skip/replace geometry attribute value, as it might be too verbose
81-
attributes.put(property.getName().toString(), "GEOMETRY (/* omitted */)");
82-
} else {
83-
attributes.put(
84-
property.getName().toString(),
85-
property.getValue() != null
86-
? property.getValue().toString()
87-
: null);
88-
}
93+
attributesMap.put(
94+
property.getName().toString(),
95+
property.getValue() != null
96+
? property.getValue().toString()
97+
: null);
8998
}
90-
return attributes;
99+
return attributesMap;
91100
}
92101
logger.info("No feature found for type {} and filter {}", typeName, cqlFilter);
93102
return null;

src/test/java/nl/b3partners/entityresolverissues/WFSGetFeatureControllerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void getProvincieFeature() throws Exception {
3232
.andExpect(status().isOk())
3333
.andExpect(jsonPath("$.naam").value("Gelderland"))
3434
.andExpect(jsonPath("$.code").value("25"))
35-
.andExpect(jsonPath("$.geom").value("GEOMETRY (/* omitted */)"));
35+
.andExpect(jsonPath("$.geom").doesNotExist());
3636
}
3737

3838
@Test
@@ -43,6 +43,6 @@ void getBakFeature() throws Exception {
4343
.andExpect(status().isOk())
4444
.andExpect(jsonPath("$.creationdate").isNotEmpty())
4545
.andExpect(jsonPath("$.terminationdate").isEmpty())
46-
.andExpect(jsonPath("$.geom").value("GEOMETRY (/* omitted */)"));
46+
.andExpect(jsonPath("$.geom").value("POINT (130887.591 459392.138)"));
4747
}
4848
}

src/test/java/nl/b3partners/entityresolverissues/WFSGetFeatureUtilTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ public void testWFSGetFeatureBak() throws CQLException, IOException {
4444
Map<String, String> feature = new WFSGetFeatureUtil(TM_WFS_URL).getOneFeature(TM_WFS_TYPE_NAME, null);
4545
assertNotNull(feature);
4646
logger.info(feature.toString());
47+
assertNotNull(feature.get("geom"));
4748
}
4849
}

0 commit comments

Comments
 (0)