9 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
10 |
|
|
11 |
from math import log, ceil |
from math import log, ceil |
12 |
|
import warnings |
13 |
|
|
14 |
from Thuban import _ |
from Thuban import _ |
15 |
import shapelib, shptree |
import shapelib, shptree |
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 |
170 |
|
|
171 |
self.UnsetModified() |
self.UnsetModified() |
172 |
|
|
173 |
|
def __getattr__(self, attr): |
174 |
|
"""Access to some attributes for backwards compatibility |
175 |
|
|
176 |
|
The attributes implemented here are now held by the shapestore |
177 |
|
if at all. For backwards compatibility pretend that they are |
178 |
|
still there but issue a DeprecationWarning when they are |
179 |
|
accessed. |
180 |
|
""" |
181 |
|
if attr in ("table", "shapetable"): |
182 |
|
value = self.store.Table() |
183 |
|
elif attr == "shapefile": |
184 |
|
value = self.store.Shapefile() |
185 |
|
elif attr == "filename": |
186 |
|
value = self.store.FileName() |
187 |
|
else: |
188 |
|
raise AttributeError, attr |
189 |
|
warnings.warn("The Layer attribute %r is deprecated." |
190 |
|
" It's value can be accessed through the shapestore" |
191 |
|
% attr, DeprecationWarning, stacklevel = 2) |
192 |
|
return value |
193 |
|
|
194 |
def SetShapeStore(self, store): |
def SetShapeStore(self, store): |
195 |
self.store = store |
self.store = store |
196 |
self.shapefile = self.store.Shapefile() |
shapefile = self.store.Shapefile() |
|
self.shapetable = self.store.Table() |
|
|
if hasattr(self.store, "FileName"): |
|
|
self.filename = self.store.FileName() |
|
|
self.table = self.shapetable |
|
197 |
|
|
198 |
numshapes, shapetype, mins, maxs = self.shapefile.info() |
numshapes, shapetype, mins, maxs = shapefile.info() |
199 |
self.numshapes = numshapes |
self.numshapes = numshapes |
200 |
self.shapetype = shapelib_shapetypes[shapetype] |
self.shapetype = shapelib_shapetypes[shapetype] |
201 |
|
|
215 |
else: |
else: |
216 |
maxdepth = int(ceil(log(self.numshapes / 4.0) / log(4))) |
maxdepth = int(ceil(log(self.numshapes / 4.0) / log(4))) |
217 |
|
|
218 |
self.shapetree = shptree.SHPTree(self.shapefile.cobject(), 2, |
self.shapetree = shptree.SHPTree(shapefile.cobject(), 2, |
219 |
maxdepth) |
maxdepth) |
220 |
# Set the classification to None if there is a classification |
# Set the classification to None if there is a classification |
221 |
# and the new shapestore doesn't have a table with a suitable |
# and the new shapestore doesn't have a table with a suitable |
238 |
def Destroy(self): |
def Destroy(self): |
239 |
BaseLayer.Destroy(self) |
BaseLayer.Destroy(self) |
240 |
self.SetClassification(None) |
self.SetClassification(None) |
|
self.store = self.shapetree = None |
|
|
self.table = self.shapefile = self.shapetable = None |
|
241 |
|
|
242 |
def BoundingBox(self): |
def BoundingBox(self): |
243 |
"""Return the layer's bounding box in the intrinsic coordinate system. |
"""Return the layer's bounding box in the intrinsic coordinate system. |
294 |
return (min(llx), min(lly), max(urx), max(ury)) |
return (min(llx), min(lly), max(urx), max(ury)) |
295 |
|
|
296 |
def GetFieldType(self, fieldName): |
def GetFieldType(self, fieldName): |
297 |
if self.table.HasColumn(fieldName): |
table = self.store.Table() |
298 |
return self.table.Column(fieldName).type |
if table.HasColumn(fieldName): |
299 |
|
return table.Column(fieldName).type |
300 |
return None |
return None |
301 |
|
|
302 |
|
def HasShapes(self): |
303 |
|
return True |
304 |
|
|
305 |
def NumShapes(self): |
def NumShapes(self): |
306 |
"""Return the number of shapes in the layer""" |
"""Return the number of shapes in the layer""" |
307 |
return self.numshapes |
return self.numshapes |
314 |
|
|
315 |
def Shape(self, index): |
def Shape(self, index): |
316 |
"""Return the shape with index index""" |
"""Return the shape with index index""" |
317 |
shape = self.shapefile.read_object(index) |
shape = self.store.Shapefile().read_object(index) |
318 |
|
|
319 |
if self.shapetype == SHAPETYPE_POINT: |
if self.shapetype == SHAPETYPE_POINT: |
320 |
points = shape.vertices() |
points = shape.vertices() |