geo_coords#
Source code: sensai/geoanalytics/geo_coords.py
Utility functions and classes for geographic coordinates
- approximate_squared_distance(p1: Tuple[float, float], p2: Tuple[float, float])[source]#
- Parameters:
p1 – a tuple (latitude, longitude)
p2 – a tuple (latitude, longitude)
- Returns:
the approximate squared distance (in m²) between p1 and p2
- closest_point_on_segment(search_pos: Tuple[float, float], segPoint1: Tuple[float, float], segPoint2: Tuple[float, float])[source]#
Gets the point on the line segment connecting segPoint1 and segPoint2 that is closest to searchPos
- Parameters:
search_pos – the position for which to search for the closest point on the line segment
segPoint1 – the first point defining the line segment on which to search
segPoint2 – the second point defining the line segment on which to search
- Returns:
the closest point, which is on the line connecting segPoint1 and segPoint2 (and may be one of the two points)
- orientation(p1: Tuple[float, float], p2: Tuple[float, float]) float [source]#
Gets the orientation angle for the vector from p1 to p2
- Parameters:
p1 – a (lat, lon) pair
p2 – a (lat, lon) pair
- Returns:
the orientation angle in rad
- abs_angle_difference(a1: float, a2: float) float [source]#
Computes the absolute angle difference in ]-pi, pi] between two angles
- Parameters:
a1 – an angle in rad
a2 – an angle in rad
- Returns:
the difference in rad
- closest_point_on_polyline(search_pos, polyline, search_orientation_angle=None, max_angle_difference=0) Tuple[Tuple[float, float], float, int] [source]#
Gets the point on the given polyline that is closest to the given search position along with the distance (in metres) to the polyline
- Parameters:
search_pos – a (lat, lon) pair indicating the position for which to find the closest math on the polyline
polyline – list of (lat, lon) pairs that make up the polyline on which to search
search_orientation_angle – if not None, defines the orientation with which to compute angle differences (if maxAngleDifference > 0)
max_angle_difference – the maximum absolute angle difference (in rad) that is admissible (between the orientation of the respective line segment and the orientation given in searchOrientationAngle)
- Returns:
a tuple (opt_point, opt_dist, opt_segment_start_idx) where opt_point is the closest point (with admissible orientation - or None if there is none), opt_dist is the distance from the polyline to the closest point, opt_segment_start_idx is the index of the first point of the segment on the polyline for which the closest point was found
- class GeoCoord(lat: float, lon: float)[source]#
Bases:
ToStringMixin
Represents geographic coordinates (WGS84)