# libpysal API reference

## Spatial Graph

Modern implementation of spatial graphs encoding spatial weights matrices.

`graph.Graph`(adjacency[, transformation, ...]) | Graph class encoding spatial weights matrices
`graph.GraphSummary`(graph[, asymmetries]) | Graph Summary
`graph.read_parquet`(path, **kwargs) | Read Graph from a Apache Parquet
`graph.read_gal`(path) | Read Graph from a GAL file
`graph.read_gwt`(path) | Read Graph from a GWT file

### Spatial Weights

Legacy implementation of spatial weights matrices.

`weights.W`(neighbors[, weights, id_order, ...]) | Spatial weights class.

Legacy implementation of spatial weights matrices.

`weights.W`(neighbors[, weights, id_order, ...]) | Spatial weights class.

### Distance Weights

`weights.DistanceBand`(data, threshold[, p, ...]) | Spatial weights based on distance band.
`weights.Kernel`(data[, bandwidth, fixed, k, ...]) | Spatial weights based on kernel functions.
`weights.KNN`(data[, k, p, ids, radius, ...]) | Creates nearest neighbor weights matrix based on k nearest neighbors.
`weights.Gabriel`(coordinates, **kwargs) | Constructs the Gabriel graph of a set of points.
`weights.Delaunay`(coordinates, **kwargs) | Constructor of the Delaunay graph of a set of input points.
`weights.Relative_Neighborhood`(coordinates[, ...]) | Constructs the Relative Neighborhood graph from a set of points.

### Contiguity Weights

`weights.Queen`(polygons, **kw) | Construct a weights object from a collection of pysal polygons that share at least one vertex.
`weights.Rook`(polygons, **kw) | Construct a weights object from a collection of pysal polygons that share at least one edge.
`weights.Voronoi`(points[, criterion, clip]) | Voronoi weights for a 2-d point set
`weights.W`(neighbors[, weights, id_order, ...]) | Spatial weights class.

### spint Weights

