How to extract contour lines from a point cloud
Step by step in CloudCompare: rasterise a point cloud into a DEM, choose grid step and empty-cell handling, then generate and export contour lines to CAD or GIS.
Clicking loads the video from YouTube: Google will receive your IP address and may store data on your device. Privacy · Watch it on YouTube
In this article I’ll explain how to extract contour lines from a point cloud using the open source software CloudCompare.
Point clouds
A point cloud is a file in which thousands, hundreds of thousands or millions of points in space reproduce an object or a landscape in 3D.
You’ll find it in these file formats: LAS, LAZ, PLY, BIN, XYZ, ASCII (and there are others…).
The aerial photogrammetric surveys that followed the spread of drones, and the availability of LiDAR instruments at more competitive prices than a few years ago, mean point clouds are talked about more and more.
Lots of people mention them, many surveyors and engineers (and not only them) process them, and many software houses have invested resources in them, making products and applications to import, view, edit and manage them.
Point clouds from surveys
A few years ago, if you commissioned a survey, what you expected to receive (and in many cases did…) was a contour plan of the area, with the characteristic features of the land drawn in CAD from the points measured in the field.
Today you might also receive a point cloud.
If you’ve never seen one, the topic may not interest you, but wait before closing this article!
I believe a point cloud can give you access to a lot of information about what was surveyed.
If you know how to open, inspect, edit and process it, you can get much more than a plan drawing (often two-dimensional!).
And you could do it completely on your own, looking for what you need for your work, without constantly going back to the surveyor.
CloudCompare
CloudCompare is open source software born to compare point clouds from laser scanning surveys.
Over time its developer has extended it with various advanced and rather interesting tools and plugins.
I’d written two articles on using it to get sections from point clouds.
You’ll find them here: a cross-section from a point cloud, cross-sections with CloudCompare.
I’ve appreciated this software for some time, but it was only after a training course organised by Gter s.r.l. of Genoa and taught by Ilaria Ferrando, of the Geomatics Laboratory of the Engineering Faculty of the University of Genoa, that I really grasped its potential and discovered some very interesting functions.
Being open source and having a huge online community behind it (where you can look for and find information, tutorials and answers) makes it, in my view, software to install and use!
I don’t think I’m exaggerating if I say CloudCompare will become, among point cloud software, what QGIS has become in GIS.
Contour lines from a point cloud
You know what a contour line is, but I’ll write it again.
A contour line is a line joining points of the ground at the same elevation.
The difference in elevation between the points of one contour and those of the next is constant for all the contours of a map: the contour interval.
One of the first articles I wrote on this blog was about their characteristics: you’ll find it here.
With contour lines you can find valleys and ridges, understand the slopes of a hillside or locate a road…
You can extract contour lines from a point cloud, and now I’ll try to explain how.
Import the point cloud
The first step is to import the point cloud into CloudCompare.
At the time of writing, version 2.10 alpha was available to download.
If it helps, you can download here a point cloud to practise on.
It’s a piece of slope below a marble quarry in the Apuan Alps basin.
The cloud comes from an aerial photogrammetric drone survey.
When you import the (LAS) file, CloudCompare will ask for two confirmations: one about the information to load with the points, the other about a shift (in X, Y and elevation) it recommends to avoid errors when processing very large coordinates (typical of a georeferenced survey).
Confirm both.

Don’t worry about the shift, it’s only fictitious, and when you export the results everything will be as before.
Select the point cloud
Once the point cloud is imported, you need to select it to activate the processing functions.
You do this by clicking the “Cloud” object in the “DB Tree” panel, on the left of the workspace by default.

Contour lines from a DEM
To get contour lines from a point cloud you need to go through a digital elevation model: the DEM (Digital Elevation Model).
A DEM is a statistical surface that assigns an elevation, a Z, to each (X,Y) coordinate pair.
The DEM typically refers to the Earth’s topography but can concern other surfaces too.
I won’t go into the theory of statistical surfaces, as I don’t think it adds value here.
If you want to dig deeper, I wrote a post on the differences between DEM, DTM and DSM, which you’ll find here.
To help you understand a DEM and why it matters for generating contour lines, I’ll use the diagram below.
It’s a simplified section of a slope, but try to imagine it whole and in three dimensions.
A DEM is built by discretising the topographic surface with a square grid.
The grid squares are all equal.
Their side is the step, spacing or resolution of the digital model.
Each square is a small piece of horizontal plane bounded by its four corners (whose X and Y coordinates are known) and has an elevation (a Z value) which is usually the average elevation of all the points inside it.

The DEM is a raster, an image that looks more or less chequered or pixelated, depending on the size of the grid squares.
The smaller the step, the more accurately the surveyed landscape is represented.
The most common file format for a DEM is TIF.
It can be opened in any GIS software and keeps the georeferencing information inside it.
Generate the DEM
Now that you have an idea of what a DEM is, I’ll show you how to extract contour lines from the point cloud.
With the cloud selected, go to “Tools – Projection – Rasterize (and contour plot)”.
A new window opens where you can set many parameters for generating the DEM and, after that, the contour lines.

