I am in an early stage of least cost paths analysis of a wide area. One part of the operation includes simulation of movement across the grid of previously agreed size of cells and extent of the grid (for reference one cell is 5X5 km).

I have easily enough created the grid (as vector - polygon file), however i would now need to provide friction values as a attribute input for each cell (each cell is a separate polygon entry), based on the above the sea level values from an underlying DEM model (SRTM in this case). In short this would, ideally, look like this: - if a 5X5km cell contains more than 50% of surface that is of certain above-the-sea level, i would attribute a value to it from a devised chart of values that describe the friction value for this cell.

Can someone suggest how to proceed with this?

I am quite uncertain how to satisfy the "above 50%" condition. While i expect to be working with raster data, majority of work will be done while working in table format, with values extracted from various cost raster.

UPDATE: Following the comments bellow, i worked through the DEM dataset in the following manner: using answers found here:How to reclass a raster with reclassify grid values in QGIS? i reclassified the dem raster into having a number of classes i needed (0 for elevation <=0, 1 for elevation range from 1 to 499 meters and so on - 4 in total). I had then used gdalwarp to obtain a desired resolution of the raster (equal to the resolution of the vector grid - i kept on to the vector, since it seemed to be good way to get the desired data from .shp attribute table into excel, as i need it to be in that form during one of the process steps). In such way 1 grid cell would get the attribute value of the dominant class i.e. elevation range within its boundaries. I went further with calculations of percentages of each elevation class contained within each grid cell, but i need to work on it further - comments on answers bellow point out to the direction im going. So - in order to get the dataset i need, it is necessary for me to get for an each cell grid (5X5 kilometers size) percentage of each elevation range im having within its boundary (<=0, >= 1 and <=499, >=500 and <=1000m and so on) as a attribute table data, ideally as separate columns. Can this be done?


You can use the raster calculator to reclassify the DEM according to these rules:

  • 0 if the cell is below sea level
  • 1 if the cell is above sea level

Use this formula:

@myraster*(@myraster > sealevel)

Substitute the actual sea level elevation value where it says sealevel, and substitute the name of your raster where it says myraster.

This gives you a raster where 0 is sea and 1 is land.

Then you can either:

  • Use gdalwarp (as MappaGnosis suggested) to resample to 5km x 5km cells, but calculate the mean. Polygonize and use the resulting grid in your analysis.


  • Use the Zonal Stats tool to add the mean raster value to each grid square, using your grid file as the "Vector layer containing zones."

Multiply by 100 to convert to percentage. Eg, grid cells with a value of 0.5 have 50% land above sea level.

  • Need a clarification re. Zonal Stats: i created 4 classes in the raster layer, describing various elevation ranges, and gdalwrapped it to a 5X5 km and created (for testing purposes) another grid with 10X10 km size of each cell size. That way, a single cell of the grid could contain max 4 classes within. I want to calculate coverage percentage of each raster class within cell grid, and add the information to the grid layer attribute table. I was - so far, unable to do this with Zonal Stats. Would you have a suggestion on how to proceed to this result? – Radioactivepanda May 27 '19 at 8:55

You could do this by using gdalwarp and set the resampling method to median. you don't need your 5km by 5km vector layer. Just resample the original raster to the resolution desired (enter this in the dialog box). You will probably keep your input and output CRS the same for this use-case.

We are using median and not mean to try and reduce the effect of a small but very high patch of ground that would otherwise skew the whole area to appear to be above sea level. Once you have a raster of all the median heights, you then will need to reclassify it with your cost values.

  • This worked - i would try to make it more complex as per my comment bellow to @CSK - id (ultimately) use a non-resampled SRTM dem, to calculate percentages of coverage of each elevation range within a grid cell. The percentage marks the friction - i.e. elevation range from 1 to 250 meters is more favorable to the 750 to 1500 meters elevation, and if a cell contains, say - more than 50% of a 1-to-250 meters elevation range it will be considered as a more easier path of movement. I am unsure how to calculate this output into attribute table of the grid vector. Do you maybe have a suggestion? – Radioactivepanda May 27 '19 at 9:23
  • It is starting to sound like you might be interested in computing either Terrain Ruggedness Index (TRI) or roughness map (slight variations on a theme). Have a look at the GDAL reference for these here, also possibly Slope might be of interest. With these you could get a little more sophisticated in your approach to creating the cost surface. – MappaGnosis May 27 '19 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.