local_coords

Local coordinate systems (for geographic data)

class LocalCoordinateSystem(lat, lon)[source]

Bases: object

Represents a local coordinate system for the conversion of geo-coordinates (latitude, longitude) to a local Cartesian coordinate system (unit=metre) and vice versa using the UTM transform

__init__(lat, lon)
Parameters
  • lat – the latitude of the origin of the coordinate system

  • lon – the longitude of the origin of the coordinate system

get_local_coords(lat, lon) Tuple[float, float]
get_lat_lon(local_x, local_y) Tuple[float, float]
class LocalHexagonalGrid(radius_m)[source]

Bases: object

A local hexagonal grid, where hex cells can be referenced by two integer coordinates relative to the central grid cell, whose centre is at local coordinate (0, 0) and where positive x-coordinates/columns are towards the east and positive y-coordinates/rows are towards the north. Every odd row of cells is shifted half a hexagon to the right, i.e. column x for row 1 is half a grid cell further to the right than column x for row 0.

For visualisation purposes, see https://www.redblobgames.com/grids/hexagons/

__init__(radius_m)
Parameters

radius_m – the radius, in metres, of each hex cell

get_hexagon(x_column: int, y_row: int) shapely.geometry.polygon.Polygon

Gets the hexagon (polygon) for the given integer hex cell coordinates :param x_column: the column coordinate :param y_row: the row coordinate :return: the hexagon

get_min_hexagon_column(x)
get_max_hexagon_column(x)
get_min_hexagon_row(y)
get_max_hexagon_row(y)
get_hexagon_coord_span_for_bounding_box(min_x, min_y, max_x, max_y) Tuple[Tuple[int, int], Tuple[int, int]]

Gets the range of hex-cell coordinates that cover the given bounding box

Parameters
  • min_x – minimum x-coordinate of bounding box

  • min_y – minimum y-coordinate of bounding box

  • max_x – maximum x-coordinate of bounding box

  • max_y – maximum y-coordinate of bounding box

Returns

a pair of pairs ((minCol, min_row), (maxCol, max_row)) indicating the span of cell coordinates

get_hexagon_coords_for_point(x, y)
fix_polygon(poly: Union[shapely.geometry.polygon.Polygon, shapely.geometry.multipolygon.MultiPolygon], maxAreaDiff=0.01) Union[shapely.geometry.polygon.Polygon, shapely.geometry.multipolygon.MultiPolygon][source]

Fix invalid shapely polygons or multipolygons.

Reference: https://stackoverflow.com/questions/35110632/splitting-self-intersecting-polygon-only-returned-one-polygon-in-shapely

Parameters
  • poly – the polygon to fix

  • maxAreaDiff – the maximum change in area

Returns

the fixed polygon or None if it cannot be fixed given the area change constraint