[GRASS5] embedding GRASS display into my app

Glynn Clements glynn.clements at virgin.net
Thu Apr 8 18:39:13 EDT 2004


David Piasecki wrote:

> Do you know of a way to convert the pixel coordinates of the PNG image 
> into geo coordinates? I imagine d.where won't work since it's only 
> interactive within the grass program itself.

Unfortunately, the correspondence is non-trivial, and the functions
which d.where, d.what.* etc use require a monitor to be selected.

The simplest solution is probably to query the map coordinates of the
top-left and bottom-right pixels at the time that the map is drawn,
using essentially the same code as d.where, then using linear
interpolation to convert arbitrary pixel coordinates to their
corresponding map coordinates.

The key issue is that you have to perform the translation at a point
where the map is still "displayed" on the monitor; if you wait until
you actually need the coordinates, the transformation which was
actually used to generate the map may no longer be known.

[In the above, I am assuming that the PNG image is from the PNG
driver. For images generated with r.out.png, the situation is somewhat
simpler, as the image's boundaries exactly correspond to the region's
boundaries.]

-- 
Glynn Clements <glynn.clements at virgin.net>




More information about the grass-dev mailing list