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 |
|
|
109 |
def __init__(self, title, filename, projection = None, |
def __init__(self, title, filename, projection = None, |
110 |
fill = Color.None, |
fill = Color.None, |
111 |
stroke = Color.Black, |
stroke = Color.Black, |
112 |
stroke_width = 1, |
lineWidth = 1, |
113 |
visible = 1): |
visible = 1): |
114 |
"""Initialize the layer. |
"""Initialize the layer. |
115 |
|
|
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 None if the shapes are not filled |
fill -- the fill color or Color.None if the shapes are not filled |
122 |
stroke -- the stroke color or None if the shapes are not stroked |
stroke -- the stroke color or Color.None if the shapes are not stroked |
123 |
visible -- boolean. If true the layer is visible. |
visible -- boolean. If true the layer is visible. |
124 |
|
|
125 |
colors are expected to be instances of Color class |
colors are expected to be instances of Color class |
142 |
self.shapetable = Table(filename) |
self.shapetable = Table(filename) |
143 |
self.table = self.shapetable |
self.table = self.shapetable |
144 |
|
|
145 |
self.__classification = classification.Classification(self) |
# |
146 |
self.__classification.SetDefaultStroke(stroke) |
# this is really important so that when the classification class |
147 |
self.__classification.SetDefaultStrokeWidth(stroke_width) |
# tries to set its parent layer the variable will exist |
148 |
|
# |
149 |
|
self.__classification = None |
150 |
|
self.__setClassLock = False |
151 |
|
|
152 |
|
|
153 |
|
self.SetClassification(None) |
154 |
|
|
155 |
|
self.__classification.SetDefaultLineColor(stroke) |
156 |
|
self.__classification.SetDefaultLineWidth(lineWidth) |
157 |
self.__classification.SetDefaultFill(fill) |
self.__classification.SetDefaultFill(fill) |
158 |
|
self.__classification.SetLayer(self) |
159 |
|
|
160 |
self.UnsetModified() |
self.UnsetModified() |
161 |
|
|
191 |
self.shapefile.close() |
self.shapefile.close() |
192 |
self.shapefile = None |
self.shapefile = None |
193 |
self.shapetree = None |
self.shapetree = None |
194 |
|
self.SetClassification(None) |
195 |
self.table.Destroy() |
self.table.Destroy() |
196 |
|
|
197 |
def BoundingBox(self): |
def BoundingBox(self): |
219 |
else: |
else: |
220 |
return None |
return None |
221 |
|
|
222 |
|
def GetFieldType(self, fieldName): |
223 |
|
self.open_shapefile() |
224 |
|
info = self.table.field_info_by_name(fieldName) |
225 |
|
if info is not None: |
226 |
|
return info[0] |
227 |
|
else: |
228 |
|
return None |
229 |
|
|
230 |
def NumShapes(self): |
def NumShapes(self): |
231 |
"""Return the number of shapes in the layer""" |
"""Return the number of shapes in the layer""" |
232 |
self.open_shapefile() |
self.open_shapefile() |
273 |
return self.__classification |
return self.__classification |
274 |
|
|
275 |
def SetClassification(self, clazz): |
def SetClassification(self, clazz): |
276 |
self.__classification = clazz |
"""Set the classification to 'clazz' |
277 |
self.changed(LAYER_LEGEND_CHANGED, self) |
|
278 |
|
If 'clazz' is None a default classification is created |
279 |
|
""" |
280 |
|
|
281 |
|
# prevent infinite recursion when calling SetLayer() |
282 |
|
if self.__setClassLock: return |
283 |
|
|
284 |
|
self.__setClassLock = True |
285 |
|
|
286 |
|
if clazz is None: |
287 |
|
if self.__classification is not None: |
288 |
|
self.__classification.SetLayer(None) |
289 |
|
self.__classification = classification.Classification() |
290 |
|
else: |
291 |
|
self.__classification = clazz |
292 |
|
try: |
293 |
|
self.__classification.SetLayer(self) |
294 |
|
except ValueError: |
295 |
|
self.__setClassLock = False |
296 |
|
raise ValueError |
297 |
|
|
298 |
|
self.changed(LAYER_CHANGED, self) |
299 |
|
|
300 |
|
self.__setClassLock = False |
301 |
|
|
302 |
|
def ClassChanged(self): |
303 |
|
"""Called from the classification object when it has changed.""" |
304 |
|
self.changed(LAYER_CHANGED, self) |
305 |
|
|
306 |
def TreeInfo(self): |
def TreeInfo(self): |
307 |
items = [] |
items = [] |
308 |
|
|