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:
Hi R users,

I would like to be able to calculate how many cells of a raster, and their values (1 or 0), lie at a distance r from a particular cell in the raster. In other words, I need to calculate the number and values of the cells lying on a ring with radius r and centred in x0 and y0.

This is as far I got:



require(spatstat)

# Build an example image of 0's and 1's:

M <- im(matrix(sample(0:1,500*500,TRUE),nrow=500),xcol=seq(0,10,length=500),

               yrow=seq(0,10,length=500))

Thanks
Lorenzo


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

___________________________________________________

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

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to