def polysFromSHP(polysFilename, datafield, polySubset): R.importLibrary('sp') shapes = shapelib.open(polysFilename) data = dbflib.open(polysFilename) polyList = [] for i in range(shapes.info()[0]): shp = shapes.read_object(i) d = data.read_record(i)[datafield] if len(polySubset) != 0: for item in polySubset: if item == d: p = SpatialPolygon(i, shp.vertices(), d) polyList.append(p) else: p = SpatialPolygon(i, shp.vertices(), d) polyList.append(p) return polyList
def polysFromSHP (polysFilename, datafield, polySubset): R.importLibrary ('sp') shapes = shapelib.open(polysFilename) data = dbflib.open (polysFilename) polyList = [] for i in range (shapes.info ()[0]): shp = shapes.read_object (i) d = data.read_record (i)[datafield] if len(polySubset) != 0: for item in polySubset: if item == d: p = SpatialPolygon (i, shp.vertices (), d) polyList.append(p) else: p = SpatialPolygon (i, shp.vertices (), d) polyList.append(p) return polyList
def __init__ (self, shp, data, source, geom=None): Polygon.__init__ (self, data, source) self.simplePolys = [] self._geom = geom maxXList = [] maxYList = [] minXList = [] minYList = [] for s in shp: simple = SimpleSpatialPolygon (s) self.simplePolys.append (simple) maxXList.append (simple.max[0]) maxYList.append (simple.max[1]) minXList.append (simple.min[0]) minYList.append (simple.min[1]) maxX = max (maxXList) maxY = max (maxYList) minX = min (minXList) minY = min (minYList) self.bounds = BoundingBox ((maxX, maxY), (minX, minY)) if not SpatialPolygon.pointInPolygon: R.importLibrary ('sp') SpatialPolygon.pointInPolygon = True
def __init__(self, shp, data, source, geom=None): Polygon.__init__(self, data, source) self.simplePolys = [] self._geom = geom maxXList = [] maxYList = [] minXList = [] minYList = [] for s in shp: simple = SimpleSpatialPolygon(s) self.simplePolys.append(simple) maxXList.append(simple.max[0]) maxYList.append(simple.max[1]) minXList.append(simple.min[0]) minYList.append(simple.min[1]) maxX = max(maxXList) maxY = max(maxYList) minX = min(minXList) minY = min(minYList) self.bounds = BoundingBox((maxX, maxY), (minX, minY)) if not SpatialPolygon.pointInPolygon: R.importLibrary('sp') SpatialPolygon.pointInPolygon = True