Skip to content

readOGR problem in Windows

5 messages · James Rooney, Alex Mandel, Michael Sumner

#
Dear List,

I have some code I have developed on a Mac that I'm trying to transfer onto a higher spec windows 8.1 machine and I am running into a problem with the readOGR function in rgdal.

My code is below. This works fine under Mac, but under windows readOGR gives me the error:
"Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, :
Cannot open file "

The rgdal version on the Mac is rgdal_0.8-16
whilst on Win 8.1 is rgdal 0.9-1

The preceding read.csv statement works just fine.
Any ideas anyone ?
Thanks,
James


Code:

library(rgdal)
library(rgeos)
library(maptools)
library(RColorBrewer)
library(classInt)
library(ggplot2)
library(INLA)


# Set working directory
setwd("/Users/james/Project Work")

source("R_Files/Ireland - General Functions/SA.data-prep.functions.R")

# Load soils databse
soils <- read.csv("Irish Data/NSDB_SA_kriged.csv", header=TRUE)

# Load shape files and data file
SA <- readOGR("./Irish Data/Processed Data/","SA.basic.analysis.shapes",TRUE)
#
On 12/23/2014 07:43 AM, James Rooney wrote:
^^ Pretty sure this line would fail on windows, so your code won't be
running in the correct directory when it gets to the readOGR later.
Windows absolute paths start with a drive letter.
Though you say this one works? odd?
No idea what Windows does with ./

Overall I think you need to verify the path that R is on, and that it
can actually see the files before it tries to load them.

Thanks,
Alex
#
Hi Alex,

Doh! I cut and paste the mac version. The windows version that is not working looks as below.
The read.csv's work no problem - but read OGR won't work even with absolute paths. So I think it is not related to directory paths unless readOGR is someone different in this regard.
James
Correct Code:

library(rgdal)
library(rgeos)
library(maptools)
library(RColorBrewer)
library(classInt)
library(ggplot2)
library(INLA)


# Set working directory
#setwd("/Users/james/Project Work/ALS Spatial - Advanced")
setwd("C:/Users/james/Project Work/ALS Spatial - Advanced")

source("R_Files/Ireland - General Functions/SA.data-prep.functions.R")

# Load soils databse
soils <- read.csv("Irish Data/Soil Database/NSDB_SA_kriged.csv", header=TRUE)

# Load shape files and data file
SA <- readOGR("./Irish Data/Processed Data/","SA.basic.analysis.shapes",TRUE)
df <- read.csv("./Irish Data/Processed Data/SA.basic.analysis.data.csv", header=TRUE)
SA at data = data.frame(SA at data, df[match(SA at data$SA_CODE, df$SA_CODE),])
#
Try removing the trailing slash from the dsn path.

HTH
On Wed, 24 Dec 2014 06:38 James Rooney <ROONEYJ4 at tcd.ie> wrote:

            

  
  
#
Fantastic! That fixed it.

Thanks much appreciated!
James