rgis

How can I download GADM data in R?


library(raster)   
france<-getData('GADM', country='FRA', level=1)

However, the command is leading me to this error.

trying URL 'http://biogeo.ucdavis.edu/data/gadm2.8/rds/FRA_adm1.rds'
Error in utils::download.file(url = aurl, destfile = fn, method = "auto",  : 
  cannot open URL 'http://biogeo.ucdavis.edu/data/gadm2.8/rds/FRA_adm1.rds'

Solution

  • First, download the country data you want from the GADM database, and save it to your local directory. Be sure that you have chosen the R (SpatialPolygonsDataFrame) format. There are five levels available for France (from level 0 to level 5). You can choose what you need.

    Second, read the .rds file downloaded from GADM with readRDS() function and transform it into a data.frame with ggplot2::fortify().

    library(ggplot2)
    library(sp)
    # assumed that you downloaded into a such path: '~/Downloads/FRA_adm1.rds':
    path <- file.path(Sys.getenv("HOME"), "Downloads", "FRA_adm1.rds")
    # FR map (Level 1) from GADM version 2.8
    frRDS <- readRDS(path)
    # Region names 1 in data frame
    frRDS_df <- ggplot2::fortify(frRDS, region = "NAME_1")
    head(frRDS_df)