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

Glynn Clements glynn at gclements.plus.com
Thu Sep 8 13:10:48 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

> 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

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




More information about the grass-user mailing list