/[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 1535 by bh, Fri Aug 1 14:27:13 2003 UTC revision 1559 by bh, Thu Aug 7 17:32:20 2003 UTC
# Line 32  shapelib_shapetypes = {shapelib.SHPT_POL Line 32  shapelib_shapetypes = {shapelib.SHPT_POL
32                         shapelib.SHPT_ARC: SHAPETYPE_ARC,                         shapelib.SHPT_ARC: SHAPETYPE_ARC,
33                         shapelib.SHPT_POINT: SHAPETYPE_POINT}                         shapelib.SHPT_POINT: SHAPETYPE_POINT}
34    
35    #
36    # Raw shape data formats
37    #
38    
39  class Shape:  # Raw data is the same as that returned by the points method.
40    RAW_PYTHON = "RAW_PYTHON"
41    
42      """Represent one shape"""  # Raw data is a shapefile. The Shape object will use the shapeid as the
43    # raw data.
44    RAW_SHAPEFILE = "RAW_SHAPEFILE"
45    
     def __init__(self, points):  
         self.points = points  
         #self.compute_bbox()  
         self.bbox = None  
46    
47      def compute_bbox(self):  class ShapefileShape:
         if self.bbox is not None:  
             return self.bbox  
48    
49          xs = []      """Represent one shape of a shapefile"""
         ys = []  
         for x, y in self.points:  
             xs.append(x)  
             ys.append(y)  
         self.llx = min(xs)  
         self.lly = min(ys)  
         self.urx = max(xs)  
         self.ury = max(ys)  
50    
51          self.bbox = (self.llx, self.lly, self.urx, self.ury)      def __init__(self, shapefile, shapeid):
52            self.shapefile = shapefile
53            self.shapeid = shapeid
54    
55          return self.bbox      def compute_bbox(self):
56            """
57            Return the bounding box of the shape as a tuple (minx,miny,maxx,maxy)
58            """
59            xs = []
60            ys = []
61            for part in self.Points():
62                for x, y in part:
63                    xs.append(x)
64                    ys.append(y)
65            return (min(xs), min(ys), max(xs), max(ys))
66    
67      def Points(self):      def Points(self):
68          return self.points          """Return the coordinates of the shape as a list of lists of pairs"""
69            shape = self.shapefile.read_object(self.shapeid)
70            points = shape.vertices()
71            if self.shapefile.info()[1] == shapelib.SHPT_POINT:
72                points = [points]
73            return points
74    
75        def RawData(self):
76            """Return the shape id to use with the shapefile"""
77            return self.shapeid
78    
79        def Shapefile(self):
80            """Return the shapefile object"""
81            return self.shapefile
82    
83    
84  class ShapeTable(transientdb.AutoTransientTable):  class ShapeTable(transientdb.AutoTransientTable):
# Line 145  class ShapefileStore: Line 161  class ShapefileStore:
161          """          """
162          return self.shapetype          return self.shapetype
163    
164        def RawShapeFormat(self):
165            """Return the raw data format of the shape data, i.e. RAW_SHAPEFILE"""
166            return RAW_SHAPEFILE
167    
168      def NumShapes(self):      def NumShapes(self):
169          """Return the number of shapes in the shape store"""          """Return the number of shapes in the shape store"""
170          return self.numshapes          return self.numshapes
# Line 182  class ShapefileStore: Line 202  class ShapefileStore:
202    
203      def Shape(self, index):      def Shape(self, index):
204          """Return the shape with index index"""          """Return the shape with index index"""
205          shape = self.shapefile.read_object(index)          return ShapefileShape(self.shapefile, index)
   
         if self.ShapeType() == SHAPETYPE_POINT:  
             points = shape.vertices()  
         else:  
             #for poly in shape.vertices():  
             poly = shape.vertices()[0]  
             points = []  
             for x, y in poly:  
                 points.append((x, y))  
   
         return Shape(points)  
206    
207    
208    

Legend:
Removed from v.1535  
changed lines
  Added in v.1559

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26