[R-sig-Geo] gdistance: costDistance with barriers

Karl Jarvis karljarvis at gmail.com
Fri Mar 13 00:47:32 CET 2015


Great! Thank you all. 

> On Mar 12, 2015, at 4:35 PM, Jacob van Etten <jacobvanetten at yahoo.com> wrote:
> 
> Robert is right. This example visualizes what is happening.
> 
> library(gdistance)
> r <- raster(nrows=18, ncols=36) 
> r[] <- 1
> x <- transition(r,function(x) 1/mean(x),4)
> origin <- c(-120,0)
> goal <- c(120,0)
> sl <- shortestPath(x, origin, goal)
> plot(raster(sl))
> 
> 
> On Thursday, 12 March 2015, 14:50, Robert J. Hijmans <r.hijmans at gmail.com> wrote:
> 
> 
> Karl,
> 
> You are using a default RasterLayer which has lon/lat coordinates. In
> that case the earth is considered spherical (or similar), not a plane.
> The maximum possible distance in longitude is 180 degrees, and the
> distance between -120 and 120 is not 240 degrees, but 60+60= 120
> degrees, .
> 
> To get the results I think you expected, use a planar CRS. For example
> r <- raster(nrows=18, ncols=36, crs='+proj=utm +zone=10')
> 
> Robert
> 
> On Thu, Mar 12, 2015 at 11:35 AM, karljarvis <karljarvis at gmail.com <mailto:karljarvis at gmail.com>> wrote:
> > Hi all,
> > I am seeing confusing behavior from the costDistance function in gdistance.
> > In general, when cost is constant, cost distance increases linearly with
> > actual distance. However, in this example, it is not doing that for the
> > longest few distances. Am I missing something?
> > Karl
> >
> > r <- raster(nrows=18, ncols=36)
> > r[] <- 1
> > t <- transition(r,function(x) 1/mean(x),4)
> > p <- cbind(seq(-120,120,by=40),rep(0,7))
> > costDistance(t,p)
> >
> >> costDistance(t,p)
> >    1  2  3  4  5  6
> > 2  4
> > 3  8  4
> > 4 12  8  4
> > 5 16 12  8  4
> > 6 16 16 12  8  4
> > 7 12 16 16 12  8  4
> >
> >
> >
> > --
> > View this message in context: http://r-sig-geo.2731867.n2.nabble.com/gdistance-costDistance-with-barriers-tp7587891.html <http://r-sig-geo.2731867.n2.nabble.com/gdistance-costDistance-with-barriers-tp7587891.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 <mailto:R-sig-Geo at r-project.org>
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo <https://stat.ethz.ch/mailman/listinfo/r-sig-geo>
> 
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org <mailto:R-sig-Geo at r-project.org>
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo <https://stat.ethz.ch/mailman/listinfo/r-sig-geo>
> 
> 


	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list