Geometry¶
- wrap_to_180(lon)[source]¶
Wrap angle(s) to the range [-180, 180) degrees.
- Parameters:
lon (float or array-like) – Angle(s) in degrees.
- Returns:
Angle(s) wrapped to [-180, 180).
- Return type:
- wrap_to_360(angle)[source]¶
Wrap angle(s) to the range [0, 360) degrees.
- Parameters:
angle (float or array-like) – Angle(s) in degrees.
- Returns:
Angle(s) wrapped to [0, 360).
- Return type:
- calculate_geographic_mean(geometry)[source]¶
Calculate the geographic mean of coordinates from a Shapely geometry or a list of Shapely geometries using pymap3d.lox.meanm.
- Parameters:
geometry (LineString, Polygon, Point, or list) – A single Shapely geometry or a list of Shapely geometries.
- Returns:
Geographic mean as a Shapely Point.
- Return type:
- get_utm_crs(lon, lat)[source]¶
Determine the UTM CRS for a given WGS84 coordinate using the area of interest (AOI).
- get_utm_transforms(geometry)[source]¶
Get the UTM CRS and transformation functions to/from WGS84 for a Shapely geometry or a list of geometries.
- Parameters:
geometry (BaseGeometry or list of BaseGeometry) – A single Shapely geometry object or a list of geometries.
- Returns:
- Transformation functions:
wgs84_to_utm: Function to transform coordinates from WGS84 to UTM.
utm_to_wgs84: Function to transform coordinates from UTM to WGS84.
- Return type:
Tuple[Callable, Callable]
- Raises:
ValueError – If the geometry is invalid, empty, or has no valid centroid.
- haversine(lat1, lon1, lat2, lon2, radius=6371000.0)[source]¶
Calculate the haversine distance between two points on the Earth’s surface.
- Parameters:
lat1 (float) – Latitude of the first point in decimal degrees.
lon1 (float) – Longitude of the first point in decimal degrees.
lat2 (float) – Latitude of the second point in decimal degrees.
lon2 (float) – Longitude of the second point in decimal degrees.
radius (float) – Radius of the Earth in meters (default: 6371e3 for meters).
- Returns:
Distance between the two points in the same unit as the radius.
- Return type:
- random_points_in_polygon(polygon, k)[source]¶
Generate k points chosen uniformly at random inside a polygon.
Uses Delaunay triangulation with area-weighted sampling to ensure uniform distribution across the polygon’s interior.
- minimum_rotated_rectangle(polygon)[source]¶
Calculate the minimum rotated rectangle of a polygon in WGS84 coordinates.
- Parameters:
polygon (Polygon) – Input polygon in WGS84 coordinates. Must be valid.
- Returns:
- A tuple containing:
lat0 (float): Latitude of the rectangle’s centroid.
lon0 (float): Longitude of the rectangle’s centroid.
azimuth (float): Azimuth of the rectangle in degrees, wrapped to [-180, 180].
length (float): Length of the rectangle’s longer side (meters).
width (float): Width of the rectangle’s shorter side (meters).
mrr_wgs84 (Polygon): Minimum rotated rectangle in WGS84 coordinates.
hull_wgs84 (Polygon): Convex hull of the polygon in WGS84 coordinates.
- Return type:
- Raises:
ValueError – If the input polygon is invalid or processing fails.
Notes
The input polygon is transformed to UTM for accurate geometry calculations.
Returns both the rectangle and the convex hull in WGS84 coordinates.
- rotated_rectangle(polygon, azimuth)[source]¶
Compute a rotated bounding rectangle around a Shapely polygon in WGS84 coordinates at a specified azimuth.
- Parameters:
- Returns:
The rotated bounding rectangle in WGS84 coordinates.
- Return type:
- Raises:
ValueError – If the input polygon is invalid or if an error occurs during processing.
Notes
The input polygon is transformed to UTM for accurate geometry calculations.
The bounding rectangle is rotated to align with the specified azimuth.
The result is returned in WGS84 coordinates.
- translate_polygon(polygon, distance, azimuth)[source]¶
Translate a Shapely polygon by a specified distance in a given rotational direction.
- Parameters:
- Returns:
The translated Shapely polygon.
- Return type:
- buffer_polygon_along_azimuth(polygon, along_track_distance, across_track_distance, azimuth)[source]¶
Translate a Shapely polygon in both a specified direction and its opposite, then compute the convex hull of the union of the two translated polygons.
- Parameters:
polygon (Polygon) – The input Shapely polygon to be buffered in WGS84 coordinates. Must be valid.
distance (ureg.Quantity) – Distance to translate the polygon. Must be a positive length Quantity.
azimuth (float) – Angle of translation in degrees, measured clockwise from north.
along_track_distance (float)
across_track_distance (float)
- Returns:
The convex hull of the union of the two translated polygons in WGS84 coordinates.
- Return type:
- Raises:
ValueError – If the input polygon is invalid or if distance is not a valid length.
Notes
The input polygon is transformed to UTM for accurate geometry calculations.
The resulting convex hull is returned in WGS84 coordinates.
- process_linestring(linestring)[source]¶
Process a LineString containing WGS84 coordinates to compute latitudes, longitudes, azimuths, and cumulative along-track distances.
- Parameters:
linestring (LineString) – A shapely LineString containing WGS84 coordinates.
- Returns:
- A tuple containing:
numpy.ndarray: Latitudes of the track points.
numpy.ndarray: Longitudes of the track points.
numpy.ndarray: Azimuths between consecutive points.
numpy.ndarray: Cumulative along-track distances in meters.
- Return type: