CityGML and 3D data in QGIS

Note: Follow the links to read previous texts about Qgis2threejs plugin and new 3D Map View in QGIS.

It’s already the third text devoted to 3D visualisations in QGIS 3.0. This time I’ll finally focus on 3D objects.

In the previous text from this series, I mentioned that when trying to use 3D Map View for vector visualisation, the program crashed. Unfortunately, I haven’t found an explanation for why this happened. I simply tried to do the same thing on a different laptop and surprisingly, it worked.

Today I want to show how to use the 3D Map View for visualising shapefiles e.g. buildings. I’ll show how to read CityGML file and view its information in 3D. Next, I’ll explain how to extrude shapefiles.

I haven’t found a very detailed description of settings available in the 3D renderer, so I spend some time testing them. I tried to figure out what they do and when to use them. I’ll explain my findings at the end of this text.

But like I mentioned before, I had no way to check whether my conclusions are correct. If I get something wrong, please let me know!

Displaying CityGML datasets

Currently, it’s not hard to find 3D city models that are free to use. Most cities have open, free 3D data ready to download. You can find them at geographic information portals run by government agencies.

If you don’t feel like looking for data, visit the official CityGML website. You’ll find there the whole list of such portals https://www.citygml.org/3dcities/ and some sample datasets as well.

And even better, now you can use the new Google dataset search. Just type CityGML in a search box and find the data you need.

For the purpose of this guide, I used a sample dataset from Delft. I found it on CityGML website

(Download from here https://3d.bk.tudelft.nl/opendata/3dfier/)

When you download and unpack CityGML file, create a new QGIS project.

First, open Delft_3dfier.gml file by dragging it to the QGIS window. If the program asks you which layers to import, mark Building and press Ok. Most likely, the layer will miss CRS information, so set it manually in layer’s properties.

I set it to EPSG: 7415, which is the CRS of my data.

Don’t forget to set also the project’s coordinate system. Be sure to choose projected CRS, otherwise, 3D Map View won’t open. I used the same as before (EPSG: 7415).

Next steps are easy. Open Layer styling panel, enable 3D renderer and turn on the 3D Map View to see the effects.

Left: QGIS 3D renderer Rigth: Google Earth

Extruding a shapefile

Did you know that even ordinary shapefiles such as lines and polygons can be visualised in 3D?

In the second example, I’ll create a building footprint based on OpenStreetMap information and extrude it. To represent the terrain, I’ll place it on the DEM layer.

First, find a DEM of the area where the building stands.

Add some base map with buildings. For example OpenStreetMap.

In the Browser panel on the left side right-click XYZ Tiles. Choose New Connection, type the layer’s name.

In URL field paste this link:

http://tile.openstreetmap.org/{z}/{x}/{y}.png

And confirm by clicking OK. The new layer appears under XYZ Tiles. Drag it to Layers panel.

Create a new polygon layer and outline a footprint of the chosen building.

When you’re ready, open Layer Styling panel and navigate to 3D View tab. Enable 3D renderer.

Add the DEM file to the project and check a few elevation values under your building. Type the average value of these numbers as Height.

It will ensure that the building’s bottom surface will stay on top of the terrain. Under Extrusion value, type the height of the building. Set Altitude Clamping to Absolute.

Open 3D Map View and examine the result.

Bonus- 3D renderer settings

I included short descriptions of settings available at 3D renderer. I found some explanations through online research and others by a try-and-test method.

Altitude Clamping

Altitude Clamping is responsible for the position of an object on a surface. There are three options: Absolute, Relative and Terrain. Depending which setting you choose, height values are interpreted differently. The Absolute setting is the best if height values are absolute and measured from 0 (like in a CityGML example). Two other values, Relative and Terrain, add given height values to terrain elevation.

Altitude Binding

Set Altitude Binding to Vertex and every vertex of a feature will be clamped to the surface.

On the other hand, if you choose Centroid, only feature’s centroid will be attached.

Culling mode

The word culling is used in 3D rendering. It means excluding geometries that don’t add to the final image. Using culling increases rendering speed.

If you set Culling mode to Back, polygons facing the inside of the building will not be rendered. It means that if you move your viewpoint inside of a 3D model, you will be able to see the outside. This setting helps with performance optimization.

Setting Front culling will result in disappearing of front faces of polygons.

Add back faces

Sometimes 3D polygons aren’t built properly. When it happens, you can notice it when back culling is enabled- some walls are missing. If you want to improve the rendering of such data, enable Add back faces option. Be careful though, this operation needs more graphical memory.

Diffuse, Ambient, Specular and Shininess

Under Diffuse you can set the colour of the object.

Setting ambient colour means choosing the colour of an object when it is in shadow.

Specular sets the colour of reflection on a shiny object

Changing Shininess value controls the reflectivity of the objects.


What to read next

  • Find out an easy way to create a GIS web app
  • If you need a tutorial how to visualise terrain data in new QGIS 3.0, read this text
  • Learn how to a create 3D map with open source GIS software, QGIS and qgis2threejs plugin.
  • Scanning with your smartphone? Now it’s possible- read here
  • Find out what are the advantages of web-based point cloud viewers from this text.