Cannot load shapefile with readOGR - ogrInfo: all features NULL


#1

Hi,

I'm trying to plot some maps. I've downloaded some shapefiles but cannot read them with "readOGR" function.

I've installed "libdgal" and "libproj-dev".

sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev

But when using:

library(rgdal)     # R wrapper around GDAL/OGR
library(ggplot2)   # for general plotting
library(ggmap)    # for fortifying shapefiles

# First read in the shapefile, using the path to the shapefile and the shapefile name minus the
# extension as arguments
shapefile <- readOGR("/home/ogonzales/Escritorio/maps_in_r/", "BAS_LIM_DEPARTAMENTO")

I get this error:

Error in readOGR("/home/ogonzales/Escritorio/maps_in_r/", "BAS_LIM_DEPARTAMENTO") : 
  no features found
Además: Warning message:
In ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv,  :
  ogrInfo: all features NULL

This is the message I get after loading "rgdal" package:

library(rgdal)     # R wrapper around GDAL/OGR
Loading required package: sp
rgdal: version: 1.3-2, (SVN revision 755)
 Geospatial Data Abstraction Library extensions to R successfully loaded
 Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
 Path to GDAL shared files: /usr/share/gdal/2.2
 GDAL binary built with GEOS: TRUE 
 Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
 Path to PROJ.4 shared files: (autodetected)
 Linking to sp version: 1.2-7

Path of file:

The file's path is correct:

list.files('/home/ogonzales/Escritorio/maps_in_r/', pattern='\\.shp$') #"BAS_LIM_DEPARTAMENTO.shp"
file.exists('/home/ogonzales/Escritorio/maps_in_r/BAS_LIM_DEPARTAMENTO.shp') #TRUE

#2

Try sf::read_sf - but if the features are empty there's not much to do, what are you expecting from the shapefile/s?

Do make sure there is more than the .shp, it needs .dbf and .shx and hopefully .prj and there may be other files, shapefile is not a single-file format.