Free SRTM elevation data in R – getData function
In this post, we show how to use the getData function of the well-known raster package to retrieve SRTM data. The function allows you to retrieve data from three free databases:
- ‘SRTM’ – elevation data from SRTM missions, also available at: http://srtm.csi.cgiar.org/
- ‘GADM’ – global database of administrative boundaries of countries. More at https://gadm.org/,
- ‘worldclim’ – global database of gridded climate data. More at http://www.worldclim.org/.
We are interested in the database of elevation data defined as ‘SRTM’. SRTM data is stored in 5 x 5 degree tiles. In order to retrieve the data using the function, it is also necessary to define the geographical coordinates of the object of interest, e.g. latitude 52 degrees and longitude 21 degrees. Our function should look like this:
dem <- getData("SRTM",lon=21,lat=52)
A tile containing the specified coordinates is downloaded directly from the page to our computer:
> dem class : RasterLayer dimensions : 6001, 6001, 36012001 (nrow, ncol, ncell) resolution : 0.0008333333, 0.0008333333 (x, y) extent : 19.99958, 25.00042, 49.99958, 55.00042 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 data source : d:/Program Files/RStudio/srtm_41_02.tif names : srtm_41_02 values : -32768, 32767 (min, max)
Let’s see what the downloaded file looks like:
plot(dem)
To learn how to retrieve data from other databases, see the documentation for the getData function. We will just tell you that you can get different detailed data for the other two databases. Have fun learning 🙂