[GRASSLIST:8778] Re: Querying display monitor locations as pe rcent from origin (0,0)?

Patton, Eric epatton at nrcan.gc.ca
Thu Oct 27 12:04:14 EDT 2005


 
I just tried a marginally more efficient way of getting EXACT display
monitor coordinates as percentage values without the hassle of guessing or
querying the display: Use g.region -e to get the n-s and e-w extents of the
screen; then g.region n=/s=/e=/w= (whichever you need to) to modify the
region extent to the next 100m value; then d.grid with an origin at the
southwest corner (0,0 on the display, and g.region -p/-g shows this) and a
grid spacing of 1/10th your e-w region extent in grid units. Now you have a
measured grid that exactly fits your display extent, and percent coordinates
can just be read off the graticule. If you want to ensure that the aspect
ratio of n-s vs.e-w display units are equal, just make your monitor extents
square.

Still a bit of work, but it should save a few iterations of trial-and-error
when placing graphics. How difficult would it be to modify d.grid to print
either easting/northings and/or monitor display % units on the graticule as
well?

~ Eric.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Eric Patton
 
Technologist, Geo-Spatial Data Services
Geological Survey of Canada (Atlantic)
Natural Resources Canada
Bedford Institute of Oceanography
Dartmouth, Nova Scotia, Canada B2Y 4A2
 
Postal address: P.O. Box 1006
Courier address: 1 Challenger Drive
 
Telephone: (902)426-7732
Facsimile:  (902)426-4104
E-mail:       epatton at NRCan.gc.ca
 

-----Original Message-----
From: owner-GRASSLIST at baylor.edu [mailto:owner-GRASSLIST at baylor.edu] On
Behalf Of Hamish
Sent: Thursday, October 27, 2005 1:07 AM
To: dylan at iici.no-ip.org
Cc: epatton at nrcan.gc.ca; GRASSLIST at baylor.edu
Subject: [GRASSLIST:8770] Re: Querying display monitor locations as percent
from origin (0,0)?

> > > I'm trying to create a simple legend for sediment grainsize 
> > > analyses (attributes consist of % gravel, % sand, % silt, % clay).
> > > I already have some really nice looking pie charts created using 
> > > d.vect.chart, and now I want an accompanying legend in the 
> > > upper-right corner of the monitor for a screen capture. Is there a 
> > > way to query the coordinates of locations on the monitor as 
> > > percentages from the lower-left corner?
> > >
> > > I could make a reasonable guess as to where I think the legend 
> > > should appear in display coordinates, but I want to use d.graph to 
> > > build a little window containing all the legend elements; having 
> > > the exact queried coordinates could just be pasted into the 
> > > d.graph command.
> >
> > I think the best you can do is kruler and a hand calculator.. :/
> >
> [snip]
> 
> Really? I wonder how hard it would be to adjust the monitor commands 
> to accept a slightly more useful form of location directives... I have 
> spent a bit of time fussing around with percentage values until I 
> finally got a reasonable legend...

what do you mean by slightly more useful? Remeber the result should look
somehwhat the same regardless of the window size, so absolute pixel
placement isn't always great. e.g. try it with d.text.freetype -p,-n.

My method with d.legend ususally is to get it where I want it with the mouse
placement and then do trial and error with the at= command until it was
correct. d.legend could do what d.barscale does which is after a mouse
placement figure out, translate, and remember the placement as the at=
option instead of the -m flag, but d.legend is more complicated...

Maybe spit out the placement answer as a G_debug(1,) message for those who
want it? That would be pretty easy to add to the mouse code.


Another general idea to automate figuring out screen percentages is to use
"g.region -g", figure out a y=mx+b 0-100% releationship with the screen
postion, then pipe the output of d.where through a conversion calculation;
it's all linear. Use d.info if you want absolute pixel positions.

Or d.frame in 10% chunks ;)


Hamish




More information about the grass-user mailing list