def __init__(self, shapefile, idvariable=None, attribute=False): self.points = {} self.npoints = 0 if idvariable: ids = get_ids(shapefile, idvariable) else: ids = None pts = ps.open(shapefile) # Get attributes if requested if attribute == True: dbname = os.path.splitext(shapefile)[0] + '.dbf' db = ps.open(dbname) else: db = None for i, pt in enumerate(pts): if ids and db: self.points[ids[i]] = {'coordinates':pt, 'properties':db[i]} elif ids and not db: self.points[ids[i]] = {'coordinates':pt, 'properties':None} elif not ids and db: self.points[i] = {'coordinates':pt, 'properties':db[i]} else: self.points[i] = {'coordinates':pt, 'properties':None} pts.close() if db: db.close() self.npoints = len(list(self.points.keys()))
def __init__(self, shapefile, idvariable=None, attribute=False): self.points = {} self.npoints = 0 if idvariable: ids = get_ids(shapefile, idvariable) else: ids = None pts = ps.open(shapefile) # Get attributes if requested if attribute == True: dbname = os.path.splitext(shapefile)[0] + '.dbf' db = ps.open(dbname) else: db = None for i, pt in enumerate(pts): if ids and db: self.points[ids[i]] = {'coordinates':pt, 'properties':db[i]} elif ids and not db: self.points[ids[i]] = {'coordinates':pt, 'properties':None} elif not ids and db: self.points[i] = {'coordinates':pt, 'properties':db[i]} else: self.points[i] = {'coordinates':pt, 'properties':None} pts.close() if db: db.close() self.npoints = len(self.points.keys())