16 |
import shapelib, shptree |
import shapelib, shptree |
17 |
|
|
18 |
from messages import LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \ |
from messages import LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \ |
19 |
LAYER_VISIBILITY_CHANGED |
LAYER_VISIBILITY_CHANGED, LAYER_CHANGED |
20 |
|
|
21 |
from color import Color |
from color import Color |
22 |
|
|
107 |
""" |
""" |
108 |
|
|
109 |
def __init__(self, title, filename, projection = None, |
def __init__(self, title, filename, projection = None, |
110 |
fill = Color.None, |
fill = Color.Transparent, |
111 |
stroke = Color.Black, |
stroke = Color.Black, |
112 |
lineWidth = 1, |
lineWidth = 1, |
113 |
visible = 1): |
visible = 1): |
118 |
projection -- the projection object. Its Inverse method is |
projection -- the projection object. Its Inverse method is |
119 |
assumed to map the layer's coordinates to lat/long |
assumed to map the layer's coordinates to lat/long |
120 |
coordinates |
coordinates |
121 |
fill -- the fill color or Color.None if the shapes are not filled |
fill -- the fill color or Color.Transparent if the shapes are |
122 |
stroke -- the stroke color or Color.None if the shapes are not stroked |
not filled |
123 |
|
stroke -- the stroke color or Color.Transparent if the shapes |
124 |
|
are not stroked |
125 |
visible -- boolean. If true the layer is visible. |
visible -- boolean. If true the layer is visible. |
126 |
|
|
127 |
colors are expected to be instances of Color class |
colors are expected to be instances of Color class |
144 |
self.shapetable = Table(filename) |
self.shapetable = Table(filename) |
145 |
self.table = self.shapetable |
self.table = self.shapetable |
146 |
|
|
147 |
self.__classification = classification.Classification(self) |
# |
148 |
|
# this is really important so that when the classification class |
149 |
|
# tries to set its parent layer the variable will exist |
150 |
|
# |
151 |
|
self.__classification = None |
152 |
|
self.__setClassLock = False |
153 |
|
|
154 |
|
|
155 |
|
self.SetClassification(None) |
156 |
|
|
157 |
self.__classification.SetDefaultLineColor(stroke) |
self.__classification.SetDefaultLineColor(stroke) |
158 |
self.__classification.SetDefaultLineWidth(lineWidth) |
self.__classification.SetDefaultLineWidth(lineWidth) |
159 |
self.__classification.SetDefaultFill(fill) |
self.__classification.SetDefaultFill(fill) |
160 |
|
self.__classification.SetLayer(self) |
161 |
|
|
162 |
self.UnsetModified() |
self.UnsetModified() |
163 |
|
|
193 |
self.shapefile.close() |
self.shapefile.close() |
194 |
self.shapefile = None |
self.shapefile = None |
195 |
self.shapetree = None |
self.shapetree = None |
196 |
|
self.SetClassification(None) |
197 |
self.table.Destroy() |
self.table.Destroy() |
198 |
|
|
199 |
def BoundingBox(self): |
def BoundingBox(self): |
275 |
return self.__classification |
return self.__classification |
276 |
|
|
277 |
def SetClassification(self, clazz): |
def SetClassification(self, clazz): |
278 |
self.__classification = clazz |
"""Set the classification to 'clazz' |
279 |
self.changed(LAYER_LEGEND_CHANGED, self) |
|
280 |
|
If 'clazz' is None a default classification is created |
281 |
|
""" |
282 |
|
|
283 |
|
# prevent infinite recursion when calling SetLayer() |
284 |
|
if self.__setClassLock: return |
285 |
|
|
286 |
|
self.__setClassLock = True |
287 |
|
|
288 |
|
if clazz is None: |
289 |
|
if self.__classification is not None: |
290 |
|
self.__classification.SetLayer(None) |
291 |
|
self.__classification = classification.Classification() |
292 |
|
else: |
293 |
|
self.__classification = clazz |
294 |
|
try: |
295 |
|
self.__classification.SetLayer(self) |
296 |
|
except ValueError: |
297 |
|
self.__setClassLock = False |
298 |
|
raise ValueError |
299 |
|
|
300 |
|
self.changed(LAYER_CHANGED, self) |
301 |
|
|
302 |
|
self.__setClassLock = False |
303 |
|
|
304 |
|
def ClassChanged(self): |
305 |
|
"""Called from the classification object when it has changed.""" |
306 |
|
self.changed(LAYER_CHANGED, self) |
307 |
|
|
308 |
def TreeInfo(self): |
def TreeInfo(self): |
309 |
items = [] |
items = [] |
310 |
|
|