3

I have a polygon layer (consist of buildings) and it has different attributes including the height attribute. I want to use that height in order to extrude my all polygons or give height to my building then export the dxf file. Want to give that height to my all polygons using the PyQGIS. I am able to find extrude documentation but unable to locate any working example as I am confused with two parameters of extrude which is x and y. I guess it should be consist of one parameter of height only.

extrude(self, x: float, y: float) → QgsGeometry
Returns an extruded version of this geometry.

Some code which I have applied without any success(no visual appearance change of polygone)

#getting the desired layer
if QgsProject.instance().mapLayersByName(layerUpdateName):
    layerUpdate = QgsProject.instance().mapLayersByName(layerUpdateName)[0]; 

for lu in layerUpdate.getFeatures():
    print (lu["Height"])
    #lu.geometry().extrude(lu["Height"],lu["Height"])
    #testExtrude(lu,lu.geometry())
    #geom = lu.geometry().asPolygone()
    lu.setGeometry(lu.geometry().extrude(lu["Height"],lu["Height"]))
3
+25

What about forgoing 0.5D?

;-)

If you don't really need extruded polygons, bot only a 3D-like representation, the 2.5D rendering option might work for you.

You can apply a calculated value to be used as "extrusion" height, based on one or multiple fields.

enter image description here

Of course this is not a real extrusion, but might suffice in many cases.

  • 2
    I am looking for actual extrusion as i have to export it for 3d modelling tool and make proper building with actual height. – Muhammad Faizan Khan Oct 16 '19 at 7:15
  • 1
    exported the layer in dxf file format and there is no height. – Muhammad Faizan Khan Oct 16 '19 at 12:32
2

Based on your comment where you say:

I am looking for actual extrusion as i have to export it for 3d modelling tool and make proper building with actual height.

I would recommend installing the qgis2threejs plugin, setting up your extrusion there, and exporting as glTF:

enter image description here

glTF export

glTF is a JSON 3D format that can be imported into a 3D modelling software. For example, I have successfully exported extruded building polygons projected onto a DEM draped with ortophoto to Blender 3D using this method.

Wikipedia for glTF: https://en.wikipedia.org/wiki/GlTF

Although a caveat is that you most likely will lose georeferencing with this process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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