leaf_engine.utils.shapely ========================= .. py:module:: leaf_engine.utils.shapely .. autoapi-nested-parse:: This module contains various pure functions for manipulating shapely geometries. Attributes ---------- .. autoapisummary:: leaf_engine.utils.shapely.DISTANCE_UNITS leaf_engine.utils.shapely.EARTH_RADIUS_IN_MILES leaf_engine.utils.shapely.GEOMETRY_ROUNDING_PRECISION Functions --------- .. autoapisummary:: leaf_engine.utils.shapely.geojson_to_wkt leaf_engine.utils.shapely.geometry_to_lat_lon leaf_engine.utils.shapely.get_geometry_diameter leaf_engine.utils.shapely.get_polygon_diameter leaf_engine.utils.shapely.haversine leaf_engine.utils.shapely.points_to_geometry leaf_engine.utils.shapely.round_geometry leaf_engine.utils.shapely.union_geometries Module Contents --------------- .. py:function:: geojson_to_wkt(geojson: dict) -> str Converts a geojson object to a shapely Polygon wkt. :param geojson: Geojson object. :type geojson: dict :returns: Shapely Polygon wkt. :rtype: str .. py:function:: geometry_to_lat_lon(geometry_string: str) -> tuple Returns a lat-lon tuple from a geometry string. :param geometry_string: Geometry string. :type geometry_string: str :returns: Lat-lon tuple. :rtype: tuple .. py:function:: get_geometry_diameter(geometry: str) -> float Computes the maximum distance between any two points in a geometry string. :param geometry: Shapely Polygon string. :type geometry: str :returns: Maximum distance between geometry points. :rtype: float .. py:function:: get_polygon_diameter(polygon: shapely.geometry.Polygon) -> float Computes the maximum distance between any two points in a Polygon. :param polygon: Shapely polygon. :type polygon: Polygon :returns: Maximum distance between polygon points. :rtype: float .. py:function:: haversine(a, b) Computes the great circle distance between two points. :param a: [lon,lat] :param b: [lon,lat] :returns: Distance in miles between a,b .. py:function:: points_to_geometry(lat_lon_records: Iterable) -> shapely.geometry.Polygon Converts lat-lon tuples to (x, y) euclidean coordinate pairs. :param lat_lon_records: Iterable of lat-lon tuples. :type lat_lon_records: Iterable :returns: Convex hull of polygon described by points. :rtype: Polygon .. py:function:: 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. .. py:function:: union_geometries(geometries: List[str], rounding_precision: int = GEOMETRY_ROUNDING_PRECISION) -> str .. py:data:: DISTANCE_UNITS :value: 'miles' .. py:data:: EARTH_RADIUS_IN_MILES :value: 3961.0 .. py:data:: GEOMETRY_ROUNDING_PRECISION :value: 5