7 |
|
|
8 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
9 |
|
|
10 |
|
import os |
11 |
from math import log, ceil |
from math import log, ceil |
12 |
|
|
13 |
import shapelib, shptree |
import shapelib, shptree |
84 |
"""Set the layer's visibility.""" |
"""Set the layer's visibility.""" |
85 |
self.visible = visible |
self.visible = visible |
86 |
self.issue(LAYER_VISIBILITY_CHANGED, self) |
self.issue(LAYER_VISIBILITY_CHANGED, self) |
87 |
|
|
88 |
|
|
89 |
class Layer(BaseLayer): |
class Layer(BaseLayer): |
90 |
|
|
91 |
"""Represent the information of one geodata file (currently a shapefile) |
"""Represent the information of one geodata file (currently a shapefile) |
120 |
colors are expected to be instances of Color class |
colors are expected to be instances of Color class |
121 |
""" |
""" |
122 |
BaseLayer.__init__(self, title, visible = visible) |
BaseLayer.__init__(self, title, visible = visible) |
123 |
self.filename = filename |
|
124 |
|
# Make the filename absolute. The filename will be |
125 |
|
# interpreted relative to that anyway, but when saving a |
126 |
|
# session we need to compare absolute paths and it's usually |
127 |
|
# safer to always work with absolute paths. |
128 |
|
self.filename = os.path.abspath(filename) |
129 |
|
|
130 |
self.projection = projection |
self.projection = projection |
131 |
self.fill = fill |
self.fill = fill |
132 |
self.stroke = stroke |
self.stroke = stroke |
166 |
self.shapetree = shptree.SHPTree(self.shapefile.cobject(), 2, |
self.shapetree = shptree.SHPTree(self.shapefile.cobject(), 2, |
167 |
maxdepth) |
maxdepth) |
168 |
|
|
169 |
|
def Destroy(self): |
170 |
|
BaseLayer.Destroy(self) |
171 |
|
if self.shapefile is not None: |
172 |
|
self.shapefile.close() |
173 |
|
self.shapefile = None |
174 |
|
self.shapetree = None |
175 |
|
self.table.Destroy() |
176 |
|
|
177 |
def BoundingBox(self): |
def BoundingBox(self): |
178 |
"""Return the layer's bounding box in the intrinsic coordinate system. |
"""Return the layer's bounding box in the intrinsic coordinate system. |
179 |
|
|
254 |
"""Set the layer's stroke width.""" |
"""Set the layer's stroke width.""" |
255 |
self.stroke_width = width |
self.stroke_width = width |
256 |
self.changed(LAYER_LEGEND_CHANGED, self) |
self.changed(LAYER_LEGEND_CHANGED, self) |
257 |
|
|
258 |
|
def TreeInfo(self): |
259 |
|
items = [] |
260 |
|
|
261 |
|
if self.Visible(): |
262 |
|
items.append("Shown") |
263 |
|
else: |
264 |
|
items.append("Hidden") |
265 |
|
items.append("Shapes: %d" % self.NumShapes()) |
266 |
|
|
267 |
|
bbox = self.LatLongBoundingBox() |
268 |
|
if bbox is not None: |
269 |
|
items.append("Extent (lat-lon): (%g, %g, %g, %g)" % bbox) |
270 |
|
else: |
271 |
|
items.append("Extent (lat-lon):") |
272 |
|
items.append("Shapetype: %s" % shapetype_names[self.ShapeType()]) |
273 |
|
|
274 |
|
def color_string(color): |
275 |
|
if color is None: |
276 |
|
return "None" |
277 |
|
return "(%.3f, %.3f, %.3f)" % (color.red, color.green, color.blue) |
278 |
|
items.append("Fill: " + color_string(self.fill)) |
279 |
|
items.append("Outline: " + color_string(self.stroke)) |
280 |
|
|
281 |
|
return ("Layer '%s'" % self.Title(), items) |