leaf_engine.utils.shapely
This module contains various pure functions for manipulating shapely geometries.
Attributes
Functions
|
Converts a geojson object to a shapely Polygon wkt. |
|
Returns a lat-lon tuple from a geometry string. |
|
Computes the maximum distance between any two points in a geometry string. |
|
Computes the maximum distance between any two points in a Polygon. |
|
Computes the great circle distance between two points. |
|
Converts lat-lon tuples to (x, y) euclidean coordinate pairs. |
|
Rounds geometry coordinates to 5 decimal places. This reduces the size of |
|
Module Contents
- leaf_engine.utils.shapely.geojson_to_wkt(geojson: dict) str
Converts a geojson object to a shapely Polygon wkt.
- leaf_engine.utils.shapely.geometry_to_lat_lon(geometry_string: str) tuple
Returns a lat-lon tuple from a geometry string.
- leaf_engine.utils.shapely.get_geometry_diameter(geometry: str) float
Computes the maximum distance between any two points in a geometry string.
- leaf_engine.utils.shapely.get_polygon_diameter(polygon: shapely.geometry.Polygon) float
Computes the maximum distance between any two points in a Polygon.
- Parameters:
polygon (Polygon) – Shapely polygon.
- Returns:
Maximum distance between polygon points.
- Return type:
- leaf_engine.utils.shapely.haversine(a, b)
Computes the great circle distance between two points.
- Parameters:
a – [lon,lat]
b – [lon,lat]
- Returns:
Distance in miles between a,b
- leaf_engine.utils.shapely.points_to_geometry(lat_lon_records: Iterable) shapely.geometry.Polygon
Converts lat-lon tuples to (x, y) euclidean coordinate pairs.
- Parameters:
lat_lon_records (Iterable) – Iterable of lat-lon tuples.
- Returns:
Convex hull of polygon described by points.
- Return type:
Polygon
- leaf_engine.utils.shapely.round_geometry(geometry_string: str, rounding_precision: int = GEOMETRY_ROUNDING_PRECISION) str
Rounds geometry coordinates to 5 decimal places. This reduces the size of geometry strings and makes them usable as spatial indices when comparing them to geometries returned by the analytics API. This is necessary because geometries returned by the API have lower precision than the geometries we work with here.
Note that this does NOT simplify the geometries (i.e., it does not reduce the number of points in the geometry), just reduces unnecessary precision in point coordinates.
The @lru_cache decorator is used to cache calls to this functions in-memory.
- leaf_engine.utils.shapely.union_geometries(geometries: List[str], rounding_precision: int = GEOMETRY_ROUNDING_PRECISION) str
- leaf_engine.utils.shapely.DISTANCE_UNITS = 'miles'
- leaf_engine.utils.shapely.EARTH_RADIUS_IN_MILES = 3961.0
- leaf_engine.utils.shapely.GEOMETRY_ROUNDING_PRECISION = 5