[GRASS5] embedding GRASS display into my app

David Piasecki piasecda at nv.doe.gov
Thu Apr 8 20:28:07 EDT 2004


I started thinking about writing my own d.where that doesn't require 
the interaction with the GRASS monitor. I took a look at the current 
d.where, and it has a function that accepts screen (x,y) pixel 
coordinates, and you can convert to Lat/Lon. I was thinking I could 
remove a good chunk of code that interacts with the user and simply 
have my program pass in the screen coords. That doesn't seem too bad to 
me. I'm just nervous about getting it to compile since I haven't 
actually been able to compile GRASS on my Mac yet (I only have the 
binary). What do you think?

Yes, my PNG image was created with the PNG driver. Basically, I want to 
be able to get Lat/Lon values for locations clicked on, and I want to 
be able to zoom, create a new PNG map, and reload.

It sounds like you're telling me that once I write the PNG file, it 
will no longer be present on the monitor, so I won't be able to get geo 
coords from it. So I should grab the corners before creating the PNG 
and interpolate the rest. What happens when I want to display a larger 
map? If I had a map the size of the U.S. or the world, then I imagine 
the results of standard linear interpolation will vary depending on 
which projection I choose to use.

Expanding on that idea, perhaps before doing a stop=PNG (which I assume 
closes the display), I can get a small number of geo coordinates at 
intervals in the image (say 100x100 points). I imagine that wouldn't 
add too much time. Then I could close the monitor and interpolate 
between the various points. I might get a little better accuracy with 
the bigger maps that way. What do you think?

David


On Apr 8, 2004, at 3:39 PM, Glynn Clements wrote:

>
> 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