citygml4j / citygml-tools

Collection of tools for processing CityGML files
Apache License 2.0
115 stars 18 forks source link

Conversion to CityJSON fails (NullPointerException) #20

Closed Rufmord closed 3 years ago

Rufmord commented 3 years ago

Summary

Converting a CityGML to CityJSON throws a NullPointerException if streets overlap.

Explanation

I converted the OpenDrive file shown here with rtron into a CityGML without failures. Now I wanted to convert the CityGML into a CityJSON. But there the conversion fails and I get the error described down below. I validated the gml file with the validator (it is valid). I found out with this validator that there are issues. Validation direct link. So I think the failure is the overlapping of the streets, because other files without overlapping are converted properly.

Error

On file data.gml: data.zip

$ ./citygml-tools to-cityjson ../files/save.gml 
[17:33:26 INFO] Starting citygml-tools.
[17:33:26 INFO] Initializing application environment.
[17:33:26 INFO] Executing command 'to-cityjson'.
[17:33:26 INFO] Found 1 file(s) at '../files/save.gml'.
[17:33:26 INFO] [1|1] Processing file '/home/tux/Code/cgbackend/src/converter/cityJSON/citygml-tools-1.4.2/../files/save.gml'.
[17:33:26 INFO] Writing output to file '/home/tux/Code/cgbackend/src/converter/cityJSON/citygml-tools-1.4.2/../files/save.json'.
[17:33:49 ERROR] The following unexpected error occurred during execution.
picocli.CommandLine$ExecutionException: Error while calling command (org.citygml4j.tools.command.ToCityJSONCommand@23e028a9): java.lang.NullPointerException
        at picocli.CommandLine.executeUserObject(CommandLine.java:1942)
        at picocli.CommandLine.access$1200(CommandLine.java:145)
        at picocli.CommandLine$RunAll.recursivelyExecuteUserObject(CommandLine.java:2402)
        at picocli.CommandLine$RunAll.recursivelyExecuteUserObject(CommandLine.java:2404)
        at picocli.CommandLine$RunAll.handle(CommandLine.java:2399)
        at picocli.CommandLine$RunAll.handle(CommandLine.java:2363)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2159)
        at org.citygml4j.tools.CityGMLTools.process(CityGMLTools.java:131)
        at org.citygml4j.tools.CityGMLTools.main(CityGMLTools.java:87)
Caused by: java.lang.NullPointerException
        at org.citygml4j.builder.cityjson.marshal.citygml.core.CoreMarshaller.marshalImplicitGeometry(CoreMarshaller.java:177)
        at org.citygml4j.builder.cityjson.marshal.citygml.core.CoreMarshaller.marshalImplicitRepresentationProperty(CoreMarshaller.java:235)
        at org.citygml4j.builder.cityjson.marshal.citygml.cityfurniture.CityFurnitureMarshaller.marshalCityFurniture(CityFurnitureMarshaller.java:108)
        at org.citygml4j.builder.cityjson.marshal.citygml.cityfurniture.CityFurnitureMarshaller.marshalCityFurniture(CityFurnitureMarshaller.java:122)
        at org.citygml4j.builder.cityjson.marshal.citygml.cityfurniture.CityFurnitureMarshaller.marshal(CityFurnitureMarshaller.java:44)
        at org.citygml4j.builder.cityjson.marshal.citygml.CityGMLMarshaller.marshal(CityGMLMarshaller.java:99)
        at org.citygml4j.builder.cityjson.marshal.gml.GMLMarshaller.marshalFeatureProperty(GMLMarshaller.java:146)
        at org.citygml4j.builder.cityjson.marshal.citygml.core.CoreMarshaller.marshalCityModel(CoreMarshaller.java:131)
        at org.citygml4j.builder.cityjson.marshal.citygml.core.CoreMarshaller.marshal(CoreMarshaller.java:84)
        at org.citygml4j.builder.cityjson.marshal.citygml.CityGMLMarshaller.marshal(CityGMLMarshaller.java:117)
        at org.citygml4j.builder.cityjson.marshal.CityJSONMarshaller.marshal(CityJSONMarshaller.java:98)
        at org.citygml4j.builder.cityjson.json.io.writer.CityJSONWriter.write(CityJSONWriter.java:45)
        at org.citygml4j.tools.command.ToCityJSONCommand.call(ToCityJSONCommand.java:134)
        at org.citygml4j.tools.command.ToCityJSONCommand.call(ToCityJSONCommand.java:50)
        at picocli.CommandLine.executeUserObject(CommandLine.java:1933)
        ... 8 more
[17:33:49 WARN] citygml-tools execution failed.
clausnagel commented 3 years ago

Thanks for sharing the test dataset. The NPEs are caused by the ImplicitGeometry elements of your city furniture objects. They contain a transformationMatrix and a referencePoint but lack the most important part: the geometry. In CityGML, the geometry of an ImplicitGeometry can either be provided by an external model in an external file (using the libraryObject property) or inline as GML geometry through the relativeGMLGeometry property. But there is no geometry in your data.

I will fix the NPE. But this will not solve the issue. In CityJSON, you also have to specify the template geometries using the "geometry-templates" property. So, after fixing the NPE, your city furniture objects will be mapped to CityJSON, but they will also lack a geometry, and even the transformationMatrix and referencePoint will get lost in the conversion without a geometry.

I will let you know once the fix is available. But my recommendation is that you fix your data as well.

clausnagel commented 3 years ago

I fixed the NPE with https://github.com/citygml4j/citygml4j/commit/d852d948f5c7c6395f935d4c6d288601916d8f68.

The master branch of citygml-tools already contains the fix. So, you can build a new version from master following this guide. Or use the latest Docker image from https://hub.docker.com/r/citygml4j/citygml-tools/. The fix will be also contained in the next release.