1

I have a DEM in HGT format. I need to isolate all areas above a certain elevation and view them as polygons. Something like this (let's say the pink polygon is everything above 1000m):

DEM to polygon example

Seems like this would be a common GIS task, but all I found is the GRASS r.lake function. What I need is the opposite of a lake. :) QGIS/Python/GRASS solutions are preferred.

2
  • 2
    Reclassify into 2 classes, convert to polygons should work
    – jbalk
    Oct 4, 2018 at 16:30
  • @jbalk: how would I do that? A full answer would be much appreciated.
    – kontextify
    Oct 5, 2018 at 7:39

5 Answers 5

5

You can use:

enter image description here

enter image description here enter image description here

Convert line to polygon tool

enter image description here

To isolate area you can Clip DEM with polygon. I hope that is it.

1
  • 1
    Perfect! I used the GRASS r.contour.step command for the contour lines, then Vector > Geometry tools > Lines to polygons. Exactly what I needed.
    – kontextify
    Oct 5, 2018 at 8:05
4

You can use r.recode to extract the areas above a certain altitude, and then r.to.vect to convert the resulting raster layer to a vector layer. The steps:

Import the data

You can import the data in a grass gis database using r.in.gdal or using the 'import raster data' menu (for more details see the grass wiki page Import of original SRTM tiles in HGT format.

Import raster data

Extract the area of interest

Next, you have various options to 'extract' the areas above a certain altitude, including the r.mapcalc, r.reclass and r.recode. In the example below, the r.recode function is used to reclassify all cells of the elevation map with a altitude > 120 to 1. The rest will be assigned a NULL (nodata) value.

Recode a raster layer

Note that the field marked with the blue asterisk will be automatically filled in (it is the path to a temporary file) when you enter the recode rule in the field below.

Convert from raster to vector

You can now convert the resulting raster layer to vector layer with the r.to.vect function.

Convert the raster layer 'highareas' to the vector polygon layer 'highareas'

Or all in once

You can use the steps above on the command line in one go:

r.recode input=elevation output=highareas rules=- << EOF
120:*:1
EOF
r.to.vect -s input=elevation@PERMANENT output=highareas type=area

And the result

This gives you a vector map of all areas with an altitude > 120.

Elevation map from the North Carolina sample dataset, overlaid with a vector layer (transparent blue area) with the areas with an altitude > 120

1

Just use QGIS:

  1. From the raster bar open the raster_calculator and perform your query, e.g.: "myDTM@1" > 1000 Result must be saved in a new raster, e.g.,"myDTM1000"
  2. From raster bar -> conversion open the polygonize tool and convert this raster into a polygon.

QGIS polygonize tool is based on a gdal function. You can even use directly gdal if you prefer.

1

Using GRASS raster calculator I would isolate the desired elevation as a binary raster and then convert is as a polygon.

With two commands in GRASS console:

r.mapcalc expression="elevation_1km = if(elevation >=10000 , 1, null())"

and then make it a polygon

r.to.vect -v input=elevation_1km output=elevation_poly type=area
1

I found this to be a quick way to do this in R using the raster and sf (simple features) packages:

dem <- raster("location of dem")
contours <- rasterToContour(dem)
contours <- st_as_sf(contours )
contour.poly <- st_polygonize(contours)
contour.poly <- st_collection_extract(contour.poly )
st_cast(contour.poly, "MULTIPOLYGON")

once you have the contour.poly you can use any of the sf geometry operations. Also, you may want to reduce the resolution of the DEM else it will take ages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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