예제 #1
0
 def load(self):
     query = Query(self._connection)
     query.SELECT('gid', self.name)
     query.SELECT('the_geom', self.name, 'AsText')
     query.SELECT(self._primary, self.name)
     for key, gen in self._fields:
         query.SELECT(key, self.name)
     whereList = []
     try:
         for entry in self._subset:
             item = self.name + '.' + self._primary + '=\'' + entry + '\''
             whereList.append(item)
             query.where = ' OR '.join(whereList)
     except TypeError:
         pass
     polyDict = PolygonDictionary()
     pairs = []
     for entry in query:
         d = []
         for key, gen in self._fields:
             d.append((gen, entry[key]))
         data = Dictionary()
         data.update(d)
         p = GeneralizedPolygon(enum.ABSTRACT, entry['gid'],
                                entry['the_geom'], data, self)
         polyKey = keygen(entry[self._primary])
         pairs.append((polyKey, p))
     polyDict.update(pairs)
     return polyDict
예제 #2
0
 def load(self):
     shapes = shapelib.open(self.name)
     data = dbflib.open(self.name)
     polys = PolygonDictionary()
     for i in range(shapes.info()[0]):
         shp = shapes.read_object(i)
         d = data.read_record(i)[self._primary]
         if self._subset != None:
             for item in self._subset:
                 if item == d:
                     p = SpatialPolygon(shp.vertices(), [], self)
                     polys.update({d: p})
         else:
             p = SpatialPolygon(shp.vertices(), [], self)
             polys.update({d: p})
     return polys