Distance calculations#
- point_distance(points, other, metrics='euclidean')[source]
Calculates the euclidean distance from one group of points to another group of points.
- Parameters:
- pointsarray
Spatial coordinates.
- otherarray
Other array with spatial coordinates.
- metricsstr, default = ‘euclidean’
Metrics used to calculate distance. See
scipy.spatial.distance.cdist
for more details.
- Returns:
- distancesarray
Distances matrix. Row index =
points
point index, and column index =other
point index.
Notes
The function creates array of size MxN, where M = number of
points
and N = number ofother
. Very big array with coordinates may cause a memory error.Examples
>>> points = [(0, 0), (0, 1), (0, 2)] >>> other = [(2, 2), (3, 3)] >>> distances = point_distance(points=points, other=other) >>> print(distances) [[2.82842712 4.24264069] [2.23606798 3.60555128] [2. 3.16227766]]
- calc_block_to_block_distance(blocks)[source]
Function calculates distances between blocks.
- Parameters:
- blocksUnion[Dict, np.ndarray, gpd.GeoDataFrame, pd.DataFrame, PointSupport]
- The point support of polygons.
Dict
:{block id: [[point x, point y, value]]}
,numpy array
:[[block id, x, y, value]]
,DataFrame
andGeoDataFrame
:columns={x, y, ds, index}
,PointSupport
.
- Returns:
- block_distancesDict
Ordered block ids (the order from the list of distances): {block id : [distances to other]}.
- Raises:
- TypeError
Wrong input’s data type.
deprecated#
- calc_point_to_point_distance(points_a, points_b=None)[source]
Function calculates distances between two group of points of a single group to itself.
- Parameters:
- points_anumpy array
The point coordinates.
- points_bnumpy array, default=None
Other point coordinates. If provided then algorithm calculates distances between
points_a
againstpoints_b
.
- Returns:
- distancesnumpy array
The distances from each point from the
points_a
to other point (from the samepoints_a
or from the other set of pointspoints_b
).
Deprecated since version 0.5.1: This will be removed in 1.0. Use point_distance() instead
Gridding#
- create_grid(ds, min_number_of_cells, grid_type='box')[source]
Function creates grid based on a set of points.
- Parameters:
- dsUnion[np.ndarray, List, gpd.GeoSeries]
Data to be transformed, point coordinates [x, y] <-> [lon, lat] or GeoSeries with Point geometry.
- min_number_of_cellsint
Expected number of cells in the smaller dimension.
- grid_typestr, default = “square”
Available types:
box
,hex
.
- Returns:
- gridgpd.GeoSeries
Empty grid that can be used to aggregate points. It is GeoSeries of Polygons (squares or hexes).
- points_to_grid(points, grid, fillna=None)[source]
Function aggregates points over a specified grid.
- Parameters:
- pointsgeopandas GeoDataFrame
- gridgeopandas GeoSeries
- fillnaAny, optional
The value to fill NaN’s, if None given then this step is skipped.
- Returns:
- aggregatedgeopandas GeoDataFrame