unable to set a geometry via wfs-ng to null or empty
Description
I want to remove the geometry from a WFS dataset. In SQL terms something like “update set geom = null where …”.
What is the right way to do this over WFS? Do I miss something? I do not want to remove the data row.
Writing features using something like
featureStore.modifyFeatures(
featureStore.getSchema().getGeometryDescriptor().getLocalName(),
null or GF.createPoint(), <----------
featureId);
works fine as far as the geometry is not empty and not null.
Setting geometry to null I get this client exception:
java.lang.RuntimeException: Error encoding object to xml-element
at org.geotools.xsd.Encoder.processChildren(Encoder.java:1028)
at org.geotools.xsd.Encoder.encode(Encoder.java:655)
at org.geotools.xsd.Encoder.encode(Encoder.java:553)
at org.geotools.data.wfs.internal.AbstractWFSStrategy.getPostContents(AbstractWFSStrategy.java:879)
at org.geotools.data.wfs.internal.WFSRequest.performPostOutput(WFSRequest.java:178)
at org.geotools.data.ows.AbstractOpenWebService.internalIssueRequest(AbstractOpenWebService.java:449)
at org.geotools.data.wfs.internal.WFSClient.internalIssueRequest(WFSClient.java:335)
at org.geotools.data.wfs.internal.WFSClient.issueTransaction(WFSClient.java:367)
at org.geotools.data.wfs.WFSRemoteTransactionState.commitInternal(WFSRemoteTransactionState.java:119)
at org.geotools.data.wfs.WFSRemoteTransactionState.commit(WFSRemoteTransactionState.java:89)
at org.geotools.data.DefaultTransaction.commit(DefaultTransaction.java:172)
...
Caused by: java.lang.NullPointerException: Cannot invoke "Object.toString()" because "value" is null
at org.geotools.wfs.bindings.PropertyTypeBinding.lambda$getProperty$0(PropertyTypeBinding.java:114)
at org.geotools.xsd.Encoder.processChildren(Encoder.java:1026)
... 18 more
@Override
public Object getProperty(final Object object, QName name) throws Exception {
if (VALUE.equals(name.getLocalPart())) {
return (EncoderDelegate) output -> {
Object value = ((PropertyType) object).getValue();
output.startElement(WFS.NAMESPACE, VALUE, "wfs:" + VALUE, new AttributesImpl());
if (value instanceof Geometry) {
Encoder encoder = new Encoder(new GMLConfiguration());
encoder.setInline(true);
encoder.encode(value, GML._Geometry, output);
} else {
String s = value.toString();
output.characters(s.toCharArray(), 0, s.length());
}
output.endElement(WFS.NAMESPACE, VALUE, "wfs:" + VALUE);
};
}
return super.getProperty(object, name);
}
Since geom is null, value instanceof Geometry is false and GeoTools try to execute:
String s = value.toString();
Setting the geometry to an empty linestring (e.g. WKT: LINESTRING EMPTY) I get this server exception:
java.lang.RuntimeException: Parsing failed for Point: java.lang.RuntimeException: Could not find a coordinate
at deployment.geoserver.war//org.geotools.xsd.impl.ParseExecutor.visit(ParseExecutor.java:153)
at deployment.geoserver.war//org.geotools.xsd.impl.BindingWalker$BindingExecutionChain.execute(BindingWalker.java:218)
at deployment.geoserver.war//org.geotools.xsd.impl.BindingWalker.walk(BindingWalker.java:184)
at deployment.geoserver.war//org.geotools.xsd.impl.ElementHandlerImpl.endElement(ElementHandlerImpl.java:233)
at deployment.geoserver.war//org.geotools.xsd.impl.ParserHandler.endElement(ParserHandler.java:798)
at org.apache.xerces@2.12.0.SP03//org.apache.xerces.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:598)
at org.apache.xerces@2.12.0.SP03//org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:181)
at org.apache.xerces@2.12.0.SP03//org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:275)
at org.apache.xerces@2.12.0.SP03//org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1653)
at org.apache.xerces@2.12.0.SP03//org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:324)
at org.apache.xerces@2.12.0.SP03//org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:875)
at org.apache.xerces@2.12.0.SP03//org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:798)
at org.apache.xerces@2.12.0.SP03//org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:108)
at org.apache.xerces@2.12.0.SP03//org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1198)
at org.apache.xerces@2.12.0.SP03//org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:564)
at org.apache.xerces@2.12.0.SP03//org.apache.xerces.jaxp.SAXParserImpl.parse(SAXParserImpl.java:298)
at deployment.geoserver.war//org.geotools.xsd.Parser.parse(Parser.java:183)
at deployment.geoserver.war//org.geotools.xsd.Parser.parse(Parser.java:138)
at deployment.geoserver.war//org.geoserver.wfs.xml.v1_0_0.WfsXmlReader.read(WfsXmlReader.java:77)
...
Caused by: java.lang.RuntimeException: Could not find a coordinate
at deployment.geoserver.war//org.geotools.gml2.bindings.GMLPointTypeBinding.parse(GMLPointTypeBinding.java:109)
at deployment.geoserver.war//org.geotools.xsd.impl.ParseExecutor.visit(ParseExecutor.java:144)
Environment
GeoTools 32.1
GeoServer 2.26.1
Activity
Show:
Tobias Warneke March 25, 2025 at 9:45 AM
Update: Using an emtpy String I was able to null the geometry.
I want to remove the geometry from a WFS dataset. In SQL terms something like “update set geom = null where …”.
What is the right way to do this over WFS? Do I miss something? I do not want to remove the data row.
Writing features using something like
featureStore.modifyFeatures( featureStore.getSchema().getGeometryDescriptor().getLocalName(), null or GF.createPoint(), <---------- featureId);
works fine as far as the geometry is not empty and not null.
Setting geometry to null I get this client exception:
java.lang.RuntimeException: Error encoding object to xml-element at org.geotools.xsd.Encoder.processChildren(Encoder.java:1028) at org.geotools.xsd.Encoder.encode(Encoder.java:655) at org.geotools.xsd.Encoder.encode(Encoder.java:553) at org.geotools.data.wfs.internal.AbstractWFSStrategy.getPostContents(AbstractWFSStrategy.java:879) at org.geotools.data.wfs.internal.WFSRequest.performPostOutput(WFSRequest.java:178) at org.geotools.data.ows.AbstractOpenWebService.internalIssueRequest(AbstractOpenWebService.java:449) at org.geotools.data.wfs.internal.WFSClient.internalIssueRequest(WFSClient.java:335) at org.geotools.data.wfs.internal.WFSClient.issueTransaction(WFSClient.java:367) at org.geotools.data.wfs.WFSRemoteTransactionState.commitInternal(WFSRemoteTransactionState.java:119) at org.geotools.data.wfs.WFSRemoteTransactionState.commit(WFSRemoteTransactionState.java:89) at org.geotools.data.DefaultTransaction.commit(DefaultTransaction.java:172) ... Caused by: java.lang.NullPointerException: Cannot invoke "Object.toString()" because "value" is null at org.geotools.wfs.bindings.PropertyTypeBinding.lambda$getProperty$0(PropertyTypeBinding.java:114) at org.geotools.xsd.Encoder.processChildren(Encoder.java:1026) ... 18 more
This is simply due to (https://github.com/geotools/geotools/blob/32.x/modules/extension/xsd/xsd-wfs/src/main/java/org/geotools/wfs/bindings/PropertyTypeBinding.java)
@Override public Object getProperty(final Object object, QName name) throws Exception { if (VALUE.equals(name.getLocalPart())) { return (EncoderDelegate) output -> { Object value = ((PropertyType) object).getValue(); output.startElement(WFS.NAMESPACE, VALUE, "wfs:" + VALUE, new AttributesImpl()); if (value instanceof Geometry) { Encoder encoder = new Encoder(new GMLConfiguration()); encoder.setInline(true); encoder.encode(value, GML._Geometry, output); } else { String s = value.toString(); output.characters(s.toCharArray(), 0, s.length()); } output.endElement(WFS.NAMESPACE, VALUE, "wfs:" + VALUE); }; } return super.getProperty(object, name); }
Since geom is null, value instanceof Geometry is false and GeoTools try to execute:
String s = value.toString();
Setting the geometry to an empty linestring (e.g. WKT: LINESTRING EMPTY) I get this server exception:
java.lang.RuntimeException: Parsing failed for Point: java.lang.RuntimeException: Could not find a coordinate at deployment.geoserver.war//org.geotools.xsd.impl.ParseExecutor.visit(ParseExecutor.java:153) at deployment.geoserver.war//org.geotools.xsd.impl.BindingWalker$BindingExecutionChain.execute(BindingWalker.java:218) at deployment.geoserver.war//org.geotools.xsd.impl.BindingWalker.walk(BindingWalker.java:184) at deployment.geoserver.war//org.geotools.xsd.impl.ElementHandlerImpl.endElement(ElementHandlerImpl.java:233) at deployment.geoserver.war//org.geotools.xsd.impl.ParserHandler.endElement(ParserHandler.java:798) at org.apache.xerces@2.12.0.SP03//org.apache.xerces.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:598) at org.apache.xerces@2.12.0.SP03//org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:181) at org.apache.xerces@2.12.0.SP03//org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:275) at org.apache.xerces@2.12.0.SP03//org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1653) at org.apache.xerces@2.12.0.SP03//org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:324) at org.apache.xerces@2.12.0.SP03//org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:875) at org.apache.xerces@2.12.0.SP03//org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:798) at org.apache.xerces@2.12.0.SP03//org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:108) at org.apache.xerces@2.12.0.SP03//org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1198) at org.apache.xerces@2.12.0.SP03//org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:564) at org.apache.xerces@2.12.0.SP03//org.apache.xerces.jaxp.SAXParserImpl.parse(SAXParserImpl.java:298) at deployment.geoserver.war//org.geotools.xsd.Parser.parse(Parser.java:183) at deployment.geoserver.war//org.geotools.xsd.Parser.parse(Parser.java:138) at deployment.geoserver.war//org.geoserver.wfs.xml.v1_0_0.WfsXmlReader.read(WfsXmlReader.java:77) ... Caused by: java.lang.RuntimeException: Could not find a coordinate at deployment.geoserver.war//org.geotools.gml2.bindings.GMLPointTypeBinding.parse(GMLPointTypeBinding.java:109) at deployment.geoserver.war//org.geotools.xsd.impl.ParseExecutor.visit(ParseExecutor.java:144)