[R-sig-Geo] readOGR problem in Windows

James Rooney ROONEYJ4 at tcd.ie
Tue Dec 23 20:34:56 CET 2014


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),])


________________________________________
From: Alex Mandel [tech_dev at wildintellect.com]
Sent: 23 December 2014 16:43
To: James Rooney; r-sig-geo at r-project.org
Subject: Re: [R-sig-Geo] readOGR problem in Windows

On 12/23/2014 07:43 AM, James Rooney wrote:
> 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")
>
^^ 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.

> 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)
>
Though you say this one works? odd?

> # Load shape files and data file
> SA <- readOGR("./Irish Data/Processed Data/","SA.basic.analysis.shapes",TRUE)
>
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



More information about the R-sig-Geo mailing list