libpysal API reference

Spatial Weights

libpysal.weights.W(neighbors[, weights, …])

Spatial weights class.

Distance Weights

libpysal.weights.DistanceBand(data, threshold)

Spatial weights based on distance band.

libpysal.weights.Kernel(data[, bandwidth, …])

Spatial weights based on kernel functions.

libpysal.weights.KNN(data[, k, p, ids, …])

Creates nearest neighbor weights matrix based on k nearest neighbors.

Contiguity Weights

libpysal.weights.Queen(polygons, **kw)

Construct a weights object from a collection of pysal polygons that share at least one vertex.

libpysal.weights.Rook(polygons, **kw)

Construct a weights object from a collection of pysal polygons that share at least one edge.

libpysal.weights.Voronoi(points)

Voronoi weights for a 2-d point set

libpysal.weights.W(neighbors[, weights, …])

Spatial weights class.

spint Weights

libpysal.weights.WSP(sparse[, id_order])

Thin W class for spreg.

libpysal.weights.netW(link_list[, share, …])

Create a network-contiguity based weight object based on different nodal relationships encoded in a network.

libpysal.weights.mat2L(edge_matrix)

Convert a matrix denoting network connectivity (edges or flows) to a list denoting edges

libpysal.weights.ODW(Wo, Wd[, transform, …])

Constructs an o*d by o*d origin-destination style spatial weight for o*d flows using standard spatial weights on o origins and d destinations.

libpysal.weights.vecW(origin_x, origin_y, …)

Distance-based spatial weight for vectors that is computed using a 4-dimensional distance between the origin x,y-coordinates and the destination x,y-coordinates

Weights Util Classes and Functions

libpysal.weights.block_weights(regimes[, …])

Construct spatial weights for regime neighbors.

libpysal.weights.lat2W([nrows, ncols, rook, …])

Create a W object for a regular lattice.

libpysal.weights.comb(items[, n])

Combinations of size n taken from items

libpysal.weights.order(w[, kmax])

Determine the non-redundant order of contiguity up to a specific order.

libpysal.weights.higher_order(w[, k])

Contiguity weights object of order k.

libpysal.weights.shimbel(w)

Find the Shimbel matrix for first order contiguity matrix.

libpysal.weights.remap_ids(w, old2new[, …])

Remaps the IDs in a spatial weights object.

libpysal.weights.full2W(m[, ids])

Create a PySAL W object from a full array.

libpysal.weights.full(w)

Generate a full numpy array.

libpysal.weights.WSP2W(wsp[, silence_warnings])

Convert a pysal WSP object (thin weights matrix) to a pysal W object.

libpysal.weights.get_ids(in_shps, idVariable)

Gets the IDs from the DBF file that moves with a given shape file or a geopandas.GeoDataFrame.

libpysal.weights.get_points_array_from_shapefile(…)

Gets a data array of x and y coordinates from a given shapefile.

Weights user Classes and Functions

libpysal.weights.min_threshold_distance(data)

Get the maximum nearest neighbor distance.

libpysal.weights.lat2SW([nrows, ncols, …])

Create a sparse W matrix for a regular lattice.

libpysal.weights.w_local_cluster(w)

Local clustering coefficients for each unit as a node in a graph.

libpysal.weights.higher_order_sp(w[, k, …])

Contiguity weights for either a sparse W or W for order k.

libpysal.weights.hexLat2W([nrows, ncols])

Create a W object for a hexagonal lattice.

libpysal.weights.attach_islands(w, w_knn1)

Attach nearest neighbor to islands in spatial weight w.

libpysal.weights.nonplanar_neighbors(w, …)

Detect neighbors for non-planar polygon collections

libpysal.weights.fuzzy_contiguity(\*args, …)

libpysal.weights.min_threshold_dist_from_shapefile(…)

Get the maximum nearest neighbor distance between observations in the shapefile.

libpysal.weights.build_lattice_shapefile(…)

Build a lattice shapefile with nrows rows and ncols cols.

libpysal.weights.spw_from_gal(galfile)

Sparse scipy matrix for w from a gal file.

Set Theoretic Weights

libpysal.weights.w_union(w1, w2[, …])

Returns a binary weights object, w, that includes all neighbor pairs that exist in either w1 or w2.

libpysal.weights.w_intersection(w1, w2[, …])

Returns a binary weights object, w, that includes only those neighbor pairs that exist in both w1 and w2.

libpysal.weights.w_difference(w1, w2[, …])

Returns a binary weights object, w, that includes only neighbor pairs in w1 that are not in w2.

libpysal.weights.w_symmetric_difference(w1, w2)

Returns a binary weights object, w, that includes only neighbor pairs that are not shared by w1 and w2.

libpysal.weights.w_subset(w1, ids[, …])

Returns a binary weights object, w, that includes only those observations in ids.

libpysal.weights.w_clip(w1, w2[, outSP, …])

Clip a continuous W object (w1) with a different W object (w2) so only cells where w2 has a non-zero value remain with non-zero values in w1.

Spatial Lag

libpysal.weights.lag_spatial(w, y)

Spatial lag operator.

libpysal.weights.lag_categorical(w, y[, ties])

Spatial lag operator for categorical variables.

cg: Computational Geometry

alpha_shapes

libpysal.cg.alpha_shape(xys, alpha)

Alpha-shape delineation (Edelsbrunner, Kirkpatrick & Seidel, 1983) from a collection of points …

libpysal.cg.alpha_shape_auto(xys[, step, …])

