2

I have downloaded shapefile from Eurostat website (download site for downloading Eurostat shapefile and direct download link of Eurostat shapefile that I am interested in). To be short, I need shapefile of Germany' NUTS3 region only (general concept for NUTS3). To do so, I used rgdal package. Here is the R script down below:

library(rgdal)
library(sp)
library(maptools)

url = "http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/download/ref-nuts-2013-03m.shp.zip"
download.file(url, basename(url))
gunzip(basename(url))
rname <- list.files(getwd(), "shp$")

but I got following error anyway:

> eu <- readOGR(dsn = getwd(), layer ="NUTS_RG_03M_2013")
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv,  : 
  Cannot open layer

don't know why does this happen. Any quick solution? How can I fix this error?

If I fix this problem, I want to retrieve shapefile of only Germany's NUTS3 region (please take a look overview of NUTS3). To do so, I come up with following solution:

nuts2 <- subset(eu, STAT_LEVL_ == 2)
proj4string(nuts2)
coordinates(point_data) <- ~LON + LAT
proj4string(point_data) <- CRS("+proj=longlat +datum=WGS84")
point_data <- spTransform(point_data, proj4string(map_nuts2))
over(point_data, nuts2, by.id = TRUE)

My ultimate goal is to get Germany' NUTS3 level shapefile. How can I correct my above solution? How can I refine my above approach? Is there any more efficient and straightforward way to get certain countries' NUTS3 level shapefile? Any idea?

2

Quick solution? Check if filename exists!

library(rgdal)
library(sp)
library(maptools)

url = "http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/download/ref-nuts-2013-03m.shp.zip"
download.file(url, basename(url))
unzip(basename(url))
rname <- list.files(getwd(), "shp$")

# your method
eu <- readOGR(dsn = getwd(), layer ="NUTS_RG_03M_2013")
## Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv,  : 
##                    Cannot open layer

# another method
eu <- shapefile("NUTS_RG_03M_2013.shp")
## Error: file.exists(extension(x, ".shp")) is not TRUE

You have a lot of files with the same pattern name:

list.files(pattern = 'NUTS_RG_03M_2013.*.shp$')
## [1] "NUTS_RG_03M_2013_3035_LEVL_0.shp" "NUTS_RG_03M_2013_3035_LEVL_1.shp"
## [3] "NUTS_RG_03M_2013_3035_LEVL_2.shp" "NUTS_RG_03M_2013_3035_LEVL_3.shp"
## [5] "NUTS_RG_03M_2013_3035.shp"        "NUTS_RG_03M_2013_3857_LEVL_0.shp"
## [7] "NUTS_RG_03M_2013_3857_LEVL_1.shp" "NUTS_RG_03M_2013_3857_LEVL_2.shp"
## [9] "NUTS_RG_03M_2013_3857_LEVL_3.shp" "NUTS_RG_03M_2013_3857.shp"       
## [11] "NUTS_RG_03M_2013_4258_LEVL_0.shp" "NUTS_RG_03M_2013_4258_LEVL_1.shp"
## [13] "NUTS_RG_03M_2013_4258_LEVL_2.shp" "NUTS_RG_03M_2013_4258_LEVL_3.shp"
## [15] "NUTS_RG_03M_2013_4258.shp"        "NUTS_RG_03M_2013_4326_LEVL_0.shp"
## [17] "NUTS_RG_03M_2013_4326_LEVL_1.shp" "NUTS_RG_03M_2013_4326_LEVL_2.shp"
## [19] "NUTS_RG_03M_2013_4326_LEVL_3.shp" "NUTS_RG_03M_2013_4326.shp" 

One could be (for WGS 84 - EPSG 4326):

eu <- readOGR(dsn = getwd(), layer ="NUTS_RG_03M_2013_4326_LEVL_2")
Germany <- eu[eu@data$CNTR_CODE == "DE",]
plot(Germany)

enter image description here

| improve this answer | |
  • Please, one question at time – aldo_tapia May 9 '18 at 8:47
  • why there is no need for projection? Why there is no need to use spTransform and over utilities? Is your solution same with my second part of R script? – kim May 9 '18 at 9:28
  • No need for projection? Really? I recommend you to search for basic tutorials of GIS and R on the internet. spTransform is for re-project from one CRS to other. I can't write anything about over because I don't know what point_data is – aldo_tapia May 9 '18 at 10:14

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.