31 |
def __init__(self, points): |
def __init__(self, points): |
32 |
self.points = points |
self.points = points |
33 |
#self.compute_bbox() |
#self.compute_bbox() |
34 |
|
self.bbox = None |
35 |
|
|
36 |
def compute_bbox(self): |
def compute_bbox(self): |
37 |
|
if self.bbox is not None: |
38 |
|
return self.bbox |
39 |
|
|
40 |
xs = [] |
xs = [] |
41 |
ys = [] |
ys = [] |
42 |
for x, y in self.points: |
for x, y in self.points: |
47 |
self.urx = max(xs) |
self.urx = max(xs) |
48 |
self.ury = max(ys) |
self.ury = max(ys) |
49 |
|
|
50 |
|
self.bbox = (self.llx, self.lly, self.urx, self.ury) |
51 |
|
|
52 |
|
return self.bbox |
53 |
|
|
54 |
def Points(self): |
def Points(self): |
55 |
return self.points |
return self.points |
56 |
|
|
74 |
|
|
75 |
"""Base class for the layers.""" |
"""Base class for the layers.""" |
76 |
|
|
77 |
def __init__(self, title, visible = 1): |
def __init__(self, title, visible = True): |
78 |
"""Initialize the layer. |
"""Initialize the layer. |
79 |
|
|
80 |
title -- the title |
title -- the title |
114 |
fill = Color.Transparent, |
fill = Color.Transparent, |
115 |
stroke = Color.Black, |
stroke = Color.Black, |
116 |
lineWidth = 1, |
lineWidth = 1, |
117 |
visible = 1): |
visible = True): |
118 |
"""Initialize the layer. |
"""Initialize the layer. |
119 |
|
|
120 |
title -- the title |
title -- the title |
184 |
maxdepth) |
maxdepth) |
185 |
if self.__classification is not None: |
if self.__classification is not None: |
186 |
fieldname = self.__classification.GetField() |
fieldname = self.__classification.GetField() |
187 |
if not self.store.Table().field_info_by_name(fieldname): |
if fieldname is not None and \ |
188 |
|
not self.store.Table().field_info_by_name(fieldname): |
189 |
self.SetClassification(None) |
self.SetClassification(None) |
190 |
self.changed(LAYER_CHANGED, self) |
self.changed(LAYER_CHANGED, self) |
191 |
|
|
218 |
else: |
else: |
219 |
return None |
return None |
220 |
|
|
221 |
|
def ShapesBoundingBox(self, shapes): |
222 |
|
"""Return a bounding box in lat/long coordinates for the given |
223 |
|
list of shape ids. |
224 |
|
|
225 |
|
If shapes is None or empty, return None. |
226 |
|
""" |
227 |
|
|
228 |
|
if shapes is None or len(shapes) == 0: return None |
229 |
|
|
230 |
|
llx = [] |
231 |
|
lly = [] |
232 |
|
urx = [] |
233 |
|
ury = [] |
234 |
|
|
235 |
|
if self.projection is not None: |
236 |
|
inverse = lambda x, y: self.projection.Inverse(x, y) |
237 |
|
else: |
238 |
|
inverse = lambda x, y: (x, y) |
239 |
|
|
240 |
|
for id in shapes: |
241 |
|
left, bottom, right, top = self.Shape(id).compute_bbox() |
242 |
|
|
243 |
|
left, bottom = inverse(left, bottom) |
244 |
|
right, top = inverse(right, top) |
245 |
|
|
246 |
|
llx.append(left) |
247 |
|
lly.append(bottom) |
248 |
|
urx.append(right) |
249 |
|
ury.append(top) |
250 |
|
|
251 |
|
return (min(llx), min(lly), max(urx), max(ury)) |
252 |
|
|
253 |
def GetFieldType(self, fieldName): |
def GetFieldType(self, fieldName): |
254 |
info = self.table.field_info_by_name(fieldName) |
info = self.table.field_info_by_name(fieldName) |
255 |
if info is not None: |
if info is not None: |
285 |
def ShapesInRegion(self, box): |
def ShapesInRegion(self, box): |
286 |
"""Return the ids of the shapes that overlap the box. |
"""Return the ids of the shapes that overlap the box. |
287 |
|
|
288 |
Box is a tuple (left, bottom, right, top) in the coordinate |
Box is a tuple (left, bottom, right, top) in unprojected coordinates. |
|
system used by the layer's shapefile. |
|
289 |
""" |
""" |
290 |
left, bottom, right, top = box |
left, bottom, right, top = box |
291 |
|
|
292 |
|
if self.projection is not None: |
293 |
|
left, bottom = self.projection.Forward(left, bottom) |
294 |
|
right, top = self.projection.Forward(right, top) |
295 |
|
|
296 |
return self.shapetree.find_shapes((left, bottom), (right, top)) |
return self.shapetree.find_shapes((left, bottom), (right, top)) |
297 |
|
|
298 |
|
def GetProjection(self): |
299 |
|
return self.projection |
300 |
|
|
301 |
def SetProjection(self, projection): |
def SetProjection(self, projection): |
302 |
"""Set the layer's projection""" |
"""Set the layer's projection""" |
303 |
self.projection = projection |
self.projection = projection |
353 |
items.append(_("Extent (lat-lon):")) |
items.append(_("Extent (lat-lon):")) |
354 |
items.append(_("Shapetype: %s") % shapetype_names[self.ShapeType()]) |
items.append(_("Shapetype: %s") % shapetype_names[self.ShapeType()]) |
355 |
|
|
356 |
|
if self.projection and len(self.projection.params) > 0: |
357 |
|
items.append((_("Projection"), |
358 |
|
[str(param) for param in self.projection.params])) |
359 |
|
|
360 |
items.append(self.__classification) |
items.append(self.__classification) |
361 |
|
|
362 |
return (_("Layer '%s'") % self.Title(), items) |
return (_("Layer '%s'") % self.Title(), items) |
363 |
|
|
364 |
|
|