Skip to content

Commit

Permalink
[GEOS-9791] GeoJSON bounding box axis order wrongly encoded when CRS …
Browse files Browse the repository at this point in the history
…axis order is NORTH-EAST
  • Loading branch information
taba90 authored and aaime committed Nov 23, 2020
1 parent 8efbfc7 commit 2bf15c8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.feature.type.FeatureType;
import org.opengis.feature.type.GeometryDescriptor;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.ReferenceIdentifier;
Expand Down Expand Up @@ -250,9 +251,13 @@ protected void writeCollectionBounds(
boolean hasGeom) {
// Bounding box for featurecollection
if (hasGeom && featureBounding) {
CoordinateReferenceSystem crs = null;
ReferencedEnvelope e = null;
for (int i = 0; i < resultsList.size(); i++) {
FeatureCollection collection = resultsList.get(i);
FeatureType schema = collection.getSchema();
if (crs == null && schema.getGeometryDescriptor() != null)
crs = schema.getGeometryDescriptor().getCoordinateReferenceSystem();
if (e == null) {
e = collection.getBounds();
} else {
Expand All @@ -261,7 +266,7 @@ protected void writeCollectionBounds(
}

if (e != null) {
jsonWriter.setAxisOrder(CRS.getAxisOrder(e.getCoordinateReferenceSystem()));
jsonWriter.setAxisOrder(CRS.getAxisOrder(crs));
jsonWriter.writeBoundingBox(e);
}
}
Expand Down
30 changes: 30 additions & 0 deletions src/wfs/src/test/java/org/geoserver/wfs/json/GeoJSONTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,36 @@ public void testNanInfinite() throws Exception {
assertEquals("Infinity", getProperty(f3, "f"));
}

@Test
public void testBoundingBoxAxisOrderInWfs10AndWfs11() throws Exception {
// test that AxisOrder of bbox coordinates are switched to EAST-NORTH,
// as for the other coordinates array in the json features, when the CRS
// has NORTH-EAST axis order
JSONObject rootObject =
(JSONObject)
getAsJSON(
"wfs?request=GetFeature&version=1.0.0&typename="
+ getLayerId(POINT_LATLON)
+ "&outputformat="
+ JSONType.json);

JSONArray bbox = rootObject.getJSONArray("bbox");

JSONObject rootObjectRep =
(JSONObject)
getAsJSON(
"wfs?request=GetFeature&version=1.1.0&typename="
+ getLayerId(POINT_LATLON)
+ "&outputformat="
+ JSONType.json
+ "&srsName=urn:x-ogc:def:crs:EPSG:4326");

JSONArray bboxRep = rootObjectRep.getJSONArray("bbox");
// bbox should be equal since the NORTH-EAST axis order in the wfs 1.1.0
// should have been ignored and kept to EAST-NORTH
assertTrue(bboxRep.equals(bbox));
}

private Object getProperty(JSONObject feature, String propertyName) {
return feature.getJSONObject("properties").get(propertyName);
}
Expand Down

0 comments on commit 2bf15c8

Please sign in to comment.