[GRASS-dev] graph function in r.mapcalc

Glynn Clements glynn at gclements.plus.com
Sun Nov 18 19:46:28 PST 2012


Paulo van Breugel wrote:

> I am using the graph function in r.mapcalc. The input is the name of the
> map to be converted and a string with XY values, like:
> 
> "newmap = graph(map, 1, x1,y1, x2,y2,... xi,yi)"

The second argument ("1") shouldn't be there.

>  Often, X and Y values are available as separate columns or vectors. In
> such cases, it would be much easier if X and Y values can be given as
> separate vectors, e.g., something like:
> 
>  "newmap = graph(map, x=x1,x2,x3,x4,...xi, y=y1,y2,y3,y4,...,yi)"

That exact syntax (i.e. with "x=" and "y=" markers) isn't possible
without fundamentally re-writing r.mapcalc.

However, it would be possible to implement:

	newmap = graph(map, x1,x2,x3,x4, y1,y2,y3,y4)

This would boil down to cloning f_graph() in raster/r.mapcalc/xgraph.c
with

	#define X(j) (argz[2 + 2 * (j) + 0][i])
	#define Y(j) (argz[2 + 2 * (j) + 1][i])

changed to:

	#define X(j) (argz[2 + (j) + 0][i])
	#define Y(j) (argz[2 + (j) + n][i])

In practice, we'd want to re-factor the common code.

A (untested) patch to implement a graph2() function with the above
syntax is attached.

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

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: graph2.diff
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20121119/d5b21d7b/attachment.ksh>


More information about the grass-dev mailing list