citygml4j / citygml-tools

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

Y Coordinates differ when transforming to CityJSON v1.0 vs CityJsoN v1.1 #35

Closed zeljkobekcic closed 1 year ago

zeljkobekcic commented 1 year ago

Hello,

I experienced that when I convert a CityGML file to CityJSON v1.0 and to CityJSON v1.1,, that the Y coordinate is different. The CityJSON v1.1 Y coordinate is incorrect.

How to reproduce:

The CityGML file comes from the open geo data portal from North Rhine-Westphalia. It is a small file, which makes it easier to see the problem.

Then I convert the CityGML file to CityJSON in the two versions.

mkdir CityGmlBugReport
cd CityGmlBugReport

wget "https://www.opengeodata.nrw.de/produkte/geobasis/3dg/lod2_gml/lod2_gml/LoD2_32_280_5660_1_NW.gml"

wget "https://github.com/citygml4j/citygml-tools/releases/download/v2.0.0/citygml-tools-2.0.0.zip"
unzip citygml-tools-2.0.0.zip
bash citygml-tools-2.0.0/citygml-tools to-cityjson --pretty-print -v 1.0 LoD2_32_280_5660_1_NW.gml
mv LoD2_32_280_5660_1_NW.json out_v10.json
bash citygml-tools-2.0.0/citygml-tools to-cityjson --pretty-print -v 1.1 LoD2_32_280_5660_1_NW.gml
mv LoD2_32_280_5660_1_NW.json out_v11.json

This way you can access/calculate the coordinates in the two files:

Way to calculate coordinates in CityJSON v1.1: https://www.cityjson.org/specs/1.1.0/#transform-object


import json
import pathlib as p
cityjson_v10 = json.loads(p.Path("out_v10.json").read_text())
cityjson_v11 = json.loads(p.Path("out_v11.json").read_text())

vertices_v10 = cityjson_v10["vertices"][0]
vertices_v11 = [
    cityjson_v11["vertices"][0][0] * cityjson_v11["transform"]["scale"][0] + cityjson_v11["transform"]["translate"][0],
    cityjson_v11["vertices"][0][1] * cityjson_v11["transform"]["scale"][1] + cityjson_v11["transform"]["translate"][1],
    cityjson_v11["vertices"][0][2] * cityjson_v11["transform"]["scale"][2] + cityjson_v11["transform"]["translate"][2],
]

print(vertices_v10)
print(vertices_v11)

This results into:

[280414.632, 5660090.756, 32.971]
[280414.632, 9172695.563000001, 32.971000000000004]

This coordinate does not exist according to https://epsg.io/ and is outside of the geographical extent described in the file.

Is there a problem on how I transform the CityGML file to CityJSON or is it a bug in the CityGML Tools?

clausnagel commented 1 year ago

@zeljkobekcic, I guess this is a duplicate of #31. The transformation issue has been fixed in the master branch but there is no new release of citygml-tools yet.

You can use the edge Docker image of citygml-tools from Docker Hub which already contains the bugfix. Alternatively, you can build your own local version of citygml-tools from the master branch (see here).

I am waiting for the CityGML 3.0 GML encoding to be finalized before releasing a new version of citygml-tools. I hope just a few more weeks.

zeljkobekcic commented 1 year ago

Hello @clausnagel, thank you for your fast answer. This indeed solves my problem. Thank you very much! I am using the docker image now with edge.