Skip to content
Prev 15588 / 29559 Next

find cells of a raster lying on a ring

Well, it seems you didnt go too far ;-)

Lets say that our point is in the center of the raster

 >point <-c(5,5)

# compute the distances from this point to each 
cell of the raster (the object named "cosa")

 > mg <- expand.grid(x=seq(0,10,length=500), y=seq(0,10,length=500))
 > cosa <- crossdist(point[1],point[2],mg$x,mg$y)

# See how many cells are at *exactly* 2 units distance from the point

 >plot(M)
 > points(mg[cosa==2,],pch=19, col=2)
# none in my computer !

# See how many cells are in a ring of width 0.02 
units at  2 units distance from the point
 > points(mg[cosa<2.01 & cosa>1.99,],pch=19, col=2)

# how many?
 > sum(cosa<2.01 & cosa>1.99)

# get their values
 > M[mg[cosa<2.01 & cosa>1.99,]]


Hope this helps,

Marcelino
At 02:25 13/07/2012, Lorenzo Cattarino wrote:
___________________________________________________

Marcelino de la Cruz Rot
Departamento de Biolog?a y Geolog?a
Escuela Superior de Ciencias Experimentales y Tecnolog?a
Universidad Rey Juan Carlos
c/ Tulip?n, s/n.
E-28933 M?stoles (Madrid)
Espa?a
Fax: +34 91 664 7490