/[thuban]/branches/WIP-pyshapelib-bramz/Extensions/importAPR/apr.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/Extensions/importAPR/apr.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2378 - (hide annotations)
Sun Oct 3 22:00:35 2004 UTC (20 years, 5 months ago) by jan
Original Path: trunk/thuban/Extensions/importAPR/apr.py
File MIME type: text/x-python
File size: 7423 byte(s)
(APR_BMkSym.GetThubanProp): Now that Thuban supports size, apply
this correctly.

1 jan 2378 # Copyright (C) 2003, 2004 by Intevation GmbH
2 jan 1725 # Authors:
3     # Jan-Oliver Wagner <[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     """
9     Classes for ArcView Objects as in '.apr'-files.
10    
11     The classes are only added to this module if they
12     are considered to be complete and whenever possible
13     accompanied by unit tests (see tests/).
14     Experimental classes should remain in importAPR.py.
15     """
16    
17     __version__ = "$Revision$"
18    
19 jan 1883 from math import ceil
20    
21 jan 1725 from Thuban.Model.color import Color, Transparent, Black
22     from Thuban.Model.range import Range
23 jan 1883 from Thuban.Model.classification import ClassGroupProperties
24 jan 1725
25     from odb import ODBBaseObject
26    
27 jan 1883 class APR_BLnSym(ODBBaseObject):
28     """Line symbol object.
29     Always references a color object TClr via 'Color'.
30    
31     The stroke width 'Width' is always given, but the scale is
32     unclear so far (e.g. which width is actually meant with value '0.1'?).
33     Meanwhile, the ceiling of 'Width' is applied to be stroke width
34     in pixels.
35    
36     Finally, there seems always to be a 'Pattern'-List consisting of
37     float values. No idea so far, how to interpret this (Thuban does
38     not support pattern yet anyway).
39     """
40     _obj_refs = [ 'Color' ]
41     _values = [ 'Width', 'Pattern' ]
42    
43     def GetThubanProp(self):
44     """Create a Thuban ClassGroupProperty from this object and
45     return it.
46     """
47     prop = ClassGroupProperties()
48     prop.SetLineColor(self.Get('Color').GetThubanColor())
49     prop.SetLineWidth(int(ceil(float(self.Get('Width')))))
50     return prop
51    
52     class APR_BMkSym(ODBBaseObject):
53     """Point symbol object.
54     Always references a Color and a Background Color via 'Color', 'BgColor'.
55     For Thuban, Color is interpreted as line color and BGColor is
56     interpreted as fill color.
57    
58     Next, there is always a 'Font' reference. Probably this defines
59     the font for the label. This is not interpreted for Thuban.
60    
61 jan 2378 There is always a Size element. It is not clear how 'size'
62     defined in ArcView.
63 jan 1883
64     There is always a Angle element, but I don't know how this is
65     defined. I only sighted the value of 360 so far.
66    
67    
68     Finally, there seems always to be a 'Pattern'-List consisting of
69     float values. No idea so far, how to interpret this (Thuban does
70     not support pattern yet anyway).
71     """
72    
73     _obj_refs = [ 'Color', 'BgColor', 'Font' ]
74     _values = [ 'Angle', 'Size', 'Pattern' ]
75    
76     def GetThubanProp(self):
77     """Create a Thuban ClassGroupProperty from this object and
78     return it.
79    
80     In Thuban, the points have all the same size,
81     but we can vary the width of the line.
82     """
83     prop = ClassGroupProperties()
84 jan 2378 prop.SetSize(int(ceil(float(self.Get('Size')))))
85 jan 1883 prop.SetLineColor(self.Get('Color').GetThubanColor())
86     prop.SetFill(self.Get('BgColor').GetThubanColor())
87     return prop
88    
89     class APR_BShSym(ODBBaseObject):
90     """Polygon symbol object.
91     Always references TClr objects via 'Color', 'OutlineColor' and 'BgColor'.
92     Always has attributes 'OutlineWidth' and 'Outline'.
93 jan 2378
94 jan 1883 OutlineColor is interpreted to be the Thuban line color, OutlineWidth
95     as the Thuban line width.
96     'Color' is interpreted to be the Thuban fill color.
97     'BgColor' is not interpreted and it is not clear what this color
98     defines.
99    
100     It is unclear what 'Outline' defines and thus is not used for Tuban.
101     """
102     _obj_refs = [ 'Color', 'OutlineColor', 'BgColor' ]
103     _values = [ 'OutlineWidth', 'Outline' ]
104    
105     def GetThubanProp(self):
106     """Create a Thuban ClassGroupProperty from this object and
107     return it.
108     """
109     prop = ClassGroupProperties()
110     prop.SetLineWidth(int(ceil(float(self.Get('OutlineWidth')))))
111     prop.SetLineColor(self.Get('OutlineColor').GetThubanColor())
112     prop.SetFill(self.Get('Color').GetThubanColor())
113     return prop
114    
115 jan 1725 class APR_LClass(ODBBaseObject):
116     """This object describes the range and label of a class
117     within a legend.
118    
119     'IsText' determines whether 'MinStr'/'MaxStr' are given, else
120     'MinNum'/'MaxNum' should be there.
121     So far, only String-Ranges with identical 'MinStr'/'MaxStr' have
122     been sighted.
123    
124     'MinNum' may not be there. In this case assume it to be -oo.
125    
126     There are objects with 'IsNoData' set to 1. Not yet sure how to
127     treat them.
128    
129     However, objects have been sighted that only have 'IsText' and
130     'Precision': We assume an empty label and a full range.
131    
132     No referenced objects.
133     """
134     _obj_refs = [ ]
135     _values = [ 'IsText', 'MinStr', 'MaxStr', 'MinNum', 'MaxNum', 'Label',
136     'Precision', 'IsNoData' ]
137    
138     def GetThubanRange(self):
139 jan 1733 """Return a Thuban range that corresponds to this object.
140 jan 2378
141 jan 1733 The returned object is a
142     - Range-Object in case of a numerical range.
143     - String-Object in case of a text range (assuming that
144     text objects occur only with 'MinStr' == 'MaxStr'.
145     """
146     if hasattr(self, 'IsText'):
147     if hasattr(self, 'MinStr'):
148     return self.MinStr
149     else:
150     return ''
151    
152 jan 1725 # build range
153     if hasattr(self, 'MinNum'):
154     range_str = ']' + self.MinNum + ';'
155     else:
156     range_str = ']-oo;'
157     if hasattr(self, 'MaxNum'):
158     range_str = range_str + self.MaxNum + ']'
159     else:
160     range_str = None
161    
162     if hasattr(self, 'MinNum') and hasattr(self, 'MaxNum'):
163     if self.MinNum == self.MaxNum:
164     range_str = '[' + self.MinNum + ';' + self.MaxNum + ']'
165     return Range(range_str)
166    
167     def GetLabel(self):
168     """Return the label string.
169     Return an empty string if there is no 'Label'.
170     """
171     if hasattr(self, 'Label'):
172     return self.Label
173     else:
174     return ''
175    
176    
177     class APR_TClr(ODBBaseObject):
178     """Color object. Appears in 3 styles:
179     1. no attributes: (so far assumed as black)
180     2. only 'Name': a string that describes the color.
181     Seen only "Transparent".
182     3. 'Red', 'Green', 'Blue': RGB code. Each value in '0xffff' style.
183     3.1 Only one or two of the colors are defined. It is assumed
184     that in this case the rest is equal to 0x0000
185     3.2 Some hex-codes are incomplete (eg. 0xff). It is assumed
186     that the missing digits are "0".
187    
188     No referenced objects.
189     """
190     _obj_refs = [ ]
191     _values = [ 'Name', 'Red', 'Green', 'Blue' ]
192    
193     def GetThubanColor(self):
194     """Return a Thuban Color object; returns None if a problem
195     occured.
196     """
197     if hasattr(self, 'Red') or hasattr(self, 'Green') or \
198     hasattr(self, 'Blue'):
199     rgb = { 'Red': 0, 'Green': 0, 'Blue': 0 } # default for missing
200     # parts: 0x0000
201    
202     for color in [ 'Red', 'Green', 'Blue' ]:
203     if hasattr(self, color):
204     s = getattr(self, color)
205     while len(s) < 6:
206     s = s + '0'
207     rgb[color] = int(s, 16)/float(int('0xffff', 16))
208     return Color(rgb['Red'], rgb['Green'], rgb['Blue'])
209     elif hasattr(self, 'Name'):
210     if self.Name == 'Transparent':
211     return Transparent
212     else:
213     return None
214     else:
215     return Black

Properties

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26