geonode.base.bbox_utils

Classes

BBOXHelper

A bounding box representation to avoid use of list indices when dealing with bounding boxes.

Functions

normalize_x_value(value)

Normalise x-axis value/longtitude to fall within [-180, 180]

polygon_from_bbox(bbox[, srid])

Constructs a Polygon object with srid from a provided bbox.

filter_bbox(queryset, bbox)

Filters a queryset by a provided bounding box.

check_crossing(lon1, lon2[, validate, dlon_threshold])

Reference: https://towardsdatascience.com/around-the-world-in-80-lines-crossing-the-antimeridian-with-python-and-shapely-c87c9b6e1513

translate_polygons(→ Generator[Union[List[dict], ...)

Reference: https://towardsdatascience.com/around-the-world-in-80-lines-crossing-the-antimeridian-with-python-and-shapely-c87c9b6e1513

split_polygon(→ Union[List[dict], ...)

Reference: https://towardsdatascience.com/around-the-world-in-80-lines-crossing-the-antimeridian-with-python-and-shapely-c87c9b6e1513

Module Contents

class geonode.base.bbox_utils.BBOXHelper(minmaxform)[source]

A bounding box representation to avoid use of list indices when dealing with bounding boxes.

classmethod from_xy(xy)[source]

Constructs a BBOXHelper instance from coordinates in “xy” format.

Parameters:

xy – collection of coordinates as [xmin, xmax, ymin, ymax]

as_polygon()[source]
geonode.base.bbox_utils.normalize_x_value(value)[source]

Normalise x-axis value/longtitude to fall within [-180, 180]

geonode.base.bbox_utils.polygon_from_bbox(bbox, srid=4326)[source]

Constructs a Polygon object with srid from a provided bbox.

geonode.base.bbox_utils.filter_bbox(queryset, bbox)[source]

Filters a queryset by a provided bounding box.

Parameters:

bbox – Comma-separated coordinates as “xmin,ymin,xmax,ymax”

geonode.base.bbox_utils.check_crossing(lon1: float, lon2: float, validate: bool = False, dlon_threshold: float = 180.0)[source]

Reference: https://towardsdatascience.com/around-the-world-in-80-lines-crossing-the-antimeridian-with-python-and-shapely-c87c9b6e1513

Assuming a minimum travel distance between two provided longitude coordinates, checks if the 180th meridian (antimeridian) is crossed.

geonode.base.bbox_utils.translate_polygons(geometry_collection: shapely.geometry.GeometryCollection, output_format: str = 'geojson') Generator[List[dict] | List[shapely.geometry.Polygon], None, None][source]

Reference: https://towardsdatascience.com/around-the-world-in-80-lines-crossing-the-antimeridian-with-python-and-shapely-c87c9b6e1513

geonode.base.bbox_utils.split_polygon(geojson: dict, output_format: str = 'geojson', validate: bool = False) List[dict] | List[shapely.geometry.Polygon] | shapely.geometry.GeometryCollection[source]

Reference: https://towardsdatascience.com/around-the-world-in-80-lines-crossing-the-antimeridian-with-python-and-shapely-c87c9b6e1513

Given a GeoJSON representation of a Polygon, returns a collection of ‘antimeridian-safe’ constituent polygons split at the 180th meridian, ensuring compliance with GeoJSON standards (https://tools.ietf.org/html/rfc7946#section-3.1.9)

Assumptions:

  • Any two consecutive points with over 180 degrees difference in longitude are assumed to cross the antimeridian

  • The polygon spans less than 360 degrees in longitude (i.e. does not wrap around the globe)

  • However, the polygon may cross the antimeridian on multiple occasions

Parameters:

(dict) (geojson) –

GeoJSON of input polygon to be split. For example:

{
"type": "Polygon",
"coordinates": [
    [
    [179.0, 0.0], [-179.0, 0.0], [-179.0, 1.0],
    [179.0, 1.0], [179.0, 0.0]
    ]
]
}
output_format (str): Available options: "geojson", "polygons", "geometrycollection"

If "geometrycollection" returns a Shapely GeometryCollection.
Otherwise, returns a list of either GeoJSONs or Shapely Polygons
validate (bool): Checks if all longitudes are within [-180.0, 180.0]

Returns:

List[dict]/List[Polygon]/GeometryCollection: antimeridian-safe polygon(s)