`weights.WSP`(sparse[, id_order, index]) | Thin `W` class for `spreg`.
`weights.netW`(link_list[, share, transform]) | Create a network-contiguity based weight object based on different nodal relationships encoded in a network.
`weights.mat2L`(edge_matrix) | Convert a matrix denoting network connectivity (edges or flows) to a list denoting edges
`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.
`weights.vecW`(origin_x, origin_y, dest_x, ...) | 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 tools to interface with rasters

`weights.da2W`(da[, criterion, z_value, ...]) | Create a W object from xarray.DataArray with an additional attribute index containing coordinate values of the raster in the form of Pandas.Index/MultiIndex.
`weights.da2WSP`(da[, criterion, z_value, ...]) | Create a WSP object from xarray.DataArray with an additional attribute index containing coordinate values of the raster in the form of Pandas.Index/MultiIndex.
`weights.w2da`(data, w[, attrs, coords]) | Creates xarray.DataArray object from passed data aligned with W object.
`weights.wsp2da`(data, wsp[, attrs, coords]) | Creates xarray.DataArray object from passed data aligned with WSP object.
`weights.testDataArray`([shape, time, rand, ...]) | Creates 2 or 3 dimensional test xarray.DataArray object

### Weights Util Classes and Functions

`weights.block_weights`(regimes[, ids, sparse]) | Construct spatial weights for regime neighbors.
`weights.lat2W`([nrows, ncols, rook, id_type]) | Create a W object for a regular lattice.
`weights.comb`(items[, n]) | Combinations of size n taken from items
`weights.order`(w[, kmax]) | Determine the non-redundant order of contiguity up to a specific order.
`weights.higher_order`(w[, k]) | Contiguity weights object of order k.
`weights.shimbel`(w) | Find the Shimbel matrix for first order contiguity matrix.
`weights.remap_ids`(w, old2new[, id_order]) | Remaps the IDs in a spatial weights object.
`weights.full2W`(m[, ids]) | Create a PySAL W object from a full array.
`weights.full`(w) | Generate a full numpy array.
`weights.WSP2W`(wsp, **kwargs) | Convert a pysal WSP object (thin weights matrix) to a pysal W object.
`weights.get_ids`(in_shps, idVariable) | Gets the IDs from the DBF file that moves with a given shape file or a geopandas.GeoDataFrame.
`weights.get_points_array_from_shapefile`(...) | Gets a data array of x and y coordinates from a given shapefile.
`weights.fill_diagonal`(w[, val, wsp]) | Returns a new weights object with values inserted along the main diagonal.

### Weights user Classes and Functions

`weights.min_threshold_distance`(data[, p]) | Get the maximum nearest neighbor distance.
`weights.lat2SW`([nrows, ncols, criterion, row_st]) | Create a sparse W matrix for a regular lattice.
`weights.w_local_cluster`(w) | Local clustering coefficients for each unit as a node in a graph.
`weights.higher_order_sp`(w[, k, ...]) | Contiguity weights for either a sparse W or W for order k.
`weights.hexLat2W`([nrows, ncols]) | Create a W object for a hexagonal lattice.
`weights.attach_islands`(w, w_knn1, **kwargs) | Attach nearest neighbor to islands in spatial weight w.
`weights.nonplanar_neighbors`(w, geodataframe) | Detect neighbors for non-planar polygon collections
`weights.fuzzy_contiguity`(gdf[, tolerance, ...]) | Fuzzy contiguity spatial weights
`weights.min_threshold_dist_from_shapefile`(...) | Get the maximum nearest neighbor distance between observations in the shapefile.
`weights.build_lattice_shapefile`(nrows, ...) | Build a lattice shapefile with nrows rows and ncols cols.
`weights.spw_from_gal`(galfile) | Sparse scipy matrix for w from a gal file.
`weights.neighbor_equality`(w1, w2) | Test if the neighbor sets are equal between two weights objects

### Set Theoretic Weights

`weights.w_union`(w1, w2, **kwargs) | Returns a binary weights object, w, that includes all neighbor pairs that exist in either w1 or w2.
`weights.w_intersection`(w1, w2[, w_shape]) | Returns a binary weights object, w, that includes only those neighbor pairs that exist in both w1 and w2.
`weights.w_difference`(w1, w2[, w_shape, ...]) | Returns a binary weights object, w, that includes only neighbor pairs in w1 that are not in w2.
`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.
`weights.w_subset`(w1, ids, **kwargs) | Returns a binary weights object, w, that includes only those observations in ids.
`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

`weights.lag_spatial`(w, y) | Spatial lag operator.
`weights.lag_categorical`(w, y[, ties]) | Spatial lag operator for categorical variables.

## cg: Computational Geometry

### alpha_shapes

`cg.alpha_shape`(xys, alpha) | Alpha-shape delineation (Edelsbrunner, Kirkpatrick & Seidel, 1983) from a collection of points
`cg.alpha_shape_auto`(xys[, step, verbose, ...]) | Computation of alpha-shape delineation with automated selection of alpha.

### voronoi

`cg.voronoi_frames`(geometry[, radius, clip, ...]) | Create Voronoi polygons from a GeoSeries of points, lines, or polygons.

### sphere

`cg.RADIUS_EARTH_KM` | Convert a string or number to a floating-point number, if possible.
`cg.RADIUS_EARTH_MILES` | Convert a string or number to a floating-point number, if possible.
`cg.arcdist`(pt0, pt1[, radius]) | Arc distance between two points on a sphere.
`cg.arcdist2linear`(arc_dist[, radius]) | Convert an arc distance (spherical earth) to a linear distance (R3) in the unit sphere.
`cg.brute_knn`(pts, k[, mode, radius]) | Computes a brute-force \(k\) nearest neighbors.
`cg.fast_knn`(pts, k[, return_dist, radius]) | Computes \(k\) nearest neighbors on a sphere.
`cg.fast_threshold`(pts, dist[, radius]) | Find all neighbors on a sphere within a threshold distance.
`cg.linear2arcdist`(linear_dist[, radius]) | Convert a linear distance in the unit sphere (R3) to an arc distance based on supplied radius.
`cg.toLngLat`(xyz) | Convert a point's x,y,z to latitude and longitude.
`cg.toXYZ`(pt) | Convert a point's latitude and longitude to x,y,z.
`cg.lonlat`(pointslist) | Converts point order from lat-lon tuples to lon-lat (x,y) tuples.
`cg.harcdist`(p0, p1[, lonx, radius]) | Alternative the arc distance function, uses the haversine formula.
`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.
`cg.geogrid`(pup, pdown, k[, lonx]) | Computes a \(k+1\) by \(k+1\) set of grid points for a bounding box in lat-lon.

