Skip to content

Commit 0b85308

Browse files
committed
Clean WFS and vector encoders
1 parent 93434f2 commit 0b85308

File tree

2 files changed

+23
-29
lines changed

2 files changed

+23
-29
lines changed

adapters/klab.ogc/src/main/java/org/integratedmodelling/klab/ogc/vector/files/VectorEncoder.java

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ public void encodeFromFeatures(FeatureSource<SimpleFeatureType, SimpleFeature> s
163163
this.intersect = urnParameters.containsKey("intersect") ? Boolean.parseBoolean(urnParameters.get("intersect")) : true;
164164
this.presence = urnParameters.containsKey("presence") ? Boolean.parseBoolean(urnParameters.get("presence")) : false;
165165

166+
/*
167+
* TODO would be nicer to check the request geometry for the data - which may not be the
168+
* scale of the result! If it's IRREGULAR MULTIPLE we want objects, otherwise we want a
169+
* state. I don't think there is a way to check that at the moment - the scale will be that
170+
* of contextualization, not the geometry for the actuator, which may depend on context.
171+
*/
172+
this.rasterize = (idRequested != null || (scope.getTargetSemantics() != null
173+
&& (scope.getTargetSemantics().is(Type.QUALITY) || scope.getTargetSemantics().is(Type.TRAIT))))
174+
&& requestScale.getSpace() instanceof Space && ((Space) requestScale.getSpace()).getGrid() != null;
175+
166176
filter = readAttributeData(source, urnParameters, filter, geomName);
167177

168178
/*
@@ -177,7 +187,7 @@ public void encodeFromFeatures(FeatureSource<SimpleFeatureType, SimpleFeature> s
177187
throw new KlabValidationException(e);
178188
}
179189
}
180-
190+
181191
/*
182192
* filters set into the resource parameters
183193
*/
@@ -240,26 +250,10 @@ private Filter readAttributeData(FeatureSource<SimpleFeatureType, SimpleFeature>
240250
}
241251
return filter;
242252
}
243-
//, , IContextualizationScope scope
244-
protected void parseFeatures(FeatureIterator<SimpleFeature> it, IResource resource, Map<String, String> urnParameters, IGeometry geometry, Builder builder, IContextualizationScope scope, ReferencedEnvelope bboxRefEnv
245-
// ,
246-
// String idRequested, Map<String, Class< ? >> attributes,
247-
// Map<String, String> attributeNames, FeatureCollection<SimpleFeatureType, SimpleFeature> fc,
248-
// Projection originalProjection, Rasterizer<Object> rasterizer, double cellWidth, Polygon polygonEnv,
249-
// String nameAttribute
250-
) {
251-
252-
Scale requestScale = geometry instanceof Scale ? (Scale) geometry : Scale.create(geometry);
253-
/*
254-
* TODO would be nicer to check the request geometry for the data - which may not be the
255-
* scale of the result! If it's IRREGULAR MULTIPLE we want objects, otherwise we want a
256-
* state. I don't think there is a way to check that at the moment - the scale will be that
257-
* of contextualization, not the geometry for the actuator, which may depend on context.
258-
*/
259-
boolean rasterize = (idRequested != null || (scope.getTargetSemantics() != null
260-
&& (scope.getTargetSemantics().is(Type.QUALITY) || scope.getTargetSemantics().is(Type.TRAIT))))
261-
&& requestScale.getSpace() instanceof Space && ((Space) requestScale.getSpace()).getGrid() != null;
262253

254+
protected void parseFeatures(FeatureIterator<SimpleFeature> it, IResource resource, Map<String, String> urnParameters,
255+
IGeometry geometry, Builder builder, IContextualizationScope scope, ReferencedEnvelope bboxRefEnv) {
256+
Scale requestScale = geometry instanceof Scale ? (Scale) geometry : Scale.create(geometry);
263257
Rasterizer<Object> rasterizer = null;
264258
double cellWidth = -1.0;
265259

@@ -291,7 +285,6 @@ protected void parseFeatures(FeatureIterator<SimpleFeature> it, IResource resour
291285

292286
SimpleFeature feature = it.next();
293287
Geometry shape = (Geometry) feature.getDefaultGeometry();
294-
295288
if (shape.isEmpty()) {
296289
continue;
297290
}
@@ -308,7 +301,7 @@ protected void parseFeatures(FeatureIterator<SimpleFeature> it, IResource resour
308301
}
309302

310303
IShape objectShape = null;
311-
if(rasterize) {
304+
if (rasterize) {
312305
// do always intersect
313306
try {
314307
Geometry intersection = GeometryHelper.multiPolygonIntersection(polygonEnv, shape, cellWidth);
@@ -317,8 +310,8 @@ protected void parseFeatures(FeatureIterator<SimpleFeature> it, IResource resour
317310
} catch (Exception e) {
318311
throw new KlabIOException(e);
319312
}
320-
321-
}else {
313+
314+
} else {
322315
objectShape = Shape.create(shape, originalProjection)
323316
.transform(requestScale.getSpace().getProjection());
324317

@@ -334,7 +327,6 @@ protected void parseFeatures(FeatureIterator<SimpleFeature> it, IResource resour
334327
}
335328

336329
if (rasterize) {
337-
338330
Object value = Boolean.TRUE;
339331

340332
if (idRequested != null) {
@@ -370,7 +362,7 @@ protected void parseFeatures(FeatureIterator<SimpleFeature> it, IResource resour
370362
}
371363

372364
builder = builder.startObject(scope.getTargetName(), objectName, objectScale);
373-
for(String key : attributes.keySet()) {
365+
for (String key : attributes.keySet()) {
374366
Object nattr = feature.getAttribute(key);
375367
if (nattr == null) {
376368
nattr = feature.getAttribute(key.toUpperCase());

adapters/klab.ogc/src/main/java/org/integratedmodelling/klab/ogc/vector/wfs/WfsEncoder.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public void getEncodedData(IResource resource, Map<String, String> urnParameters
6666
if (forceXYSwap) {
6767
wfs.forceCoordinateSwapping();
6868
}
69+
6970
try {
7071
wfs.connect();
71-
System.out.println("Version: " + wfs.getVersion());
7272

7373
Space space = (Space) geometry.getDimensions().stream().filter(d -> d instanceof Space).findFirst().orElseThrow();
7474
IEnvelope geomAsEnv = space.getEnvelope();
@@ -81,7 +81,8 @@ public void getEncodedData(IResource resource, Map<String, String> urnParameters
8181
crs = GeotoolsUtils.INSTANCE.checkCrs(crs);
8282
this.originalProjection = Projection.create(crs);
8383
IEnvelope envelopeInOriginalProjection = requestScale.getSpace().getEnvelope().transform(originalProjection, true);
84-
ReferencedEnvelope bboxRefEnv = ((org.integratedmodelling.klab.components.geospace.extents.Envelope) envelopeInOriginalProjection).getJTSEnvelope();
84+
ReferencedEnvelope bboxRefEnv = ((org.integratedmodelling.klab.components.geospace.extents.Envelope) envelopeInOriginalProjection)
85+
.getJTSEnvelope();
8586

8687
FeatureIterator<SimpleFeature> it = fc.features();
8788
this.intersect = urnParameters.containsKey("intersect") ? Boolean.parseBoolean(urnParameters.get("intersect")) : true;
@@ -98,7 +99,8 @@ public void getEncodedData(IResource resource, Map<String, String> urnParameters
9899
try {
99100
wfs.close();
100101
} catch (Exception e) {
101-
throw new KlabResourceAccessException("Error closing WFS resource of layer '" + layerName + "'. Reason: " + e.getMessage());
102+
throw new KlabResourceAccessException(
103+
"Error closing WFS resource of layer '" + layerName + "'. Reason: " + e.getMessage());
102104
}
103105
}
104106

0 commit comments

Comments
 (0)