[R-sig-Geo] Import raster from ArcGIS - mismatch between original GRID and raster in R
Jenn.B
jsbarret at sfu.ca
Wed Dec 7 00:48:33 CET 2011
Hi everyone,
I'm an advanced ArcGIS user, but new to doing all things spatial in R (I
typically only use R for graphing and regressions). That said:
I've written some code to calculate shortest paths between nest sites and
foraging locations, following water only (water coded as 1, all other cells
= 0) The loop works fine; however, my problem is in the initial import of
the GRID into R using raster().
In running my loop, I received the error:
"In get.shortest.paths(adjacencyGraph, indexOrigin, indexGoal) :
At structural_properties.c:4277 :Couldn't reach some vertices"
for one of my nests, which I understand to mean that the particular nest and
foraging location that the loop is currently processing are not connected.
However, they ARE connected in my ArcGIS GRID (i.e., they both lie on water
cells with no gaps between them). After a little investigating I noticed
that the GRID gets resampled when imported into R, such that my location,
which is near land, now falls on land (and thus not on a value cell). How
can I avoid this? Is there some argument I can apply to "snap" the raster to
the original GRID? This is a serious problem, as I imagine I'll encounter
the same issue for other nests and foraging locations that the loop has yet
to process.
The code for one nest and location looks like:
library(gdistance)
library(maptools)
# Import raster layer - ocean + freshwater = 1, land = NoData
r.CS<- raster ("C:/myfile")
# Create transition layer
t.CS<- transition(r.CS, transitionFunction=mean, directions=16)
tc.CS<- geoCorrection(t.CS)
# Import nest and forage locations
setwd("C:/ForR")
nest1<-read.csv("nest1.csv")
radio1<-read.csv("radio1.csv")
# Extract X and Y
nestXY<- cbind(nest1$X, nest1$Y)
radioXY<-cbind(radio1$X, radio1$Y)
# Create Spatial Points objects - for radio, just do first location for
testing...
SpRadio<-SpatialPoints(radioXY)
SpRadio
SpNest<-SpatialPoints(nestXY)
#Calculate the shortest path
sPathL<-shortestPath(tc.CS, SpNest, SpRadio, output="SpatialLines")
distance<-SpatialLinesLengths(sPathL, longlat=FALSE)
Apologies if any of this is unclear. If you're interested in the loop, I can
post that as well - it basically just involves a bunch of subsetting and
writing outputs for different nests to different files.
Cheers,
Jenn
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Import-raster-from-ArcGIS-mismatch-between-original-GRID-and-raster-in-R-tp7068880p7068880.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
More information about the R-sig-Geo
mailing list