/[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 1733 - (hide annotations)
Mon Sep 22 12:23:43 2003 UTC (21 years, 5 months ago) by jan
Original Path: trunk/thuban/Extensions/importAPR/apr.py
File MIME type: text/x-python
File size: 4118 byte(s)
(APR_LClass.GetThubanRange): Now returns a string object if the range
is based on text.

1 jan 1725 # Copyright (C) 2003 by Intevation GmbH
2     # 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     from Thuban.Model.color import Color, Transparent, Black
20     from Thuban.Model.range import Range
21    
22     from odb import ODBBaseObject
23    
24     class APR_LClass(ODBBaseObject):
25     """This object describes the range and label of a class
26     within a legend.
27    
28     'IsText' determines whether 'MinStr'/'MaxStr' are given, else
29     'MinNum'/'MaxNum' should be there.
30     So far, only String-Ranges with identical 'MinStr'/'MaxStr' have
31     been sighted.
32    
33     'MinNum' may not be there. In this case assume it to be -oo.
34    
35     There are objects with 'IsNoData' set to 1. Not yet sure how to
36     treat them.
37    
38     However, objects have been sighted that only have 'IsText' and
39     'Precision': We assume an empty label and a full range.
40    
41     No referenced objects.
42     """
43     _obj_refs = [ ]
44     _values = [ 'IsText', 'MinStr', 'MaxStr', 'MinNum', 'MaxNum', 'Label',
45     'Precision', 'IsNoData' ]
46    
47     def GetThubanRange(self):
48 jan 1733 """Return a Thuban range that corresponds to this object.
49    
50     The returned object is a
51     - Range-Object in case of a numerical range.
52     - String-Object in case of a text range (assuming that
53     text objects occur only with 'MinStr' == 'MaxStr'.
54     """
55     if hasattr(self, 'IsText'):
56     if hasattr(self, 'MinStr'):
57     return self.MinStr
58     else:
59     return ''
60    
61 jan 1725 # build range
62     if hasattr(self, 'MinNum'):
63     range_str = ']' + self.MinNum + ';'
64     else:
65     range_str = ']-oo;'
66     if hasattr(self, 'MaxNum'):
67     range_str = range_str + self.MaxNum + ']'
68     else:
69     range_str = None
70    
71     if hasattr(self, 'MinNum') and hasattr(self, 'MaxNum'):
72     if self.MinNum == self.MaxNum:
73     range_str = '[' + self.MinNum + ';' + self.MaxNum + ']'
74     return Range(range_str)
75    
76     def GetLabel(self):
77     """Return the label string.
78     Return an empty string if there is no 'Label'.
79     """
80     if hasattr(self, 'Label'):
81     return self.Label
82     else:
83     return ''
84    
85    
86     class APR_TClr(ODBBaseObject):
87     """Color object. Appears in 3 styles:
88     1. no attributes: (so far assumed as black)
89     2. only 'Name': a string that describes the color.
90     Seen only "Transparent".
91     3. 'Red', 'Green', 'Blue': RGB code. Each value in '0xffff' style.
92     3.1 Only one or two of the colors are defined. It is assumed
93     that in this case the rest is equal to 0x0000
94     3.2 Some hex-codes are incomplete (eg. 0xff). It is assumed
95     that the missing digits are "0".
96    
97     No referenced objects.
98     """
99     _obj_refs = [ ]
100     _values = [ 'Name', 'Red', 'Green', 'Blue' ]
101    
102     def GetThubanColor(self):
103     """Return a Thuban Color object; returns None if a problem
104     occured.
105     """
106     if hasattr(self, 'Red') or hasattr(self, 'Green') or \
107     hasattr(self, 'Blue'):
108     rgb = { 'Red': 0, 'Green': 0, 'Blue': 0 } # default for missing
109     # parts: 0x0000
110    
111     for color in [ 'Red', 'Green', 'Blue' ]:
112     if hasattr(self, color):
113     s = getattr(self, color)
114     while len(s) < 6:
115     s = s + '0'
116     rgb[color] = int(s, 16)/float(int('0xffff', 16))
117     return Color(rgb['Red'], rgb['Green'], rgb['Blue'])
118     elif hasattr(self, 'Name'):
119     if self.Name == 'Transparent':
120     return Transparent
121     else:
122     return None
123     else:
124     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