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

Handle geometries containing GML patches #14

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/org/opengis/cite/geomatics/Extents.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.opengis.util.FactoryException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

Expand Down Expand Up @@ -152,6 +153,11 @@ public static Envelope calculateEnvelopeUsingSingleGeometry(NodeList geomNodes)
if (geom.getLocalName().equals("Curve") || geom.getLocalName().equals("Surface")) {
geom = GmlUtils.convertToMultiType(geomNodes.item(i));
}

Node geomNode = geomNodes.item(i);
if (GmlUtils.checkForAbstractSurfacePatchTypes(geomNode)) {
geom = GmlUtils.handleAbstractSurfacePatch(geomNode);
}
JAXBElement<AbstractGeometry> result = (JAXBElement<AbstractGeometry>) unmarshaller.unmarshal(geom);
AbstractGeometry gmlGeom = result.getValue();
String srsName = gmlGeom.getSrsName();
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/org/opengis/cite/geomatics/gml/GmlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,40 @@ public static TemporalGeometricPrimitive gmlToTemporalGeometricPrimitive(Element
*/
public static Element convertToMultiType(Node geomNode) {
String typeName = "Multi" + geomNode.getLocalName();
return convertGeomNode(typeName, geomNode);
}

/**
* Rewrites a geometry Node that contain AbstractSurfacePatch elements.
* See https://github.com/opengeospatial/ets-wfs20/issues/260
*
* @param geomNode a geometry Node containing AbstractSurfacePatch elements.
* @return The rewritten geometry Node.
*/
public static Element handleAbstractSurfacePatch(Node geomNode) {
String typeName = geomNode.getLocalName();
return convertGeomNode(typeName, geomNode);
}

/**
* Checks for <code>AbstractSurfacePatchTypes</code> in geometry nodes
*
* @param node The geometry node
* @return true, if the geometry node contains a <code>AbstractSurfacePatchTypes</code>, otherwise false
*/
public static boolean checkForAbstractSurfacePatchTypes(Node node) {
boolean result = false;
if (node.getLocalName().contains("Multi")) {
NodeList childNodes = node.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node childNode = childNodes.item(i);
result = result || checkForAbstractSurfacePatchTypesRecursively(childNode);
}
}
return result;
}

private static Element convertGeomNode(String typeName, Node geomNode) {
String geomMemberType = geomNode.getLocalName().equalsIgnoreCase("Curve") ? "curveMember" : "surfaceMember";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
Expand Down Expand Up @@ -591,4 +625,23 @@ public static Element convertToMultiType(Node geomNode) {
multiGeom.appendChild(memberType);
return multiGeom;
}

private static boolean checkForAbstractSurfacePatchTypesRecursively(Node node) {
boolean result = false;
if (node.getNodeType() == Node.TEXT_NODE) {
return false;
}
if (node.getLocalName().contains("patch")) {
return true;
}
if (!node.hasChildNodes()) {
return false;
}
NodeList childNodes = node.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node childNode = childNodes.item(i);
result = result || checkForAbstractSurfacePatchTypesRecursively(childNode);
}
return result;
}
}