[GRASSLIST:8223] Re: Making a raster coordinate a value

Glynn Clements glynn at gclements.plus.com
Fri Sep 9 09:37:18 EDT 2005


Joel Peter William Pitt wrote:

> > > What is the simplest way to get get a singular cell in a raster map to be
> > > set to a value,
> > > irregardless of the current regions resolution?
> > >
> > > More specifically I want to set closest cell to the origin (0,0) to have
> > > value 1. But only 1 cell must be present, and it must work for any
> > > resolution - although I'm currently concerned with working at res=1.
> > 
> > This is awkward if two or four cells are all an equal distance from
> > the origin. If you ignore that case, you're after the cell which is
> > less than half the grid resolution from the origin in each direction,
> > e.g.:
> > 
> > out = abs(x()) < ewres()/2 && abs(y()) < nsres()/2
> 
> 
> Thanks Glynn for clarifying that for me.
> 
> I actually realised that I was making a conceptual mistake in thinking there 
> was a center cell for [0,0], when the origin is actually a coordinate rather 
> than a cell! (I thinking I just needed to sleep on it ;)
> 
> The way I now get around this is to use the above equation (similar to what 
> I was already doing but I was having trouble with cells equidistant from the 
> origin), and then add 0.5 to the x and y coordinates - thus selecting the 
> cell just to the right and above the origin.

That assumes that the raster grid is aligned with the origin. While
that may be true for simple cases (e.g. X-Y data with res=1 and
integer boundaries), it isn't true in general.

If you were to offset the region boundaries by 0.5 in each direction,
or changed the resolution to 0.5, you would again end up with four
"centre" cells.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-user mailing list