[R-sig-Geo] Problems reading shapefiles in R

Roger Bivand Roger.Bivand at nhh.no
Mon Apr 11 09:54:43 CEST 2011


On Sun, 10 Apr 2011, Felipe Carrillo wrote:

> Mr Bivand, that's not unmotivated advice and I am not trying to mislead 
> anybody. That exact thing that Manuel is describing happened to me and 
> it got fixed by removing the rgeos package from my library.

Then please respect the implicit contract in all use of open source 
software! Please inform the maintainer of the packages (me) with a fully 
reproducible case, so that we may benefit from your discovery by 
identifying and removing the cause.

As I stated, both rgeos and maptools are thoroughly tested on multiple 
platforms, so your diagnosis seems unlikely, but the way you repay those 
who write and maintain the software you benefit from is by documenting and 
reporting irregularities.

Until I receive your reproducible case, I will assert that your problem is 
caused by something else, specific to your platform and installation, and 
that your advice is inappropriate with repect to the problem reported by 
the original poster:

library(maptools)
dir <- system.file("shapes", package="maptools")
file.copy(paste(dir, "sids.shp", sep="/"), td)
file.copy(paste(dir, "sids.shx", sep="/"), td)
sids <- readShapeSpatial(paste(td, "sids.shp", sep="/"))
sids <- readShapeSpatial(paste(td, "sids", sep="/"))
sids <- readShapePoly(paste(td, "sids.shp", sep="/"))
library(rgdal)
sids <- readOGR(td, "sids")

(missing DBF file) reproduce the error messages correctly (maptools 
0.8-6). I get a different error message from rgdal (0.6-36) with GDAL 
1.8.0, but as we have neither the output of sessionInfo() from the 
original poster, not the version information printed by rgdal on load, the 
difference may be from a different version of GDAL. Would the original 
poster see different error messages after running update.packages()?

Roger

>  
> Felipe D. Carrillo
> Supervisory Fishery Biologist
> Department of the Interior
> US Fish & Wildlife Service
> California, USA
> http://www.fws.gov/redbluff/rbdd_jsmp.aspx
>
>
>
>
> ----- Original Message ----
>> From: Roger Bivand <Roger.Bivand at nhh.no>
>> To: Felipe Carrillo <mazatlanmexico at yahoo.com>
>> Cc: Manuel Spínola <mspinola10 at gmail.com>; r-sig-geo at r-project.org
>> Sent: Sun, April 10, 2011 12:15:51 PM
>> Subject: Re: [R-sig-Geo] Problems reading shapefiles in R
>> 
>> On Sun, 10 Apr 2011, Felipe Carrillo wrote:
>> 
>> > Manuel:
>> > As a test, delete the rgeos package from your library and run one of the
>> > commands again. You can always install the package back if you need it.
>> 
>> Please do not give unmotivated advice on the list, as it will mislead. 
>> There is no interaction between rgeos and functions for reading vector 
>> objects - if you believe otherwise, please report this with a reproducible 
>> case. Bad advice is worse than no advice.
>> 
>> The obvious place to check is:
>> 
>> list.files(path="C:/ProyectosRespacial/ICE/SIG_Biotica_PHED",
>>   pattern="AI_BIOTICA_010411_CRTM05")
>> 
>> which must show at least:
>> 
>> "AI_BIOTICA_010411_CRTM05.dbf" "AI_BIOTICA_010411_CRTM05.shp" 
>> "AI_BIOTICA_010411_CRTM05.shx"
>> 
>> for "AI_BIOTICA_010411_CRTM05" to be a shapefile. The error messages show 
>> that "AI_BIOTICA_010411_CRTM05.dbf" is missing, so please check that it is 
>> present first.
>> 
>> Hope this clarifies,
>> 
>> Roger
>> 
>> >  
>> > Felipe D. Carrillo
>> > Supervisory Fishery Biologist
>> > Department of the Interior
>> > US Fish & Wildlife Service
>> > California, USA
>> > http://www.fws.gov/redbluff/rbdd_jsmp.aspx
>> >
>> >
>> >
>> >
>> > ----- Original Message ----
>> >> From: Manuel Spínola <mspinola10 at gmail.com>
>> >> To: r-sig-geo at r-project.org
>> >> Sent: Sun, April 10, 2011 9:54:20 AM
>> >> Subject: [R-sig-Geo] Problems reading shapefiles in R
>> >>
>> >> Dear list members,
>> >>
>> >> I am trying to read a shapefile in R using 3 different methods and all of
>> >> them failed:
>> >>
>> >>> ai_biotica <- readOGR(dsn="C:/ProyectosRespacial/ICE/SIG_Biotica_PHED",
>> >> layer="AI_BIOTICA_010411_CRTM05")
>> >> Error in ogrInfo(dsn = dsn, layer = layer, input_field_name_encoding =
>> >> input_field_name_encoding) :
>> >>
>> >>         GDAL Error 4: Unable to open
>> >> 
>> C:/ProyectosRespacial/ICE/SIG_Biotica_PHED\carretera_interamericana_CRTM05.shx
>> >> or
>> >>
>> > 
>> C:/ProyectosRespacial/ICE/SIG_Biotica_PHED\carretera_interamericana_CRTM05.SHX.
>> >>
>> >>> nc1 <-
>> >> 
>> readShapePoly("C:/ProyectosRespacial/ICE/Shapefiles/AI_BIOTICA_010411_CRTM05.shp",
>>
>> >> ,
>> >> proj4string=CRS("+proj=tmerc +lon_0=-84 +lat_0=0 +x_0=500000 +k=0.9999
>> >> +datum=WGS84"))
>> >> Error in read.dbf(filen1) : unable to open DBF file
>> >>
>> >>
>> >>> ai_biotica <- readShapeSpatial("AI_BIOTICA_010411_CRTM05")
>> >> Error in read.dbf(filen1) : unable to open DBF file
>> >>
>> >> I will appreciate any input on the problem.
>> >>
>> >> Best,
>> >>
>> >> Manuel Spínola
>> >>
>> >>
>> >>
>> >> --
>> >> *Manuel Spínola, Ph.D.*
>> >> Instituto Internacional en Conservación y Manejo de Vida Silvestre
>> >> Universidad Nacional
>> >> Apartado 1350-3000
>> >> Heredia
>> >> COSTA RICA
>> >> mspinola at una.ac.cr
>> >> mspinola10 at gmail.com
>> >> Teléfono: (506) 2277-3598
>> >> Fax: (506) 2237-7036
>> >> Personal website: Lobito de río 
> <https://sites.google.com/site/lobitoderio/>
>> >> Institutional website: ICOMVIS <http://www.icomvis.una.ac.cr/>
>> >>
>> >>     [[alternative HTML version deleted]]
>> >>
>> >>
>> >
>> > _______________________________________________
>> > R-sig-Geo mailing list
>> > R-sig-Geo at r-project.org
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> >
>> 
>> -- 
>> Roger Bivand
>> Economic Geography Section, Department of Economics, Norwegian School of
>> Economics and Business Administration, Helleveien 30, N-5045 Bergen,
>> Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
>> e-mail: Roger.Bivand at nhh.no
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no


More information about the R-sig-Geo mailing list