0

I'm trying to open ne_10m_urban_areas.shp with rgdal::readOGR, but it gives me the bellow error

library(rgdal)
a <- readOGR(dsn = path.expand("C:/.../Desktop/"),
layer = "ne_10m_urban_areas.shp")

> Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, :

> Cannot open layer

a <- shapefile("C:/.../Desktop/ne_10m_urban_areas.shp")

> Error: file.exists(extension(x, ".shx")) is not TRUE

file.exists("C:/.../Desktop/ne_10m_urban_areas.shp")

> [1] TRUE

  • All you need is the name of the shapefile so, remove ".shp" from the name of dataset. – Jeffrey Evans May 16 '18 at 21:25
2

This bit:

a <- shapefile("C:/.../Desktop/ne_10m_urban_areas.shp")
 Error: file.exists(extension(x, ".shx")) is not TRUE

tells us that there is no ne_10m_urban_areas.shx file - note the file extension SHX not SHP. A valid shapefile needs a .shp, a .shx and usually a .dbf file (as well as possible others). Do you have all those in the same folder? I don't think so. There's your problem.

0

It is also possible you don't have even read permissions over the folder you are trying to open a layer from. This problem is especially pesky if running stuff from a docker container. In order to give yourself permission just type:

chmod -R 777 /path/to/folder

in terminal.

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.