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

Joel Peter William Pitt joel.pitt at gmail.com
Thu Sep 8 18:10:02 EDT 2005


On 9/8/05, Glynn Clements <glynn at gclements.plus.com> 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.

> I've been playing with mapcalc but the way it calculates x() and y() seems
> > odd and round() rounds them to either 1 or -1, skipping 0. int() 
> truncates
> > leaving two rows/columns with a value 0.
> 
> round() rounds towards the nearest integer, so:
> 
> round( 0.7) == 1
> round( 0.2) == 0
> round(-0.2) == 0
> round(-0.7) == -1
> 
> etc.
> 
> int() rounds towards zero, so:
> 
> int( 1.2) == 1
> int( 0.9) == 0
> int(-0.9) == 0
> int(-1.2) == -1
> 
> 
Thats what I thought they should do, I realise that when I was using round 
the coordinates were > 0.5 or < -0.5 thus round would give 1.

Thanks,
Joel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-user/attachments/20050908/99af4c14/attachment.html


More information about the grass-user mailing list