Computation of alpha-shape delineation with automated selection of alpha.

voronoi

libpysal.cg.voronoi_frames(points[, radius])

Composite helper to return Voronoi regions and generator points as individual dataframes

sphere

libpysal.cg.RADIUS_EARTH_KM

float(x) -> floating point number

libpysal.cg.RADIUS_EARTH_MILES

float(x) -> floating point number

libpysal.cg.arcdist(pt0, pt1[, radius])

Arc distance between two points on a sphere.

libpysal.cg.arcdist2linear(arc_dist[, radius])

Convert an arc distance (spherical earth) to a linear distance (R3) in the unit sphere.

libpysal.cg.brute_knn(pts, k[, mode])

valid modes are [‘arc’,’xrz’]

libpysal.cg.fast_knn(pts, k[, return_dist])

Computes k nearest neighbors on a sphere.

libpysal.cg.fast_threshold(pts, dist[, radius])

Find all neighbors on a sphere within a threshold distance

libpysal.cg.linear2arcdist(linear_dist[, radius])

Convert a linear distance in the unit sphere (R3) to an arc distance based on supplied radius

libpysal.cg.toLngLat(xyz)

Convert x,y,z to latitude and longitude

libpysal.cg.toXYZ(pt)

Convert a point’s latitude and longitude to x,y,z

libpysal.cg.lonlat(pointslist)

Converts point order from lat-lon tuples to lon-lat (x,y) tuples

libpysal.cg.harcdist(p0, p1[, lonx, radius])

Alternative arc distance function, uses haversine formula

libpysal.cg.geointerpolate(p0, p1, t[, lonx])

Finds a point on a sphere along the great circle distance between two points on a sphere also known as a way point in great circle navigation

libpysal.cg.geogrid(pup, pdown, k[, lonx])

Computes a k+1 by k+1 set of grid points for a bounding box in lat-lon uses geointerpolate

shapes

libpysal.cg.Point(loc)

Geometric class for point objects.

libpysal.cg.LineSegment(start_pt, end_pt)

Geometric representation of line segment objects.

libpysal.cg.Line(m, b)

Geometric representation of line objects.

libpysal.cg.Ray(origin, second_p)

Geometric representation of ray objects.

libpysal.cg.Chain(vertices)

Geometric representation of a chain, also known as a polyline.

libpysal.cg.Polygon(vertices[, holes])

Geometric representation of polygon objects.

libpysal.cg.Rectangle(left, lower, right, upper)

Geometric representation of rectangle objects.

libpysal.cg.asShape(obj)

Returns a pysal shape object from obj.

standalone

libpysal.cg.bbcommon(bb, bbother)

Old Stars method for bounding box overlap testing Also defined in pysal.weights._cont_binning

libpysal.cg.get_bounding_box(items)

Find bounding box for a list of geometries

libpysal.cg.get_angle_between(ray1, ray2)

Returns the angle formed between a pair of rays which share an origin get_angle_between(Ray, Ray) -> number

libpysal.cg.is_collinear(p1, p2, p3)

Returns whether a triplet of points is collinear.

libpysal.cg.get_segments_intersect(seg1, seg2)

Returns the intersection of two segments.

libpysal.cg.get_segment_point_intersect(seg, pt)

Returns the intersection of a segment and point.

libpysal.cg.get_polygon_point_intersect(poly, pt)

Returns the intersection of a polygon and point.

libpysal.cg.get_rectangle_point_intersect(…)

Returns the intersection of a rectangle and point.

libpysal.cg.get_ray_segment_intersect(ray, seg)

Returns the intersection of a ray and line segment.

libpysal.cg.get_rectangle_rectangle_intersection(r0, r1)

Returns the intersection between two rectangles.

libpysal.cg.get_polygon_point_dist(poly, pt)

Returns the distance between a polygon and point.

libpysal.cg.get_points_dist(pt1, pt2)

Returns the distance between a pair of points.

libpysal.cg.get_segment_point_dist(seg, pt)

Returns the distance between a line segment and point and distance along the segment of the closest point on the segment to the point as a ratio of the length of the segment.

libpysal.cg.get_point_at_angle_and_dist(ray, …)

Returns the point at a distance and angle relative to the origin of a ray.

libpysal.cg.convex_hull(points)

Returns the convex hull of a set of points.

libpysal.cg.is_clockwise(vertices)

Returns whether a list of points describing a polygon are clockwise or counterclockwise.

libpysal.cg.point_touches_rectangle(point, rect)

Returns True if the point is in the rectangle or touches it’s boundary.

libpysal.cg.get_shared_segments(poly1, poly2)

Returns the line segments in common to both polygons.

libpysal.cg.distance_matrix(X[, p, threshold])

Distance Matrices

locators

libpysal.cg.Grid(bounds, resolution)

Representation of a binning data structure.

libpysal.cg.PointLocator(points)

An abstract representation of a point indexing data structure.

libpysal.cg.PolygonLocator(polygons)

An abstract representation of a polygon indexing data structure.

kdtree

libpysal.cg.KDTree(data[, leafsize, …])

kd-tree built on top of kd-tree functionality in scipy.

io

libpysal.io.open

alias of libpysal.io.fileio.FileIO

libpysal.io.fileio.FileIO([dataPath, mode, …])

Metaclass for supporting spatial data file read and write

examples

libpysal.examples.available([verbose])

List available datasets

libpysal.examples.explain(name)

Explain a dataset by name

libpysal.examples.get_path(example_name[, raw])

Get path of example folders