0

I am trying to load a Shapefile using readShapeSpatial() but I get the error

"Error in readShapeSpatial(shp) : File type cannot be read" .

Any ideas on what is going wrong here? Here is my code with the shapefile I'm using, which comes from the 2010 Brazilian Population Census.

# Load Libraries
library(maptools)
library(rgdal)

# Set Working Directory
setwd("C:/Users/rafa/Desktop/test_shape")

# Download official shape files 
download.file("ftp://geoftp.ibge.gov.br/malhas_digitais/censo_2010/setores_censitarios/rj.zip", "SetorCensitario_2010_Rio.zip", quiet = FALSE)

# Unzip files
unzip("SetorCensitario_2010_Rio.zip", exdir="SetorCensitario_2010_Rio")

# Load shapefile using `readShapeSpatial`
shp<- "C:/Users/rafa/Desktop/test_shape/SetorCensitario_2010_Rio/rj/33MUE250GC_SIR.shp"
shp <- readShapeSpatial(rioshape, proj4string = CRS("+proj=longlat +datum=WGS84"))

The strange part is that I can load the file using readOGR from package rgdal

shp <- readOGR(dsn="./SetorCensitario_2010_Rio/rj", layer="33MUE250GC_SIR")
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
rafa.pereira
  • 13,251
  • 6
  • 71
  • 109
  • Remove the `.shp` extension – maccruiskeen Jul 25 '15 at 14:51
  • 3
    If you look at the source for `readShapeSpatial` you'll see it doesn't support "PointM", "PolyLineM", PolygonM", "MultiPointM" shapes. `readShapePoly` will show you that it's a `Shapefile type: PolygonM (25), # of Shapes: 293` file but still not read it. GDAL is far more flexible, hence `readOGR` is able to read the shapefile when the `maptools` functions cannot. – hrbrmstr Jul 25 '15 at 14:59
  • did you try that @choff? – hrbrmstr Jul 25 '15 at 15:02
  • Just tried now, but no help. I think `readOGR` is the way to go. – maccruiskeen Jul 25 '15 at 15:04

0 Answers0