get_midpoint¶
- pyhelpers.geom.get_midpoint(x1, y1, x2, y2, as_geom=False)[source]¶
Get the midpoint between two points (applicable for vectorised computation).
- Parameters:
x1 (float | int | Iterable | numpy.ndarray) – Longitude(s) or easting(s) of a point (an array of points).
y1 (float | int | Iterable | numpy.ndarray) – Latitude(s) or northing(s) of a point (an array of points).
x2 (float | int | Iterable | numpy.ndarray) – Longitude(s) or easting(s) of another point (another array of points).
y2 (float | int | Iterable | numpy.ndarray) – Latitude(s) or northing(s) of another point (another array of points).
as_geom (bool) – Whether to return shapely.geometry.Point; defaults to
False
.
- Returns:
The midpoint between
(x1, y1)
and(x2, y2)
(or midpoints between two sequences of points).- Return type:
numpy.ndarray | shapely.geometry.Point | shapely.geometry.MultiPoint
Examples:
>>> from pyhelpers.geom import get_midpoint >>> x_1, y_1 = 1.5429, 52.6347 >>> x_2, y_2 = 1.4909, 52.6271 >>> midpt = get_midpoint(x_1, y_1, x_2, y_2) >>> midpt array([ 1.5169, 52.6309]) >>> midpt = get_midpoint(x_1, y_1, x_2, y_2, as_geom=True) >>> midpt.wkt 'POINT (1.5169 52.6309)' >>> x_1, y_1 = (1.5429, 1.4909), (52.6347, 52.6271) >>> x_2, y_2 = [2.5429, 2.4909], [53.6347, 53.6271] >>> midpt = get_midpoint(x_1, y_1, x_2, y_2) >>> midpt array([[ 2.0429, 53.1347], [ 1.9909, 53.1271]]) >>> midpt = get_midpoint(x_1, y_1, x_2, y_2, as_geom=True) >>> midpt.wkt 'MULTIPOINT (2.0429 53.1347, 1.9909 53.1271)'