[R-sig-Geo] Error in reading shape file with readOGR()

Roger Bivand Roger.Bivand at nhh.no
Tue Jan 27 21:57:33 CET 2015


On Tue, 27 Jan 2015, Amos Thairu wrote:

> That works!
> It seems that readOGR() does not expand the ~ and thus requires the full
> expanded path.

The reason for not expanding is that the dsn= argument takes very 
different string values depending on the driver, but as the driver is 
discovered in OGR itself, we can't say that we know that it is going to be 
a file or directory, for example for PostGIS or WFS.

Hope this clarifies,

Roger

> Thanks!
>
> On 27 January 2015 at 17:13, Frede Aakmann Tøgersen <frtog at vestas.com>
> wrote:
>
>> Hi Amos
>>
>> Some time ago since I have used readOGR() but I vaguely remember that
>> readOGR() does not expand the ~ as e.g. list.files does. You need to give
>> the full expanded path like something like this:
>>
>> "/home/my_username/datasets/mapping"
>>
>> which of course depends on the system setup (I'm guessing you are on a
>> unix-alike system based on the path to gdal installation). Cannot remember
>> if a relative path works.
>>
>>
>> Yours sincerely / Med venlig hilsen
>>
>>
>> Frede Aakmann Tøgersen
>> Specialist, M.Sc., Ph.D.
>> Plant Performance & Modeling
>>
>> Technology & Service Solutions
>> T +45 9730 5135
>> M +45 2547 6050
>> frtog at vestas.com
>> http://www.vestas.com
>>
>> Company reg. name: Vestas Wind Systems A/S
>> This e-mail is subject to our e-mail disclaimer statement.
>> Please refer to www.vestas.com/legal/notice
>> If you have received this e-mail in error please contact the sender.
>>
>>
>> > -----Original Message-----
>> > From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of
>> > Amos Thairu
>> > Sent: 27. januar 2015 14:50
>> > To: r-sig-geo at r-project.org
>> > Subject: [R-sig-Geo] Error in reading shape file with readOGR()
>> >
>> > I am trying to import a shapefile using readOGR below:
>> > > dataProjected <- readOGR(dsn="~/datasets/mapping", layer="locations")
>> >
>> > But I am facing the following error:
>> > Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding,
>> use_iconv =
>> > use_iconv,  :
>> >   Cannot open file
>> >
>> > I have successfully loaded the same shapefile using readOGR in my windows
>> > platform but cannot read that same file
>> > using the same command in a linux platform. I guess the problem seems to
>> > be
>> > related to having uploaded the
>> > .shp and its associated files from a Windows machine onto the linux
>> > platform.
>> >
>> > The directory with the shape file is complete with the associated files
>> as
>> > shown below:
>> > > list.files("~/datasets/mapping")
>> > [1] "locations-c.dta"   "locations-d.dta"   "locations.dbf"
>> > "locations.prj"     "locations.sbn"
>> > [6] "locations.sbx"     "locations.shp"     "locations.shp.xml"
>> > "locations.shx"
>> >
>> > I get the following package startup message:
>> > > library(rgdal)
>> > Loading required package: sp
>> > rgdal: version: 0.9-1, (SVN revision 518)
>> > Geospatial Data Abstraction Library extensions to R successfully loaded
>> > Loaded GDAL runtime: GDAL 1.7.3, released 2010/11/10
>> > Path to GDAL shared files: /usr/share/gdal
>> > GDAL does not use iconv for recoding strings.
>> > Loaded PROJ.4 runtime: Rel. 4.7.1, 23 September 2009, [PJ_VERSION: 470]
>> > Path to PROJ.4 shared files: (autodetected)
>> >
>> > My session info is as follows:
>> > > sessionInfo()
>> > R version 3.1.2 (2014-10-31)
>> > Platform: x86_64-redhat-linux-gnu (64-bit)
>> >
>> > locale:
>> > [1] C
>> >
>> > attached base packages:
>> > [1] stats     graphics  grDevices utils     datasets  methods   base
>> >
>> > other attached packages:
>> > [1] rgdal_0.9-1 sp_1.0-17
>> >
>> > loaded via a namespace (and not attached):
>> > [1] grid_3.1.2      lattice_0.20-29 tools_3.1.2
>> >
>> > Does anyone know why this is happening? Any assistance would be greatly
>> > appreciated.
>> >
>> > --
>> > Regards,
>> > Amos Mbugua.
>> >
>> >       [[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
>>
>
>
>
> -- 
> Regards,
> Amos Mbugua.
>
> 	[[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
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: Roger.Bivand at nhh.no


More information about the R-sig-Geo mailing list