# Making elevation contours of raster smoother using QGIS

I am using QGIS 3.6.

I have raster of Europe map which I want to make a colored relief model. After duplicating the layer, used hillshade on backward layer and colored the upper layer interpolation > discrete then 65 % transparency. But the contour of color levels are not smoothed as the image shows.

Is there any way to do that?

Ex (photo):

• An example of how your map looks would be helpful. – Saijin_Naib Dec 27 '19 at 19:27
• There is an example and what I want to do is to make smooth the contour line between colors as the example have. – Iven Pepa Dec 27 '19 at 19:39
• Please edit your question to show the pictures – Ian Turton Dec 27 '19 at 19:46
• Have you created a polyline feature using the contour lines? If so you can use the simplify/smooth tool in qgis to accomplish this. – Kartograaf Dec 27 '19 at 22:37
• @Kartograaf, your answer was really useful and I think that you deleted it? If you can rasterize the smoothed contours the output will look great. – Gabriel De Luca Dec 28 '19 at 5:12

## 2 Answers

In my case, I have a DEM with continue values, going from 100 to 103 meters. The spatial resolution is 0.25 x 0.25 degrees, defined in EPSG:4326. The DEM is styled with a discrete color ramp with three classes:

To smooth it, first I will make a raster algebra. Because I want a raster with only three values. I am using the following formula:

``````("testDEM@1"  <= 100) * 100 +
("testDEM@1"  > 100  AND  "testDEM@1" <= 101) * 101 +
("testDEM@1" > 101 AND "testDEM@1" <= 103) * 103
``````

Don't worry about its style, because it is an intermediate step:

For the smooting, I will use GRASS provider `r.resamp.rst` algorithm, in two steps. First, we need the slope output to use it as a smoothing raster. So run the algorithm without smooth raster. Set the spatial resolution and delete row/column overlap and spline tension values:

From the outputs, I have removed all of them except the slopes raster:

Finally, run the GRASS provider `r.resamp.rst` algorithm again, defining the slopes output as smoothing raster:

We just need the Resampled output. But now, we will style it with a linear interpolation instead discrete:

Now, you can use that raster with a 65% transparency over a hillshade:

External Reference:

• I'm trying in this way as you explained step by step but i have some problems during the r.resamp.rst process. At the first step after finishing r.resamp.rst process checking only the slope raster, at log window is an ERROR 6: SetColorTable() only supported for Byte or UInt16 bands in TIFF format. although the process finished resampling slope raster. So, at the last step using r.resamp.rst > selecting output and slope raster > same resolution (200 cell size) > deleting Rows/columns and Spline tension > result : ERROR: Map <rast_5e1f80a7de6704> is the wrong resolution, and couldn't finish. – Iven Pepa Jan 15 '20 at 21:20
• @IvenPepa, Hi. The ColorTable error is not important, a color table cannot be written for float format values, but we are not interested in the color table. The problem is with the resolution when running the algorithm again. If the CRS is a geographic one, the resolution of 200 degrees is not possible. If you cannot solve the resolution problem, please start a new question about all detailed steps to reproduce it and a complet log paste in your question. – Gabriel De Luca Jan 15 '20 at 22:35

There are several tools that exist in qgis to smooth contour lines as opposed to smoothing the raster itself , including vector->geometry->simplify, the vector geometry tool "smooth", and the GRASS function v.generalize.

Personally, I like the results of the SAGA module line smoothing ("http://www.saga-gis.org/saga_tool_doc/2.2.2/shapes_lines_7.html), and the results in the sample data I used look pretty similar to what you provided.

To use it, make sure you have the SAGA installed (https://sourceforge.net/p/saga-gis/wiki/SAGA%20Installation/) then select the tool from the processing toolbox (#1). Use the method drop-down menu to select the improved iterative averaging (SIA) algorithm (#2).

Before:

After:

You can then convert the lines back to raster format via GRASS package's r.surface.contour or similar. Creating a contour raster from contour lines shapefile