0

I'm trying to convert a GeoJSON file to GML 3.1.1 using an old org.geotools lib. geotools lib are 2.7.0 version. Sadly, upgrading is not an option. Here is the relevant part of my code:

FeatureCollection geoJsonDocument = featureJSON.readFeatureCollection(myGeoJsonInputStream));
...
Configuration config = new org.geotools.gml3.GMLConfiguration();    
Encoder encoder = new Encoder(config);
encoder.getNamespaces().declarePrefix("myorgns", "http://myorg.org");
encoder.setEncoding(StandardCharsets.US_ASCII);
encoder.encode(geoJsonDocument, new QName("http://www.opengis.net/gml", "FeatureCollection"), out);

If I print the content of out variable I find that GeoJSON elements in GML all have "null" prefix. Here is a snippet of the content:

<gml:FeatureCollection xmlns:sch="http://www.ascc.net/xml/schematron" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:myorgns="http://myorg.org">
<gml:featureMembers>
    <null:feature gml:id="feature-0">
        <gml:boundedBy>
            <gml:Envelope>
                <gml:lowerCorner>3.4686311 51.1304626</gml:lowerCorner>
                <gml:upperCorner>3.4686311 51.1304626</gml:upperCorner>
            </gml:Envelope>
        </gml:boundedBy>
        <null:pk_track>729</null:pk_track>
        <null:time_ISO8601>2017-01-10T05:13:06+01:00</null:time_ISO8601>
        <null:time_epoch>1484021586000</null:time_epoch>
...

When I try do encode the geoJsonDocument I got an exception because encoded element prefixes are "null":

Exception in thread "Thread-30" java.lang.RuntimeException: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 238; The prefix "null" for element "null:feature" is not bound.
at org.geotools.xml.StreamingParser$1.run(StreamingParser.java:248)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 238; The prefix "null" for element "null:feature" is not bound.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
at org.geotools.xml.StreamingParser$1.run(StreamingParser.java:244)
... 1 more

How can I solve this?

1

The only sensible path to fix this is to upgrade to a supported version of geotools.

Your alternative is to try to apply all the patches that have gone on to the gml writer in the last 10 versions.

  • Hello, thank for your answer. Sadly, upgrade geotools is not an option. What about patches? Can you point me to some .jar and docs? – Francesco Aug 10 '17 at 21:57
  • You would have to look through the github.com/geotools repo – Ian Turton Aug 10 '17 at 22:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.