/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/data.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/Model/data.py

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

revision 1564 by bh, Thu Aug 7 19:19:56 2003 UTC revision 1921 by bh, Mon Nov 3 18:42:27 2003 UTC
# Line 7  Line 7 
7    
8  """Data source abstractions"""  """Data source abstractions"""
9    
10    from __future__ import generators
11    
12  __version__ = "$Revision$"  __version__ = "$Revision$"
13  # $Source$  # $Source$
14  # $Id$  # $Id$
# Line 43  RAW_PYTHON = "RAW_PYTHON" Line 45  RAW_PYTHON = "RAW_PYTHON"
45  # raw data.  # raw data.
46  RAW_SHAPEFILE = "RAW_SHAPEFILE"  RAW_SHAPEFILE = "RAW_SHAPEFILE"
47    
48    # Raw data in well-known text format
49    RAW_WKT = "RAW_WKT"
50    
51    
52  class ShapefileShape:  class ShapefileShape:
53    
# Line 64  class ShapefileShape: Line 69  class ShapefileShape:
69                  ys.append(y)                  ys.append(y)
70          return (min(xs), min(ys), max(xs), max(ys))          return (min(xs), min(ys), max(xs), max(ys))
71    
72        def ShapeID(self):
73            return self.shapeid
74    
75      def Points(self):      def Points(self):
76          """Return the coordinates of the shape as a list of lists of pairs"""          """Return the coordinates of the shape as a list of lists of pairs"""
77          shape = self.shapefile.read_object(self.shapeid)          shape = self.shapefile.read_object(self.shapeid)
# Line 191  class ShapefileStore: Line 199  class ShapefileStore:
199          """          """
200          return self.bbox          return self.bbox
201    
202      def ShapesInRegion(self, box):      def ShapesInRegion(self, bbox):
203          """Return the ids of the shapes that overlap the box.          """Return an iterable over the shapes that overlap the bounding box.
204    
205          Box is a tuple (left, bottom, right, top) in the coordinate          The bbox parameter should be the bounding box as a tuple in the
206          system used used in the shapefile.          form (minx, miny, maxx, maxy) in the coordinate system of the
207          """          shape store.
208          left, bottom, right, top = box          """
209          return self.shapetree.find_shapes((left, bottom), (right, top))          # Bind a few globals to locals to make it a bit faster
210            cls = ShapefileShape
211            shapefile = self.shapefile
212    
213            left, bottom, right, top = bbox
214            for i in self.shapetree.find_shapes((left, bottom), (right, top)):
215                yield cls(shapefile, i)
216    
217        def AllShapes(self):
218            """Return an iterable over the shapes in the shape store."""
219            for i in xrange(self.NumShapes()):
220                yield ShapefileShape(self.shapefile, i)
221    
222      def Shape(self, index):      def Shape(self, index):
223          """Return the shape with index index"""          """Return the shape with index index"""
# Line 257  class DerivedShapeStore: Line 276  class DerivedShapeStore:
276          """          """
277          return self.shapestore.ShapesInRegion(bbox)          return self.shapestore.ShapesInRegion(bbox)
278    
279        def AllShapes(self):
280            """Return an iterable over the shapes in the shape store.
281    
282            This method is simply delegated to the shapestore the
283            DerivedShapeStore was instantiated with.
284            """
285            return self.shapestore.AllShapes()
286    
287      def ShapeType(self):      def ShapeType(self):
288          """Return the type of the shapes in the layer.          """Return the type of the shapes in the layer.
289    

Legend:
Removed from v.1564  
changed lines
  Added in v.1921

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26