local_coords#
Source code: sensai/geoanalytics/local_coords.py
Local coordinate systems (for geographic data)
- class LocalCoordinateSystem(lat, lon)[source]#
Bases:
objectRepresents 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
- Parameters:
lat: the latitude of the origin of the coordinate system lon: the longitude of the origin of the coordinate system
- class LocalHexagonalGrid(radius_m)[source]#
Bases:
objectA 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/
- Parameters:
radius_m – the radius, in metres, of each hex cell
- get_hexagon(x_column: int, y_row: int) shapely.geometry.polygon.Polygon[source]#
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_hexagon_coord_span_for_bounding_box(min_x, min_y, max_x, max_y) Tuple[Tuple[int, int], Tuple[int, int]][source]#
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
- 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.
- 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