Skip to content
Back to formatted view

Raw Message

Message-ID: <201207130846.q6D8kJaA009291@smtp.upm.es>
Date: 2012-07-13T08:44:41Z
From: Marcelino de la Cruz
Subject: find cells of a raster lying on a ring
In-Reply-To: <23582DCD2EF0CA4EA89366505DDB692809742C@UQEXMDA8.soe.uq.edu .au>

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 at 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