14 Oct

Get administrative, topographic and climatic data directly in R

This post shows some examples of the function  getData into the Raster package. This function  allows to directly download data from 3 global datasets (Administrative bordersAltitude, Climate). This will be shown for a country (Belgium). The code is below.

Administrative borders  (from GDMA dataset) is available at 5 country sub-levels

1AdminAltitude (from the SRTM dataset) at 90m of resolution

2AltitudeClimate (available from worldclim at 0.5 minute of degree corresponding to 5.5 km of spatial resolution in Belgium)

Mean precipitations by month31Precipitations     Annual mean temperature32MeanTemperature

# 1/ ADMINISTRATIVE BORDERS
## Get Adminstrative boundaries data at 5 different level from (GADM)
# polygons for all countries at a higher resolution than the 'wrld_simpl' data in the maptools pacakge
 
admin_bel_l0<-getData('GADM',country='BEL',level=0)
admin_bel_l1<-getData('GADM',country='BEL',level=1)
admin_bel_l2<-getData('GADM',country='BEL',level=2)
admin_bel_l3<-getData('GADM',country='BEL',level=3)
admin_bel_l4<-getData('GADM',country='BEL',level=4)
 
par(mfrow=c(1,5))
plot(admin_bel_l0,zcol='NAME_ISO',main='level 0')
title("level 0")
plot(admin_bel_l1,zcol='ISO',main='level 1')
title("level 1")
plot(admin_bel_l2,zcol='ISO',main='level 2')
title("level 2")
plot(admin_bel_l3,zcol='ISO',main='level 3')
title("level 3")
plot(admin_bel_l4,zcol='ISO',main='level 4')
title("level 4")
 
# 2/ ALTITUDE
## Get SRTM data (90m)
par(mfrow=c(1,2))
r_alt<-getData('alt',country="BEL")
plot(r_alt,main= 'altitude')
hist(r_alt,main= 'altitude distribution' )
 
# 3/ CLIMATE 
# 3.1/ MEAN PRECIPITATIONS BY MONTH
#Get climatic data (from http://www.worldclim.org) 'tmin', 'tmax', 'prec', 'bio'
r_prec<-getData('worldclim', var='prec',res=0.5, lon=4.35, lat=50.8)
levelplot(r_prec)
plot(admin_bel_l0,ext=admin_bel_l0,zcol='NAME_ISO',add=T)
 
idx <- seq(1, 12)
r_prec_crop<-crop(r_prec,admin_bel_l0)
r_prec_crop_z <- setZ(r_prec_crop, idx)
names(r_prec_crop_z) <- month.abb
 
myTheme=rasterTheme(region=rev(sequential_hcl(10, power=1)))
p<-levelplot(r_prec_crop_z, par.settings=myTheme)
p + layer(sp.polygons(admin_bel_l2, lwd=0.8, col='black'))
 
 
# 3.2/ ANNUAL MEAN TEMPERATURE
r_bio<-getData('worldclim', var='bio',res=0.5, lon=4.35, lat=50.8) #resolution is in minute of degree
# (0.5 minutes is about 5.56 km in Belgium ans is the finest resolution available from worldclim)
 
# there are 12 (monthly) files for each variable except for 'bio' which contains 19 files
# BIO1 = Annual Mean Temperature
# BIO2 = Mean Diurnal Range (Mean of monthly (max temp - min temp))
# BIO3 = Isothermality (BIO2/BIO7) (* 100)
# BIO4 = Temperature Seasonality (standard deviation *100)
# BIO5 = Max Temperature of Warmest Month
# BIO6 = Min Temperature of Coldest Month
# BIO7 = Temperature Annual Range (BIO5-BIO6)
# BIO8 = Mean Temperature of Wettest Quarter
# BIO9 = Mean Temperature of Driest Quarter
# BIO10 = Mean Temperature of Warmest Quarter
# BIO11 = Mean Temperature of Coldest Quarter
# BIO12 = Annual Precipitation
# BIO13 = Precipitation of Wettest Month
# BIO14 = Precipitation of Driest Month
# BIO15 = Precipitation Seasonality (Coefficient of Variation)
# BIO16 = Precipitation of Wettest Quarter
# BIO17 = Precipitation of Driest Quarter
# BIO18 = Precipitation of Warmest Quarter
# BIO19 = Precipitation of Coldest Quarter
 
# NOTE: Temperature data is in units of °C * 10 
par(mfrow=c(1,2))
plot(r_bio$bio1_16/10,ext=admin_bel_l0,main="Annual Mean Temperature")
plot(admin_bel_l0,ext=admin_bel_l0,zcol='NAME_ISO',add=T)
hist(r_bio$bio1_16/10, main="")

One thought on “Get administrative, topographic and climatic data directly in R

  1. Hi there. This looks like an amazing resource. Thank you for making it available. I am looking for a way to produce a raster map that includes a histogram that shares the same color-ramp. In other words, has anyone made code available that would take the Mean Annual Temperature map and histogram above, but where the histogram bars are color-ramped such that they matched the map. This seems like a very useful legend for maps, but I am having a hard time finding anyone who has produced such figures. Thank you!
    Travis

Leave a Reply

Your email address will not be published. Required fields are marked *