8 |
|
|
9 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
10 |
|
|
11 |
|
from math import fabs, cos, pi |
12 |
|
|
13 |
from Thuban import _ |
from Thuban import _ |
14 |
|
|
15 |
import resource |
import resource |
19 |
from Thuban.Model.layer import BaseLayer |
from Thuban.Model.layer import BaseLayer |
20 |
from Thuban.Model.map import Map |
from Thuban.Model.map import Map |
21 |
from Thuban.Model.classification import ClassGroup |
from Thuban.Model.classification import ClassGroup |
22 |
|
from Thuban.Model.proj import PROJ_UNITS_DEGREES |
23 |
|
|
24 |
from Thuban.Model.messages import \ |
from Thuban.Model.messages import \ |
25 |
MAP_STACKING_CHANGED, MAP_LAYERS_ADDED, MAP_LAYERS_REMOVED, LAYER_CHANGED,\ |
MAP_STACKING_CHANGED, MAP_LAYERS_ADDED, MAP_LAYERS_REMOVED, LAYER_CHANGED,\ |
687 |
|
|
688 |
if self.canvas.map is not None \ |
if self.canvas.map is not None \ |
689 |
and self.canvas.map.projection is not None: |
and self.canvas.map.projection is not None: |
690 |
|
|
691 |
|
# if we are using a projection with geographics coordinates |
692 |
|
# we need to change the scale value based on where we are |
693 |
|
# on the globe. |
694 |
|
if self.canvas.map.projection.GetProjectedUnits() \ |
695 |
|
== PROJ_UNITS_DEGREES: |
696 |
|
|
697 |
|
width, height = self.canvas.GetSizeTuple() |
698 |
|
long, lat = self.canvas.win_to_proj(width/2, height/2) |
699 |
|
|
700 |
|
# slightly inaccurate, but if we are looking at |
701 |
|
# the north/south pole we could end up dividing by zero |
702 |
|
# |
703 |
|
# it shouldn't matter for our purposes that we ignore |
704 |
|
# the original sign of lat. |
705 |
|
if fabs(lat) > 89.9: lat = 89.9 |
706 |
|
|
707 |
|
# |
708 |
|
# one degree is about 111,133m at the equator |
709 |
|
# we need to adjust that for latitude as |
710 |
|
# we move north/south. use the center of the map |
711 |
|
# as the point to scale the length to. |
712 |
|
# |
713 |
|
scale = scale / (111133.0 * fabs(cos(lat * pi/180))) |
714 |
|
|
715 |
self.scalebar.DrawScaleBar(scale, dc, (0,0), dc.GetSizeTuple()) |
self.scalebar.DrawScaleBar(scale, dc, (0,0), dc.GetSizeTuple()) |
716 |
|
|
717 |
self.scalebarBitmap.SetBitmap(bmp) |
self.scalebarBitmap.SetBitmap(bmp) |