tudelft3d / azul

3D city model viewer for Mac
GNU General Public License v3.0
101 stars 15 forks source link

does Azul support rendering CityJSON v0.6? #5

Closed agilliland closed 5 years ago

agilliland commented 5 years ago

I have some data that I'm currently writing into citygml and cityjson. Azul renders my gml just fine, but when I write the same data out into cityjson v0.6 the geometries are way off.

Notes on the Azul 0.8.1 release says it supports CityJSON v0.5 so I'm unsure if there are enough deltas between cityjson 0.5 and 0.6 to cause the issues I'm seeing or not. I'm creating both files using citygml4j.

Here's a view in Azul of the citygml: screen shot 2019-01-02 at 5 07 11 pm

Here's the strange rendering of the cityjson v0.6: screen shot 2019-01-02 at 5 09 02 pm

hugoledoux commented 5 years ago

it does support v0.6 yes (and also v0.8, nothing related to geometries has changed). The demo files should work: https://www.cityjson.org/en/0.8/datasets/ Do they?

How did you create your CityJSON file actually, just curious?

agilliland commented 5 years ago

Yep, the 0.8 demos are rendering fine for me in Azul, so it must be something wrong with my files 😢

I'm creating the files using citygml4j by extruding a footprint+height into an LOD1 solid. The footprint is a GeoJSON geometry in WGS84 lat/lon pairs and the height values are in meters. The code is open source if you care to look. This is from a PR that is trying to add in the CityJSON support https://github.com/opencitymodel/data-pipeline/blob/48181174fd094e1788f334380496a3ded758d9a8/citygml/src/main/java/org/opencitymodel/citygml/CitygmlBuilder.java

The source data for this is a flat JSON object with the geometry, height, and an assortment of other attributes we may find/calculate. Each JSON object represents a building.

{
   "id":"18SUH2497:-1433177202",
   "ubid":"87C4RX7F+4M-2-2-2-1",
   "state":"DistrictofColumbia",
   "county":"11001",
   "lat":38.812817,
   "lon":-77.025778,
   "mgrs":"18SUH2497",
   "grid":"18SUH29",
   "area":626.383955123689,
   "height":7.23,
   "height_source":"model",
   "fp_source":"msfp-usbuildings-v1-1",
   "geometry":{
      "coordinates":[
         [
            [
               -77.025616,
               38.812654
            ],
            [
               -77.025719,
               38.813008
            ],
            [
               -77.025938,
               38.812969
            ],
            [
               -77.025918,
               38.812899
            ],
            [
               -77.025862,
               38.812909
            ],
            [
               -77.025779,
               38.812625
            ],
            [
               -77.025616,
               38.812654
            ]
         ]
      ],
      "type":"Polygon"
   }
}

The CityGML is coming out fine and renders in Azul. I've also used it to export into cesium streaming tiles for web visualization and that's working as well.

hugoledoux commented 5 years ago

citygml4j offers the possibility to convert CityGML to CityJSON, it works perfectly. I suggest you use this, there's an example code (https://github.com/citygml4j/citygml4j/tree/master/citygml4j-samples/src/main/java/cityjson/citygml2cityjson)

another thing you can do is validate your CityJSON files with the validator in cjio, that might catch errors you have made during the conversion.

agilliland commented 5 years ago

Ahh, after a little debugging and looking at the examples you provided I found that the problem was that I was losing precision on my vertices given that I'm using WGS84 and the values all have up to 6 decimal places. Adding this line to my cityjson output factory resolved everything ...

factory.setVerticesBuilder(new DefaultVerticesBuilder().withSignificantDigits(6));

I'll try running the files through cjio to validate them as well but I'm a lot more confident now that the geometries are rendering properly in Azul. Thanks for the help @hugoledoux !