/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/scalebar.py
ViewVC logotype

Contents of /branches/WIP-pyshapelib-bramz/Thuban/UI/scalebar.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1240 - (show annotations)
Thu Jun 19 09:25:31 2003 UTC (21 years, 8 months ago) by frank
Original Path: trunk/thuban/Thuban/UI/scalebar.py
File MIME type: text/x-python
File size: 3111 byte(s)
(ScaleBar.DrawScaleBar): Apply conversion to scale if projection is
latlong to get better estimate.

1 # Copyright (c) 2001, 2002 by Intevation GmbH
2 # Authors:
3 # Frank Koormann <[email protected]>
4 #
5 # This program is free software under the GPL (>=v2)
6 # Read the file COPYING coming with Thuban for details.
7
8 __version__ = "$Revision$"
9
10 from Thuban import _
11 from Thuban.Model.scalebar import deriveInterval, roundInterval
12
13 from wxPython.wx import *
14
15 class ScaleBar:
16
17 def __init__(self, map):
18 self.map = map
19
20 def DrawScaleBar(self, scale, dc, position, size):
21 """Draw a scalebar on a given DC"""
22
23 # Only draw a legend if the corresponding map has a layer
24 if self.map is not None and len(self.map.layers) > 0 and scale > 0.0:
25
26 # If no projection is specified, the scale information _might_
27 # be reasonable. So gray out the scalebar in these cases.
28 if self.map.projection is None:
29 BlackPen = wxGREY_PEN
30 BlackBrush = wxGREY_BRUSH
31 BlackText = wxColor(127,127,127)
32 else:
33 params = {}
34 # For geographic projection we have to convert the scale from
35 # Unit DD to meters.
36 for p in self.map.projection.params:
37 key, value = p.split('=')
38 params[key] = value
39 if params['proj'] == 'latlong':
40 scale = scale * 0.017453 / 1000.0
41 # We have a projection, draw the scalebar in bw
42 BlackPen = wxBLACK_PEN
43 BlackBrush = wxBLACK_BRUSH
44 BlackText = wxBLACK
45
46 # Get the dimension
47 width, height = size
48 posx, posy = position
49 l1width, l1height = dc.GetTextExtent("%d"%0)
50
51 # Make a first guess for the interval (to get the size we have
52 # to reserve for the labels)
53 interval, unit = deriveInterval(width, scale)
54 l2width, l2height = dc.GetTextExtent("%d %s"%(interval,unit))
55 width = width - 4.0 - l1width/2.0 -l2width/2.0
56
57 # Having precised the width now the final interval can be calculated
58 interval, unit = deriveInterval(width, scale)
59 interval, label = roundInterval(interval)
60
61 if interval > 0.0:
62 # We draw 2 rectangles with half the width
63 if unit == 'km':
64 width = int(interval*1000.0*scale/2)
65 else:
66 width = int(interval*scale/2)
67
68 dc.SetPen(BlackPen)
69
70 brush = wxBrush(wxWHITE, wxSOLID)
71 dc.SetBrush(brush)
72 dc.DrawRectangle(posx+4,posy+2,width,8)
73
74 dc.SetBrush(BlackBrush)
75 dc.DrawRectangle(posx+width+4,posy+2,width,8)
76
77 dc.SetTextForeground(BlackText)
78 dc.DrawText("%d"%0, posx+ 4 - l1width/2, posy+12)
79
80 l2width, l2height = dc.GetTextExtent("%s %s"%(label, unit))
81 dc.DrawText("%s %s"%(interval, unit), posx+ 2*width+4 - l2width/2, posy + 12)
82

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26