At first the window is empty, because the DEM hasn’t been generated yet.
A few words on the generation options.
GRID
The grid is the mesh that discretises the model.
The STEP sets the side length of the grid squares.
It’s an important parameter, also for generating the contour lines.
If the grid squares are small, the DEM approximates the cloud well, but the contour lines may be a bit “jittery”, picking up local features that aren’t interesting or shouldn’t even be shown (medium-sized boulders and blocks on the slope).
If the grid is made of large squares, the contour lines may look nicer, but you risk losing specific features such as hollows or humps, which could be relevant for analysing rainwater runoff.
Careful: CloudCompare uses implicit units!
This applies to generating the DEM as well as all the other operations on point clouds (distances, areas, alignments, …).
The unit depends on how the survey was done.
If you surveyed in millimetres, 1 corresponds to a millimetre.
If you surveyed in metres, 10 is ten metres.
I work in metres.
Below you can see the DEM of the point cloud with a step of 1 (m) and 5 (m).
You’ll surely notice that the DEM with step = 5 is more chequered than the one with step = 1.


The Active layer is a way of displaying the DEM.
You can use different colours depending on elevation (the most common case, and the one I show here), RGB colours taken from the points of the cloud, or other methods.
It changes nothing in substance.
It’s just a way of displaying it.
Below is a close-up of the DEM generated with a one-metre step, where the points are the centres of the squares the 3D model was discretised into.

PROJECTION
In the Projection box you decide how CloudCompare will calculate the DEM.
To extract contour lines from a point cloud, the direction must stay Z, because the elevation information is in Z.
Cell height lets you choose how to calculate the height of the cells.
I usually leave average height, because it reduces the chance of values inconsistent with reality caused by a “dirty” point cloud or particularly complex ground.
The other two options (interpolate SFs and resample input cloud) are less relevant (for these purposes) and you can leave them unticked.
EMPTY CELLS
Empty cells is an important parameter with which you decide how CloudCompare behaves when it finds a “hole” in the point cloud.
With Leave empty it leaves the hole empty, which in my view is philosophically the most correct choice.
Or you can tell it to fill it in various ways.
Among those available I’d suggest “interpolate”, with which the software takes the elevation information from the existing points around the hole and fills it.
But you can try all the options to see how it works in your case.
Holes in a point cloud aren’t a minor issue, far from it!
If you receive a cloud from an aerial photogrammetric survey (the same goes for laser scanning), you might want to clean it to remove trees, buildings, power line pylons, parked cars or other man-made features, keeping only the ground information (bare earth).
This operation, which CloudCompare handles very well with its tools, is very important because it strengthens the cloud for the information you want to keep (like the ground), but it inevitably leaves areas without information, which you’ll have to decide how to handle when generating the DEM and contour lines.
Once you’ve set all the parameters for creating the DEM, click the red Update grid button and the digital model will appear in the main window.
You can export the DEM to a TIF (GeoTIFF) file from the Export panel of the same window (at the bottom), choosing the Raster option.
You can use this file in any GIS for further analyses or processing.
It’s a georeferenced file!

Generate and export the contour lines
In the lower part of the window you still have open, select the Contour plot tab.
Now you can generate and export contour lines from the DEM.
Here you need to choose the starting elevation for generating the contours.
Careful, because it’s the elevation recalculated with the initial shift CloudCompare proposed when importing the point cloud!
My advice is to round this number down to the ten just below the default value you find in the cell.
The step is the contour interval.
Min. vertex count is, as far as I understand, the minimum number of vertices a contour line must have to be kept: shorter, fragmented contours are discarded.
Check the CloudCompare documentation for the exact behaviour in your version.
My advice is again to try different values depending on how complex your case is.

If you tick Colorize, the contour lines will have different colours depending on their elevation.
When you’ve set the parameters for generating the contours, click Generate.
Then with Export you export them as vector elements.
Export the contour lines from CloudCompare
If you chose to export all the contour lines, you’ll find the DB Tree panel on the left full of new elements grouped in a folder called Contour plot.
Each contour is identified by a number, its elevation.
I’ll repeat once more that this value isn’t the real elevation but the one calculated from the initial shift when importing the point cloud.
They’re all vector elements you can save and import into other software, such as CAD.
To export them, select the whole folder containing them and do “Save (CTRL+S)”.
Choose the file format you prefer among those available (including DXF and shapefile SHP) and give the file a destination.
If you open the file you’ve just saved in AutoCAD, you’ll see the contours shown as 3D polylines with the correct elevation and georeferenced.
The same goes for the shapefile opened in a GIS.

I hope this article helps you extract contour lines from a point cloud simply and quickly using open source software.
The point cloud I’ve made available for download (here’s the link again) isn’t complex or very large.
I think most computers can handle it fairly easily, without particular hardware.
You can use it to experiment and try out what I’ve written as you like.
See you soon!
Paolo Corradeghini
I published a video on my YouTube channel about interpolating a point cloud to get a 2.5D raster and contour lines representing the ground. The video is in Italian.