### shapes

`cg.Point`(loc) | Geometric class for point objects.
`cg.LineSegment`(start_pt, end_pt) | Geometric representation of line segment objects.
`cg.Line`(m, b) | Geometric representation of line objects.
`cg.Ray`(origin, second_p) | Geometric representation of ray objects.
`cg.Chain`(vertices) | Geometric representation of a chain, also known as a polyline.
`cg.Polygon`(vertices[, holes]) | Geometric representation of polygon objects.
`cg.Rectangle`(left, lower, right, upper) | Geometric representation of rectangle objects.
`cg.asShape`(obj) | Returns a PySAL shape object from `obj`, which must support the `__geo_interface__`.

### standalone

`cg.bbcommon`(bb, bbother) | Old Stars method for bounding box overlap testing.
`cg.get_bounding_box`(items) | Find bounding box for a list of geometries.
`cg.get_angle_between`(ray1, ray2) | Returns the angle formed between a pair of rays which share an origin.
`cg.is_collinear`(p1, p2, p3) | Returns whether a triplet of points is collinear.
`cg.get_segments_intersect`(seg1, seg2) | Returns the intersection of two segments if one exists.
`cg.get_segment_point_intersect`(seg, pt) | Returns the intersection of a segment and point.
`cg.get_polygon_point_intersect`(poly, pt) | Returns the intersection of a polygon and point.
`cg.get_rectangle_point_intersect`(rect, pt) | Returns the intersection of a rectangle and point.
`cg.get_ray_segment_intersect`(ray, seg) | Returns the intersection of a ray and line segment.
`cg.get_rectangle_rectangle_intersection`(r0, r1) | Returns the intersection between two rectangles.
`cg.get_polygon_point_dist`(poly, pt) | Returns the distance between a polygon and point.
`cg.get_points_dist`(pt1, pt2) | Returns the distance between a pair of points.
`cg.get_segment_point_dist`(seg, pt) | Returns (1) the distance between a line segment and point and (2) the distance along the segment to the closest location on the segment from the point as a ratio of the length of the segment.
`cg.get_point_at_angle_and_dist`(ray, angle, dist) | Returns the point at a distance and angle relative to the origin of a ray.
`cg.convex_hull`(points) | Returns the convex hull of a set of points.
`cg.is_clockwise`(vertices) | Returns whether a list of points describing a polygon are clockwise or counterclockwise.
`cg.point_touches_rectangle`(point, rect) | Returns `True` (`1`) if the point is in the rectangle or touches it's boundary, otherwise `False` (`0`).
`cg.get_shared_segments`(poly1, poly2[, bool_ret]) | Returns the line segments in common to both polygons.
`cg.distance_matrix`(X[, p, threshold]) | Calculate a distance matrix.

### locators

`cg.Grid`(bounds, resolution) | Representation of a binning data structure.
`cg.PointLocator`(points) | An abstract representation of a point indexing data structure.
`cg.PolygonLocator`(polygons) | An abstract representation of a polygon indexing data structure.

### kdtree

`cg.KDTree`(data[, leafsize, distance_metric, ...]) | kd-tree built on top of kd-tree functionality in scipy.

## io

`io.open` | alias of `FileIO`
`io.fileio.FileIO`([dataPath, mode, dataFormat]) | Metaclass for supporting spatial data file read and write.

## kernels

`kernels.kernel`(distances, bandwidth[, ...]) | Evaluate a kernel function over a distance array.

## examples

`examples.available`() | Return a dataframe with available datasets.
`examples.explain`(name) | Explain a dataset by name.
`examples.get_path`(file_name) | Get the path for a file by searching installed datasets.