" />


Tutorial: 3D in QGIS

3D plugin!

It has now been possible to create 3D models in QGIS for several months using the QGIS2ThreeJS plugin. I have seen several nice maps that came out of this plugin:

This plugin is perfect for me, as I have little coding experience, and this plugin requires absolutely none of it. For a step-by-step guide of how to make a map using this plugin, view the great blog of Anita Graser.

I tried to use the plugin in a slightly different way, as I don’t use it for topographical purposes but for a more abstract purpose. I wondered if it was able to population density in the Netherlands in an original way, not using points or polygons but using lines (and 3D obviously). Here is my thought process/steps:

1. Data

I used CBS data (Dutch statistical agency) as they have pretty detailed data regarding real estate values in the Netherlands. This data is available as 500x500meter polygons.

I first tried to simply plot these squares using the population density as the height of the Z axis. However since there are a lot (151108) 500×500 meter squares making up the Netherlands I quickly ran into performance issues. Inspired by James Cheshires Population Line map, I wanted to visualize using lines.

1Polygon2500002 (Custom)

Polygon Shapefile (CBS, 2013)

2. Manipulating data

As mentioned before I wanted to go from polygons to lines. However this is easier said than done. I wanted horizontal lines, however at first I was stumped on how to generate them from polygons… I first started to make centroids from the polygons, which is easy enough in QGIS.

Polygon en punten

From polygons to centroid points (CBS, 2013)

I then thought of something, if I want to connect the dots in a horizontal line they will all have the same latitude value. Following this I calculated this value in a new field using the field calculator and then used the point to line function to connect the dots to form 1 line using the latitude value as the binding attribute.

So now I had my lines, 626 of them to be exact, however they looked nothing like the Netherlands as the lines simply connected through water to form a uniform blob of lines. So I clipped the lines using a layer of the Netherlands which solved the problem and produced a nice sharp layer.

Straight to water

Straight lines to straight lines with water mask (CBS, 2013)

However I still needed to gives these lines a z value. Luckily the threeJS plugin supports multiple layers, so I simply created a DEM from the original centroid layer I created earlier! I used the number of people per 500×500 meter square as the height value which resulted in a DEM (generated using the QGIS toolbox, GRASS interpolate plugin).


DEM of the Netherlands based on population density

3. Final product

So to recap, we went from polygons to points, from points to lines, from lines without height value, to lines on top of DEM.

This results in the following output:


3D model of population density in the Netherlands (click to view model)

Investigate the model by clicking on the picture (Controls: Left mouse button : Rotate, Middle mouse button : Zoom, Right mouse button : Pan).

You will see a landscape which just looks like a bunch of lines from above but once you pan and zoom you will find that it is a landscape including height.

You will see the huge population density in Amsterdam and the ‘flat plains’ in the Dutch countryside. Be advised though, the model uses a lot RAM, and is quite a large file, so it might take a while to load.

I hope you found this blog interesting, have fun exploring the plugin for yourself. Feel free to ask any questions!


This Post Has 12 Comments

  1. carlosgis schreef:

    Hello, thanks for the tutorial and that work, how you find a way to place legend in those maps
    Best regards, from Nicaragua!

  2. Stef schreef:

    Hey, nice job. The map looks awesome. I have one question though, from where did you obtain the continous high resolution population data? I have searched around but I only seem to find discrete data based on municipalities of the Netherlands

  3. Kate Z schreef:

    Love this map! Trying to recreate this concept (pop density for different countries in Africa) for a publication but wondering if it’s possible to save/convert the html output into an image file?

    • Jeroen Drewes schreef:

      Hello Kate,

      Sounds like a cool project! There is a built in ‘save as image’ functionality within the export. You can use it with the key combi Shift+S. Hopefully this works!
      Good luck on your project.

  4. Kate Z schreef:

    Hi again Jeroen,

    I’m having issues in replicating the map – I have raster pop density data that I’ve converted to vector data (points) and then I’m trying to convert to lines but I don’t quite understand the step with the field calculator. What was the field that you calculated for the points? latitude?


    • Jeroen Drewes schreef:

      Hello Kate,

      I believe I calculated the y value. You can use the field calculator in Qgis for this. The correct formula would be ‘ $y ‘. If you put this in the expression box it will calculate the y value for your points, which should be the same for each line of horizontal points. You can the combine the points to a line. Hope this helps!


  5. Kate Z schreef:

    Ok great, and one last question. For the line vector file in the threejs plugin, for the mode (z-coordinate), what did you select – “relative to DEM”? Did you have to play around with the height? Thanks for your help and patience!

  6. JohanBlomme schreef:

    Hi Jeroen,

    I tried to apply the procedure you describe in your tutorial. More specifically, I used centroid coordinates to get a spatiallines object (with the point to lines plugin) and to give a height to the lines I used a DEM raster file. I entered the DEM in the user interface of the QGis2threeJS plugin but this does not seem to work. I cannot select “relative to DEM” to specify a z-coordinate. What am I doing wrong ?

    • Jeroen Drewes schreef:

      I believe that with the current plugin you only need to select the DEM layer in the DEM tab (on the left). And then select the line layer and set the Z-coordinate to relative to DEM. Is this option not available at all in the dropdown menu?

Leave A Reply

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you agree to these settings.