cityjson / cityjson-qgis-plugin

A QGIS plugin that adds support for CityJSON files
Apache License 2.0
35 stars 8 forks source link

Moving to PostGIS? #39

Open larsgrobe opened 2 years ago

larsgrobe commented 2 years ago

Dear all, first, thanks to the authors for contributing this plugin which makes it very convenient to work with 3D city data in QGIS! I am currently investigating options to share 3D models through PostGIS, and CityJSON appears to provide exactly the level of detail we will need. However, to have access to the 3D data (just as vector and raster data in 2D), I would need to store the models in my PostGIS database. Simply dragging the QGIS-Layer did not work since my PostGIS-Tables lack the z row. Would it be possible to support PostGIS as a storage for the CityJSON-models loaded into QGIS, or is this already possible and I just need to add a column to my tables? I could not find anything about this in the documentation. Best, Lars.

liberostelios commented 2 years ago

Thanks for your kind words! Glad to see that you found the plugin useful.

It's definitely possible to store 3D data in PostGIS, but making it work can be a bit tricky. I am not sure if a simple copy-paste would work out of the box. Maybe that would work, as soon as your layer's geometry definition in PostGIS is defined specifically for 3D? But I am not sure if I would trust QGIS in the process.

My suggestion is that you export from QGIS using the GDL toolbox. You'll have to make an intermediate file, though:

  1. Export the imported CityJSON layer to a file by right-clicking on the layer and selecting Export->Save features as.... I would suggest that you choose a Geopackage or GeoJSON. Make sure that under the you set the Geometry type to Polygon and that you have the Include z-dimension checkbox checked.
  2. From the toolbox select GDAL->Vector miscellaneous->Export to PostgreSQL (available connection). Select your connection and, as input, the file that you just exported. Also, make sure that you set the Vector dimensions to 3.

When I tested this, I ended up with 3d geometries in PostGIS.