def threshold_continuousW_from_shapefile(shapefile, threshold, p=2, alpha=-1, idVariable=None, radius=None): """ Threshold distance based continuous weights from a shapefile. Parameters ---------- shapefile : string shapefile name with shp suffix threshold : float distance band p : float Minkowski p-norm distance metric parameter: 1<=p<=infinity 2: Euclidean distance 1: Manhattan distance alpha : float distance decay parameter for weight (default -1.0) if alpha is positive the weights will not decline with distance. idVariable : string name of a column in the shapefile's DBF to use for ids radius : float If supplied arc_distances will be calculated based on the given radius. p will be ignored. Returns ------- w : W instance; Weights object with continuous weights. Examples -------- >>> w = threshold_continuousW_from_shapefile(pysal.examples.get_path("columbus.shp"),0.62,idVariable="POLYID") >>> w.weights[1] [1.6702346893743334, 1.7250729841938093] Notes ----- Supports polygon or point shapefiles. For polygon shapefiles, distance is based on polygon centroids. Distances are defined using coordinates in shapefile which are assumed to be projected and not geographical coordinates. """ data = get_points_array_from_shapefile(shapefile) if radius is not None: data = pysal.cg.KDTree(data, distance_metric='Arc', radius=radius) if idVariable: ids = get_ids(shapefile, idVariable) w = DistanceBand(data, threshold=threshold, p=p, alpha=alpha, binary=False) w.remap_ids(ids) else: w = threshold_continuousW_from_array(data, threshold, p=p, alpha=alpha) w.set_shapefile(shapefile,idVariable) return w