utils.geometry.shapes

Provides functions for measuring and transforming geometries.

utils.geometry.shapes.calculate_circle_spacing(radius_m, overlap_m=0)[source]

Takes a radius in meters and an overlap in meters. Calculates the minimum spacing of circles of the given radius that will ensure no gaps between them. This is equal to the width of a square that fits inside the circle. The overlap insures against gaps between circles when used to calculate geographic coordinates.

utils.geometry.shapes.calculate_farthest_dist_km(points, target)[source]

(tuple(tuple(lng, lat)), tuple(lng, lat)) -> float

Takes a tuple of (lng, lat) points and a (lng, lat) target. Returns the distance in kilometers between the target and the point farthest from the target.

utils.geometry.shapes.calculate_multipoly_radius_km(multipolygon)[source]

Takes a GEOSGeometry MultiPolygon and returns the distance in kilometers between the MultiPolygon’s centroid and the point on the MultiPolygon farthest from the centroid.

utils.geometry.shapes.calculate_polygon_radius_km(polygon)[source]

Takes a GEOSGeometry Polygon and returns the distance in kilometers between the Polygon’s centroid and the point on the polygon farthest from the centroid.

utils.geometry.shapes.convert_circle_to_rectangle(point, radius_m)[source]

(tuple(int or float, int or float), int or float) -> GEOSGeometry Polygon

Takes a circle as a (lng, lat) tuple and a radius in meters. Returns the smallest rectangular Polygon that encompasses the circle.

utils.geometry.shapes.convert_to_point(location, location_format)[source]

Takes a dict, tuple, or list of coordinates and converts them to a Point.

utils.geometry.shapes.create_buffered_bounds(polygon, buffer_m)[source]

Takes a GEOSGeometry Polygon and a buffer distance in meters. Returns a Bounds object representing the polygon bounds buffered by the specified distance.

utils.geometry.shapes.factor_polygon_into_circles(polygon, radius_km)[source]

Takes a GEOSGeomtery Polygon and a radius in kilometers. Returns a list of (lng, lat) tuples representing the centers of circles of the specified radius that together cover the area of the Polygon.

utils.geometry.shapes.is_rectangle(coords)[source]

(tuple(tuple(float or int, float or int))) -> Boolean

Takes a tuple of (x, y) coordinate tuples. Returns True if the coordinates represent a rectangle. Otherwise returns False.

utils.geometry.shapes.reverse_coordinate_order(coords)[source]

Takes a tuple of (lat, lng) or (lng, lat) coordinates and reverses their order.

utils.geometry.shapes.sides_parallel(coords, clockwise=True)[source]

Takes a 5-tuple of (x, y) coordinate tuples for a clockwise or counterclockwise quadrilateral. Assumes coordinates start at (min_x, min_y) and end at (min_x, min_y). Returns True if the coordinates define a rectangle. Otherwise returns False.