3dcitydb / importer-exporter

3D City Database client for high-performance import and export of 3D city model data
Apache License 2.0
128 stars 55 forks source link

Properly calculate the area/volume of a building/city object #294

Closed iduuck closed 3 months ago

iduuck commented 1 year ago

Hey together, I am currently struggling with a problem, that I actually don't know is because of the source data, or because of the importer getting anything wrong.

I am using the data from the city of duisburg to generate some data on my own API. Now, the problem is, that I am having a hard time calculating the area (surface area) and the volume of the building.

As far as I understand, I would need to calculate the st_3darea of the lod2_solid_id's surface_geometry table entry. The problem is now, that I am not getting it to run, because of an internal error in PostGIS.

The error is as following:

PolyhedralSurface is invalid : Polygon 0 is invalid: points don't lie in the same plane : POLYHEDRALSURFACE(((5918945815606329/17179869184 3057265650599723/536870912 6240440971163599/140737488355328,5918942671690269/17179869184 764317136888791/134217728 6240440971163599/140737488355328,5918779445753151/17179869184 6114536738628043/1073741824 6240440971163599/140737488355328,1479695660302205/4294967296 1528632736716161/268435456 6240440971163599/140737488355328,739848229583061/2147483648 382157822126719/67108864 6240440971163599/140737488355328,5918875670200451/17179869184 3057262674187387/536870912 6240440971163599/140737488355328,5918876597913387/17179869184 764315520370475/134217728 6240440971163599/140737488355328,2959474857718317/8589934592 6114524086728131/1073741824 6240440971163599/140737488355328,5918945815606329/17179869184 3057265650599723/536870912 6240440971163599/140737488355328),(5918945815606329/17179869184 3057265650599723/536870912 592258535371309/17592186044416,2959474857718317/8589934592 6114524086728131/1073741824 592258535371309/17592186044416,5918876597913387/17179869184 764315520370475/134217728 592258535371309/17592186044416,5918875670200451/17179869184 3057262674187387/536870912 592258535371309/17592186044416,739848229583061/2147483648 382157822126719/67108864 592258535371309/17592186044416,1479695660302205/4294967296 1528632736716161/268435456 592258535371309/17592186044416,5918779445753151/17179869184 6114536738628043/1073741824 592258535371309/17592186044416,5918942671690269/17179869184 764317136888791/134217728 592258535371309/17592186044416,5918945815606329/17179869184 3057265650599723/536870912 592258535371309/17592186044416),(2959474857718317/8589934592 6114524086728131/1073741824 6240440971163599/140737488355328,2959474857718317/8589934592 6114524086728131/1073741824 592258535371309/17592186044416,5918945815606329/17179869184 3057265650599723/536870912 592258535371309/17592186044416,5918945815606329/17179869184 3057265650599723/536870912 6240440971163599/140737488355328,295947485

So, my question is, is this something the importer should "correct" when importing, or is the importer just "dumb" and we are trusting that the source data is valid?

clausnagel commented 1 year ago

The importer does neither check nor correct invalid geometry but just imports it as-is. So, the geometry issues come from your input data. There are some tools for validating CityGML geometries. I can recommend CityDoctor (open source) and FME (commercial). You could use these tools to validate your input data before importing it.

gioagu commented 1 year ago

Hi!

Another thing to consider: PostGIS 3D functions (e.g. ST_Volume) are a pick "picky" when it comes to the planarity test with polygons that, for example, make up a PolyhedralSurface.

Your geometries could be indeed correct (you can test them using the tools that Claus suggested), but sometimes, if they are not triangulated and due to - I assume - coordinate conversion to PostGIS' binary wkt, you may still end up with the error you show. This has happened to me a number of times computing volume as you are doing.

Unluckily, to my knowledge, there is no way at the moment to set a tolerance threshold in ST_Volume to overcome this "issue".