[R-SIG-Mac] Mac-only problem using readOGR() to read a shapefile from a directory on a USB pen drive

D G. Rossiter d.g.rossiter at cornell.edu
Sat Mar 4 12:40:21 CET 2017


Thanks to Ken Beath, this indeed was the problem. I tested by formatting a USB drive to Mac format with Disk Info, copying the shapefiles onto it, and then reading with readOGR().

Problem solved, although the Mac-formatted USB drive could not be used to transfer files to and from Windows machines.

D G (David) Rossiter
Section of Soil & Crop Sciences
Cornell University
http://www.css.cornell.edu/faculty/dgr2/


  1. Re:  Mac-only problem using readOGR(), which uses ogrInfo(),
     to read a shapefile from a directory on a USB pen drive (Ken Beath)

From: Ken Beath <ken at kjbeath.com.au<mailto:ken at kjbeath.com.au>>
Subject: Re: [R-SIG-Mac] Mac-only problem using readOGR(), which uses ogrInfo(), to read a shapefile from a directory on a USB pen drive
Date: 3 March 2017 at 20:28:33 GMT-5
To: "D G. Rossiter" <d.g.rossiter at cornell.edu<mailto:d.g.rossiter at cornell.edu>>
Cc: "r-sig-mac at r-project.org<mailto:r-sig-mac at r-project.org>" <r-sig-mac at r-project.org<mailto:r-sig-mac at r-project.org>>


My thought is that it might be that USB drives are usually MSDOS formatted. Usually not a problem but rgdal works with directories. Formatting  in a Mac with Disk Utility might be a work-around, with the limitation that the USB will only work in Macs.

I would also try verbose=TRUE which may give more information.

In the absence of other ideas contacting the package author can help.

Ken

On 4 Mar 2017, at 3:32 am, D G. Rossiter <d.g.rossiter at cornell.edu<mailto:d.g.rossiter at cornell.edu>> wrote:

I ran across a Mac-only problem using readOGR(), which uses ogrInfo(), to read a shapefile from a directory on a USB pen drive. I tested the behaviour on a Windows 10 machine and did not get the problem.

Trying to read from the USB drive, with relative and full paths:

setwd("/Volumes/ISPRS/“) # this is my connected USB drive
list.files()
[1] "map7100.dbf"                      "map7100.prj"
[3] "map7100.sbn"                      "map7100.sbx"
[5] "map7100.shp"                      "map7100.shp.xml"
[7] "map7100.shx"
file.exists("map7100.shp")
[1] TRUE
usa <- readOGR(dsn=".", layer="map7100")
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv,  :
Cannot open data source
usa <- readOGR(dsn="/Volumes/ISPRS", layer="map7100")
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv,  :
Cannot open data source

But, readOGR reads the shapefile correctly if it’s located on the Mac’s internal drive:

setwd("/Users/rossiter/data/edu/dgeostats/ex")
file.exists("./ds/NEweather/map7100.shp")
[1] TRUE
usa <- readOGR(dsn="./ds/NEweather", layer="map7100")
OGR data source with driver: ESRI Shapefile
Source: "./ds/NEweather", layer: "map7100"
with 7926 features
It has 19 fields

All packages are up to date. Here is the sessionInfo():

R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X El Capitan 10.11.6

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] ggplot2_2.2.1  sf_0.3-4       maptools_0.9-1 rgdal_1.2-5
[5] sp_1.2-4       gstat_1.1-4

loaded via a namespace (and not attached):
[1] Rcpp_0.12.9      plyr_1.8.4       xts_0.9-7        tools_3.3.2
[5] digest_0.6.12    evaluate_0.10    tibble_1.2       gtable_0.2.0
[9] lattice_0.20-34  DBI_0.5-1        yaml_2.1.14      stringr_1.2.0
[13] knitr_1.15.1     rprojroot_1.2    grid_3.3.2       spacetime_1.2-0
[17] foreign_0.8-67   rmarkdown_1.3    udunits2_0.13    magrittr_1.5
[21] backports_1.0.5  scales_0.4.1     intervals_0.15.1 htmltools_0.3.5
[25] units_0.4-2      rsconnect_0.7    assertthat_0.1   colorspace_1.3-2
[29] labeling_0.3     stringi_1.1.2    lazyeval_0.2.0   munsell_0.4.3
[33] FNN_1.1          zoo_1.7-14

This is a problem because several of my students have OS/X machines and like to work from USB-connected external drives.

D G (David) Rossiter
Section of Soil & Crop Sciences
Cornell University
http://www.css.cornell.edu/faculty/dgr2/

_______________________________________________
R-SIG-Mac mailing list
R-SIG-Mac at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-mac




_______________________________________________
R-SIG-Mac mailing list
R-SIG-Mac at r-project.org<mailto:R-SIG-Mac at r-project.org>
https://stat.ethz.ch/mailman/listinfo/r-sig-mac


	[[alternative HTML version deleted]]



More information about the R-SIG-Mac mailing list