[R-sig-Geo] Import raster from ArcGIS - mismatch between original GRID and raster in R
Rainer M Krug
r.m.krug at gmail.com
Wed Dec 7 10:01:45 CET 2011
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 07/12/11 00:48, Jenn.B wrote:
> 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.
Where does the "resampling" occur, because as far as I am aware, an
import does not do any resampling.
I would suggest to track down where in your code this occurs.
Just to be save: what about projections - are they the same?
Also: try something like qgis or GRASS to visualize your data and see
if they are as you expect them to be.
Also: can you provide a subset of your data (the site which is on land
but should be on water, and the underlying clipped raster map) so that
the example is reproducible?
Cheers,
Rainer
>
> 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.
>
> _______________________________________________ R-sig-Geo mailing
> list R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
- --
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)
Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa
Tel : +33 - (0)9 53 10 27 44
Cell: +33 - (0)6 85 62 59 98
Fax : +33 - (0)9 58 10 27 44
Fax (D): +49 - (0)3 21 21 25 22 44
email: Rainer at krugs.de
Skype: RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk7fK3kACgkQoYgNqgF2egqqHACeKOhX7UqT093oGZc6sdosJpgB
XEMAn2y7UFx19D9RKbGxwvZo5sehJk+b
=2+GL
-----END PGP SIGNATURE-----
More information about the R-sig-Geo
mailing list