1 |
# Copyright (c) 2001, 2002 by Intevation GmbH |
# Copyright (c) 2001, 2002 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
4 |
|
# Jonathan Coles <[email protected]> |
5 |
# |
# |
6 |
# This program is free software under the GPL (>=v2) |
# This program is free software under the GPL (>=v2) |
7 |
# Read the file COPYING coming with Thuban for details. |
# Read the file COPYING coming with Thuban for details. |
19 |
LAYER_VISIBILITY_CHANGED |
LAYER_VISIBILITY_CHANGED |
20 |
|
|
21 |
from color import Color |
from color import Color |
|
# Some predefined colors for internal use |
|
|
_black = Color(0, 0, 0) |
|
22 |
|
|
23 |
from classification import Classification |
import classification |
24 |
|
|
25 |
from table import Table |
from table import Table |
26 |
|
|
107 |
""" |
""" |
108 |
|
|
109 |
def __init__(self, title, filename, projection = None, |
def __init__(self, title, filename, projection = None, |
110 |
fill = None, stroke = _black, stroke_width = 1, visible = 1): |
fill = Color.None, |
111 |
|
stroke = Color.Black, |
112 |
|
lineWidth = 1, |
113 |
|
visible = 1): |
114 |
"""Initialize the layer. |
"""Initialize the layer. |
115 |
|
|
116 |
title -- the title |
title -- the title |
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 |
133 |
self.filename = os.path.abspath(filename) |
self.filename = os.path.abspath(filename) |
134 |
|
|
135 |
self.projection = projection |
self.projection = projection |
|
self.fill = fill |
|
|
self.stroke = stroke |
|
|
self.stroke_width = stroke_width |
|
136 |
self.shapefile = None |
self.shapefile = None |
137 |
self.shapetree = None |
self.shapetree = None |
138 |
self.open_shapefile() |
self.open_shapefile() |
142 |
self.shapetable = Table(filename) |
self.shapetable = Table(filename) |
143 |
self.table = self.shapetable |
self.table = self.shapetable |
144 |
|
|
145 |
self.classification = Classification() |
# |
146 |
self.classification.setNull( |
# this is really important so that when the classification class |
147 |
{'stroke':stroke, 'stroke_width':stroke_width, 'fill':fill}) |
# tries to set its parent layer the variable will exist |
148 |
|
# |
149 |
|
self.__classification = None |
150 |
|
|
151 |
|
self.SetClassification(classification.Classification(self)) |
152 |
|
self.__classification.SetDefaultLineColor(stroke) |
153 |
|
self.__classification.SetDefaultLineWidth(lineWidth) |
154 |
|
self.__classification.SetDefaultFill(fill) |
155 |
|
|
156 |
|
self.UnsetModified() |
157 |
|
|
158 |
def open_shapefile(self): |
def open_shapefile(self): |
159 |
if self.shapefile is None: |
if self.shapefile is None: |
214 |
else: |
else: |
215 |
return None |
return None |
216 |
|
|
217 |
|
def GetFieldType(self, fieldName): |
218 |
|
self.open_shapefile() |
219 |
|
info = self.table.field_info_by_name(fieldName) |
220 |
|
if info is not None: |
221 |
|
return info[0] |
222 |
|
else: |
223 |
|
return None |
224 |
|
|
225 |
def NumShapes(self): |
def NumShapes(self): |
226 |
"""Return the number of shapes in the layer""" |
"""Return the number of shapes in the layer""" |
227 |
self.open_shapefile() |
self.open_shapefile() |
264 |
self.projection = projection |
self.projection = projection |
265 |
self.changed(LAYER_PROJECTION_CHANGED, self) |
self.changed(LAYER_PROJECTION_CHANGED, self) |
266 |
|
|
267 |
def SetFill(self, fill): |
def GetClassification(self): |
268 |
"""Set the layer's fill color. None means the shapes are not filled""" |
return self.__classification |
|
self.fill = fill |
|
|
self.changed(LAYER_LEGEND_CHANGED, self) |
|
269 |
|
|
270 |
def SetStroke(self, stroke): |
def SetClassification(self, clazz): |
|
"""Set the layer's stroke color. None means the shapes are not |
|
|
stroked.""" |
|
|
self.stroke = stroke |
|
|
self.changed(LAYER_LEGEND_CHANGED, self) |
|
271 |
|
|
272 |
def SetStrokeWidth(self, width): |
# prevent infinite recursion when calling SetLayer() |
273 |
"""Set the layer's stroke width.""" |
if clazz == self.__classification: |
274 |
self.stroke_width = width |
return |
275 |
|
|
276 |
|
self.__classification = clazz |
277 |
|
self.__classification.SetLayer(self) |
278 |
self.changed(LAYER_LEGEND_CHANGED, self) |
self.changed(LAYER_LEGEND_CHANGED, self) |
279 |
|
|
280 |
def TreeInfo(self): |
def TreeInfo(self): |
293 |
items.append(_("Extent (lat-lon):")) |
items.append(_("Extent (lat-lon):")) |
294 |
items.append(_("Shapetype: %s") % shapetype_names[self.ShapeType()]) |
items.append(_("Shapetype: %s") % shapetype_names[self.ShapeType()]) |
295 |
|
|
296 |
def color_string(color): |
items.append(self.__classification) |
|
if color is None: |
|
|
return "None" |
|
|
return "(%.3f, %.3f, %.3f)" % (color.red, color.green, color.blue) |
|
|
items.append(_("Fill: ") + color_string(self.fill)) |
|
|
items.append(_("Outline: ") + color_string(self.stroke)) |
|
297 |
|
|
298 |
return (_("Layer '%s'") % self.Title(), items) |
return (_("Layer '%s'") % self.Title(), items) |
299 |
|
|