19 |
|
|
20 |
import classification |
import classification |
21 |
|
|
22 |
from color import Color |
from color import Transparent, Black |
23 |
from base import TitledObject, Modifiable |
from base import TitledObject, Modifiable |
24 |
|
|
25 |
import resource |
import resource |
99 |
"""Determine if this layer support classifications.""" |
"""Determine if this layer support classifications.""" |
100 |
return False |
return False |
101 |
|
|
102 |
|
def HasShapes(self): |
103 |
|
"""Determine if this layer supports shapes.""" |
104 |
|
return False |
105 |
|
|
106 |
def GetProjection(self): |
def GetProjection(self): |
107 |
"""Return the layer's projection.""" |
"""Return the layer's projection.""" |
108 |
return self.projection |
return self.projection |
119 |
All children of the layer have the same type. |
All children of the layer have the same type. |
120 |
|
|
121 |
A layer has fill and stroke colors. Colors should be instances of |
A layer has fill and stroke colors. Colors should be instances of |
122 |
Color. They can also be None, indicating no fill or no stroke. |
Color. They can also be Transparent, indicating no fill or no stroke. |
123 |
|
|
124 |
The layer objects send the following events, all of which have the |
The layer objects send the following events, all of which have the |
125 |
layer object as parameter: |
layer object as parameter: |
129 |
""" |
""" |
130 |
|
|
131 |
def __init__(self, title, data, projection = None, |
def __init__(self, title, data, projection = None, |
132 |
fill = Color.Transparent, |
fill = Transparent, |
133 |
stroke = Color.Black, |
stroke = Black, |
134 |
lineWidth = 1, |
lineWidth = 1, |
135 |
visible = True): |
visible = True): |
136 |
"""Initialize the layer. |
"""Initialize the layer. |
140 |
projection -- the projection object. Its Inverse method is |
projection -- the projection object. Its Inverse method is |
141 |
assumed to map the layer's coordinates to lat/long |
assumed to map the layer's coordinates to lat/long |
142 |
coordinates |
coordinates |
143 |
fill -- the fill color or Color.Transparent if the shapes are |
fill -- the fill color or Transparent if the shapes are |
144 |
not filled |
not filled |
145 |
stroke -- the stroke color or Color.Transparent if the shapes |
stroke -- the stroke color or Transparent if the shapes |
146 |
are not stroked |
are not stroked |
147 |
visible -- boolean. If true the layer is visible. |
visible -- boolean. If true the layer is visible. |
148 |
|
|
157 |
# tries to set its parent layer the variable will exist |
# tries to set its parent layer the variable will exist |
158 |
# |
# |
159 |
self.__classification = None |
self.__classification = None |
|
self.__setClassLock = False |
|
160 |
|
|
161 |
self.SetShapeStore(data) |
self.SetShapeStore(data) |
162 |
|
|
165 |
self.__classification.SetDefaultLineColor(stroke) |
self.__classification.SetDefaultLineColor(stroke) |
166 |
self.__classification.SetDefaultLineWidth(lineWidth) |
self.__classification.SetDefaultLineWidth(lineWidth) |
167 |
self.__classification.SetDefaultFill(fill) |
self.__classification.SetDefaultFill(fill) |
|
self.__classification.SetLayer(self) |
|
168 |
|
|
169 |
self.UnsetModified() |
self.UnsetModified() |
170 |
|
|
235 |
|
|
236 |
def Destroy(self): |
def Destroy(self): |
237 |
BaseLayer.Destroy(self) |
BaseLayer.Destroy(self) |
238 |
self.SetClassification(None) |
self.GetClassification()._set_layer(None) |
239 |
|
|
240 |
def BoundingBox(self): |
def BoundingBox(self): |
241 |
"""Return the layer's bounding box in the intrinsic coordinate system. |
"""Return the layer's bounding box in the intrinsic coordinate system. |
297 |
return table.Column(fieldName).type |
return table.Column(fieldName).type |
298 |
return None |
return None |
299 |
|
|
300 |
|
def HasShapes(self): |
301 |
|
return True |
302 |
|
|
303 |
def NumShapes(self): |
def NumShapes(self): |
304 |
"""Return the number of shapes in the layer""" |
"""Return the number of shapes in the layer""" |
305 |
return self.numshapes |
return self.numshapes |
345 |
return self.__classification |
return self.__classification |
346 |
|
|
347 |
def SetClassification(self, clazz): |
def SetClassification(self, clazz): |
348 |
"""Set the classification to 'clazz' |
"""Set the classification used by this layer to 'clazz' |
349 |
|
|
350 |
If 'clazz' is None a default classification is created |
If 'clazz' is None a default classification is created. |
|
""" |
|
351 |
|
|
352 |
# prevent infinite recursion when calling SetLayer() |
ValueError is raised if the classification's field name |
353 |
if self.__setClassLock: return |
and type are different (if they aren't None) than what |
354 |
|
is in the shapestore. The Layer will not be changed in |
355 |
|
this case. |
356 |
|
""" |
357 |
|
|
358 |
self.__setClassLock = True |
old_class = self.__classification |
359 |
|
|
360 |
if clazz is None: |
if clazz is None: |
361 |
if self.__classification is not None: |
clazz = classification.Classification() |
|
self.__classification.SetLayer(None) |
|
|
self.__classification = classification.Classification() |
|
|
else: |
|
|
self.__classification = clazz |
|
|
try: |
|
|
self.__classification.SetLayer(self) |
|
|
except ValueError: |
|
|
self.__setClassLock = False |
|
|
raise ValueError |
|
362 |
|
|
363 |
self.changed(LAYER_CHANGED, self) |
try: |
364 |
|
self.__classification = clazz |
365 |
|
clazz._set_layer(self) |
366 |
|
|
367 |
self.__setClassLock = False |
# only change things after a successful call |
368 |
|
if old_class is not None: |
369 |
|
old_class._set_layer(None) |
370 |
|
except ValueError: |
371 |
|
self.__classification = old_class |
372 |
|
raise ValueError |
373 |
|
|
374 |
|
# we don't need this since a message will be sent |
375 |
|
# after calling _set_layer() |
376 |
|
#self.changed(LAYER_CHANGED, self) |
377 |
|
|
378 |
def ClassChanged(self): |
def ClassChanged(self): |
379 |
"""Called from the classification object when it has changed.""" |
"""Called from the classification object when it has changed.""" |
382 |
def TreeInfo(self): |
def TreeInfo(self): |
383 |
items = [] |
items = [] |
384 |
|
|
385 |
if hasattr(self, 'filename'): |
items.append(_("Filename: %s") % self.ShapeStore().FileName()) |
|
items.append(_("Filename: %s") % self.filename) |
|
386 |
|
|
387 |
if self.Visible(): |
if self.Visible(): |
388 |
items.append(_("Shown")) |
items.append(_("Shown")) |
449 |
def BoundingBox(self): |
def BoundingBox(self): |
450 |
"""Return the layer's bounding box in the intrinsic coordinate system. |
"""Return the layer's bounding box in the intrinsic coordinate system. |
451 |
|
|
452 |
If the layer has no shapes, return None. |
If the there is no support for images, or the file cannot |
453 |
|
be read, or there is no geographics information available, return None. |
454 |
""" |
""" |
455 |
if not resource.has_gdal_support(): |
if not resource.has_gdal_support(): |
456 |
return None |
return None |
506 |
def TreeInfo(self): |
def TreeInfo(self): |
507 |
items = [] |
items = [] |
508 |
|
|
509 |
|
items.append(_("Filename: %s") % self.GetImageFilename()) |
510 |
|
|
511 |
if self.Visible(): |
if self.Visible(): |
512 |
items.append(_("Shown")) |
items.append(_("Shown")) |
513 |
else: |
else: |
514 |
items.append(_("Hidden")) |
items.append(_("Hidden")) |
|
items.append(_("Shapes: %d") % self.NumShapes()) |
|
515 |
|
|
516 |
bbox = self.LatLongBoundingBox() |
bbox = self.LatLongBoundingBox() |
517 |
if bbox is not None: |
if bbox is not None: |