Search code examples
rgdalshapefilergdal

Cannot load a shapefile in R "Error: no features found"


I'm trying to read the shapefile that you can download with this url.

I have a code similar to the next one to download automatically the files:

library("raster")}
url<-"http://www6.gipuzkoa.eus/CATASTRO/Planos/ZIP-A098.zip"
downloader::download(url, dest=paste0(getwd(),"/","my_file.zip"), mode="wb",quiet=T)

zipped_shape_names<-c("098_HELBIDE_SHP/ATRIBUTOAK-A098.cpg","098_HELBIDE_SHP/ATRIBUTOAK-A098.dbf","098_HELBIDE_SHP/ATRIBUTOAK-A098.shp","098_HELBIDE_SHP/ATRIBUTOAK-A098.shx")

unzip("my_file.zip", files=zipped_shape_names)
my_shape<-raster::shapefile("098_HELBIDE_SHP/ATRIBUTOAK-A098.shp")

But what I obtain is the following error:

Error in rgdal::readOGR(dirname(x), fn, stringsAsFactors = stringsAsFactors,  : 
  no features found
In addition: Warning messages:
1: In .local(x, ...) : .prj file is missing
2: In ogrFIDs(dsn = dsn, layer = layer) : no features found

You can access to the original web page by this link and pressing "Descargar planos"

I don't have this problem with others areas, just with this and another one, but I don't know what is happening with this specific area.

Any help will be appreciated.


Solution

  • The error message is quite clear. no features found means that your shapefile is empty. You can check this in multiple ways.

    One is to add your shapefile in Q-Gis or any other GIS-software tool. In the case of Q-GIS your shapefile will pop-up in the layers pane, but you won't see any features.

    It is also possible to check the .dbf file in R:

    library(foreign)
    read.dbf("098_HELBIDE_SHP/ATRIBUTOAK-A098.dbf")
    

    The .dbf should contain as many rows as there are features. In your case None.