1

I have a buildings layer in QGIS that is stored in Postgis. The layer is MultiPolygon type although I am pretty sure there is only 1 geometry (Polygon) per element.

enter image description here

I was able to create a height field (height of the building) for each polygon using a LIDAR layer.

Now, I would like to modify the geometry of the layer and convert each building from 2D to 3D using this height field.

In QGIS, I tried the "Set Z Value" Processing algorithm, but when I check the $Z value for each element, I get null. If I open the 3D view, I see it is totally flat.

I also tried "Drape (set Z value from raster)" using a raster created with the heights, and I got the same result.

So my next step was to do it with PostGIS. I created the following query that first converts each point to a point3D, then creates Polylines3D, and finally, Polygonizes the lines:

CREATE TABLE "borrarEdif3DPrueba" AS
    WITH points2d AS
        (SELECT id,(ST_DumpPoints(the_geom)).geom AS geom, altura_edificio_max
         FROM "borraEdifConAltura"
        )
    ,
    points3d AS
        (SELECT id, ST_MakePoint(
             st_x(geom),
             st_y(geom),
             altura_edificio_max) AS "geomPoint3D"
             from points2d)
    ,
    edif_line as (SELECT  id, ST_MakeLine("geomPoint3D") AS geom
    FROM points3d
    GROUP BY id)
    ,
    edifpol as (select id, ST_Force3D(ST_setSRID(ST_CollectionExtract(ST_Polygonize(geom),3),25830))::geometry(MultiPolygonZ, 25830) as geom from edif_line group by id)
    
    SELECT id, geom from edifpol

I imported the layer into QGIS and got the same result: $Z values are null, and in 3D everything is flat.

2
  • 1
    are your geometry columns MULTIPOLYGONZ, MULTIPOLYGONMZ or just MULTIPOLYGON?
    – Ian Turton
    Dec 19, 2022 at 12:11
  • Yes, the table is MultiPolygonZ. I add the geometry(MultiPolygonZ, 25830) conversion explicitly in the query just in case
    – Egidi
    Dec 19, 2022 at 12:21

1 Answer 1

1

If it's just for visualization, you can use the attribute value directly to show the polygons in 3D, using Layer Styling > 3D View settings. For extrusion, use data driven override and select the elevation attribute. Then the polygons will appear in 3D.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.