[GRASS-dev] [grass-code R][401] GIS.m: Fancy Map Display statusbar coords in Lat/Lon

grass-coder at wald.intevation.org grass-coder at wald.intevation.org
Mon May 21 10:00:46 EDT 2007


code R item #401, was opened at 2007-05-22 02:00
Status: Open
Priority: 3
Submitted By: Hamish Bowman (hamish)
Assigned to: Nobody (None)
Summary: GIS.m: Fancy Map Display statusbar coords in Lat/Lon 
Issue status: None
GRASS component: gis.m
Operating system: all
Operating system version: 


Initial Comment:
Hi,
I would love for Lat/Lon locations to format the Map Display statusbar x,y string into 45°59.9999'S  170°59.9999'W.

Hamish:
>>>        set mapunits [MapCanvas::get_mapunits]
>>>         if { [string first "degree" $mapunits ] >= 0 } {
>>>             set outfmt_coords {%.6f}
>>>         } else {
>>>             set outfmt_coords {%.3f}
>>>         }
Michael:
> > This is a procedure I didn't know about. Did you write it? Seems
> > handy. I might write something similar in wxgrass.
H:
>> Yes, I wrote it to stabilize the x,y coords in the bottom right corner
>> of the GIS.m Map Display window. I would love for Lat/Lon locations
>> to munge the string into 45°59.9999'S  170°59.9999'W.
M:
> Why can't this just be built into your get_mapunits procedure? I can add it
> to the statusbar easily enough.

because that calls g.proj to get the units. You only need to do that once
at init to set a global variable. You really don't want to be calling a
module twice every time the mouse moves 1 pixel.

Python/SWIG:
# test the string made by   (eg "degrees")
python_grass6.G_database_unit_name(int plural)   # ie 0 or 1


> BUT is there a way to get the degree symbol that works on all platforms?

Does this show a degree symbol on the Mac?
$ echo "puts \xB0; exit" | wish



here is some non-functional demo Tcl code:


init {
   global is_ll
   set mapunits [MapCanvas::get_mapunits]

   if {string first "degree" $mapunits ] >= 0 } {
      set is_ll 1
   } else {
      set is_ll 0
   }
   if { is_ll } {
       # failsafe, will try for fancy fmt later
       set outfmt_coords {%.6f}
   } else {
       set outfmt_coords {%.3f}
   }
}


.....
bind $can($mon) <Motion> {
  global mon
  global is_ll

  set scrxmov %x
  set scrymov %y
  if { is_ll } {
     set eastcoord  [fmt_latlon [eval MapCanvas::scrx2mape $mon %x] 0]
     set northcoord [fmt_latlon [eval MapCanvas::scry2mapn $mon %y] 1]
  } else {
     set eastcoord  [format $outfmt_coords [eval MapCanvas::scrx2mape $mon %x] ]
     set northcoord [format $outfmt_coords [eval MapCanvas::scry2mapn $mon %y] ]
  }
  set coords($mon) "$eastcoord $northcoord"
}
......



proc fmt_latlon { num, is_latitude } {
     global is_ll
     # units are degrees
     # _d means integer, _f means float
     set deg_d [expr num - (num%1) ]
     set min_f [expr (num%1)*60 ]
     set min_d [expr min_d - (min_d%1) ]
     set sec_f [expr (min_f%1)*60 ]

     if { is_latitude } {
       if { num > 0 } {
	  set hem_str "N"
       } elif { num == 0 } {
	  set hem_str ""
       } else {
	  set hem_str "S"
       }
     } else {
       if { num > 0 } {
	  set hem_str "E"
       } elif { num == 0 } {
	  set hem_str ""
       } else {
	  set hem_str "W"
       }
     }

     set num_fmt [concat [format {%3d} deg] "\xB0" \
	[format {%02d} min_d] {'} \
	[format {%.5} sec_f]  {"" } $hem_str ]

    return num_fmt
}




Hamish


----------------------------------------------------------------------

You can respond by visiting: 
http://wald.intevation.org/tracker/?func=detail&atid=188&aid=401&group_id=21




More information about the grass-dev mailing list