/[thuban]/trunk/thuban/Thuban/Model/layer.py
ViewVC logotype

Diff of /trunk/thuban/Thuban/Model/layer.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 794 by jonathan, Wed Apr 30 17:00:52 2003 UTC revision 839 by bh, Tue May 6 15:54:18 2003 UTC
# Line 31  class Shape: Line 31  class Shape:
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:
# Line 43  class Shape: Line 47  class Shape:
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    
# Line 177  class Layer(BaseLayer): Line 185  class Layer(BaseLayer):
185          if self.__classification is not None:          if self.__classification is not None:
186              fieldname = self.__classification.GetField()              fieldname = self.__classification.GetField()
187              if fieldname is not None and \              if fieldname is not None and \
188                 not self.store.Table().field_info_by_name(fieldname):                 not self.store.Table().HasColumn(fieldname):
189                  self.SetClassification(None)                  self.SetClassification(None)
190          self.changed(LAYER_CHANGED, self)          self.changed(LAYER_CHANGED, self)
191    
# Line 210  class Layer(BaseLayer): Line 218  class Layer(BaseLayer):
218          else:          else:
219              return None              return None
220    
221      def GetFieldType(self, fieldName):      def ShapesBoundingBox(self, shapes):
222          info = self.table.field_info_by_name(fieldName)          """Return a bounding box in lat/long coordinates for the given
223          if info is not None:          list of shape ids.
224              return info[0]  
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:          else:
238              return None              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):
254            if self.table.HasColumn(fieldName):
255                return self.table.Column(fieldName).type
256            return None
257    
258      def NumShapes(self):      def NumShapes(self):
259          """Return the number of shapes in the layer"""          """Return the number of shapes in the layer"""

Legend:
Removed from v.794  
changed lines
  Added in v.839

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26