get_midpoint
- pyhelpers.geom.get_midpoint(x1, y1, x2, y2, as_geom=False)
Get the midpoint between two points (applicable for vectorized computation).
- Parameters
x1 (float or int or Iterable or numpy.ndarray) – longitude(s) or easting(s) of a point (an array of points)
y1 (float or int or Iterable or numpy.ndarray) – latitude(s) or northing(s) of a point (an array of points)
x2 (float or int or Iterable or numpy.ndarray) – longitude(s) or easting(s) of another point (another array of points)
y2 (float or int or Iterable or 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 or shapely.geometry.Point or 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)'