[GIS] Convert raster to smooth contour polygons in QGIS

contourqgisraster

I have had limited success creating smooth contour polygons from a raster layers.

I have created contour lines and boundary polylines and then used QGIS Union. Then I use QGIS Polygonize. Then use zonal statistics to the original raster to get the value on the polygons.

The 2nd method I tried was to convert raster to polygon. Then create a new attribute column rounded to the contour I desire. Then I dissolve lines between the same value. Then use v.generalize. This method is a little quicker, but it will leave some polygons jagged/unsmoothed.

enter image description here

Is there an easier method that actually works all the time. Seems like there should be a simple command that does the entire process.

Best Answer

I've experienced the same problems you area having in your second method. I exported a Raster to a Vector and try to and use v.generalise and I get mostly smooth polygons with the occasional 'stepped' boundary which appears to have been unaffected by the algorithm.

I found a process that worked for my task, not sure if its the best way but thought i'd share it in case it helped you.

What I started with was an ascii grid from BoM that looked like this: enter image description here

What I wanted something similar to what BoM produce like this: enter image description here

I was able to get to an outcome (that I was happy with) using the following steps.

  • Load grid (in my case ASCII Grid from BoM) into QGIS.
  • Recoded into discrete classes. (Processing Toolbox>Grass>Raster>r.recode)
  • Run a majority filter to 'clean up'.(Processing Toolbox>SAGA>Raster Filter>Majority Filter)
  • Created contours from the filtered grid at intervals of 1, and stored them in an attribute 'class' (because my classes were 1,2,3,4,etc). (Raster 'Menu'>Extraction>Contour)
  • The output contours are somewhat generalised, but I used v.generalised with the 'snakes' algorithm to smooth them out.(Processing Toolbox>Grass>Vector>v.generalize)
  • I then converted the lines to polygon.(Processing Toolbox>QGIS geoalgorithms>Vector Geometry Tools>Lines to Polygons)
  • Finally I had to convert the single part polygons into multiple parts, so that all the polygons drew nicely. (Processing Toolbox>QGIS geoalgorithms>Vector Geometry Tools>Singleparts to Mulitpart).

After styling my output is below: enter image description here

I would also be interested in hearing if someone knows a simpler way. Originally I was thinking similar to @Rx_ that I could just convert my raster to vector then generalise and I would be done. What I had to do was much much longer.