shapely_function#

explode_multipolygon(geometry_str: str) list[Polygon][source]#

Explode a MultiPolygon WKT string into a list of Polygon objects.

Parameters:

geometry_str (str) – The WKT string of the MultiPolygon.

Returns:

The list of Polygon objects.

Return type:

list[Polygon]

find_closest_node_from_list(data: dict, node_name: str, node_list_name: str) str | None[source]#

Find the closest node ID from a given node ID geometry mapping.

Parameters:
  • data (dict) – The data dictionary containing node information.

  • node_name (str) – The key for the node ID.

  • node_list_name (str) – The key for the list of node IDs.

Returns:

The closest node ID.

Return type:

Optional[str]

generate_valid_polygon(multipolygon_str: str) Polygon | MultiPolygon | None[source]#

Generate a valid polygon from a MultiPolygon WKT string.

Parameters:

multipolygon_str (str) – The WKT string of the MultiPolygon.

Returns:

The valid polygon.

Return type:

Optional[Polygon]

geoalchemy2_to_shape(geo_str: str) Geometry[source]#

Convert a GeoAlchemy2 WKBElement string to a Shapely Geometry object.

Parameters:

geo_str (str) – The GeoAlchemy2 WKBElement string.

Returns:

The Shapely Geometry object.

Return type:

Geometry

get_closest_point_from_multi_point(geo_str: str, multi_point: MultiPoint, max_distance: float = 100) str | None[source]#

Find the closest point within a maximum distance from a given geometry WKT string.

Parameters:
  • geo_str (str) – The WKT string of the geometry.

  • multi_point (MultiPoint) – The MultiPoint object.

  • max_distance (float, optional) – The maximum distance. Defaults to 100.

Returns:

The WKT string of the closest point.

Return type:

Optional[str]

get_multilinestring_from_wkt_list(linestring_list: list[str]) MultiPoint[source]#

Convert a list of WKT representations of linestring into a MultiLineString geometry.

Parameters:

linestring_list (list[str]) – The list of WKT linestring strings.

Returns:

The MultiLineString geometry.

Return type:

MultiLineString

get_multipoint_from_wkt_list(point_list: list[str]) MultiPoint[source]#

Convert a list of WKT representations of points into a MultiPoint geometry.

Parameters:

point_list (list[str])) – The list of WKT points strings.

Returns:

The MultiPoint geometry.

Return type:

MultiPoint

get_multipolygon_from_wkt_list(polygon_list: list[str]) MultiPolygon[source]#

Convert a list of WKT representations of polygons into a MultiPolygon geometry.

Parameters:

polygon_list (list[str])) – The list of WKT polygons strings.

Returns:

The MultiPolygon geometry.

Return type:

MultiPolygon

get_nearest_point_within_distance(point: Point, point_list: MultiPoint, min_distance: float) str | None[source]#

Find the nearest point within a specified distance from a given point.

Parameters:
  • point (Point) – The reference point.

  • point_list (MultiPoint) – The list of points to search.

  • min_distance (float) – The minimum distance to search for the nearest point.

Returns:

The nearest point in wkt format within the specified distance, or None if no point is found.

Return type:

str or None

get_point_list_centroid(point_list: list[Point]) Point[source]#

Calculate the centroid of a list of points.

Parameters:

points (Point) – The list of points.

Returns:

The centroid of the list of points.

Return type:

Point

get_point_side(line: LineString, point: Point) str | None[source]#

Determine which side of a line a point is on.

Parameters:
  • point (Point) – The point to check.

  • line (LineString) – The line to check against.

Returns:

start if the point is to the beginning of the line, 1 if to the right, and end if it is at the end.

Return type:

str

get_polygon_multipoint_intersection(polygon_str: str, multipoint: MultiPoint) list[str] | None[source]#

Get the intersection points between a polygon and a multipoint.

Parameters:
  • polygon_str (str) – The WKT string of the polygon.

  • multipoint (MultiPoint) – The MultiPoint object.

Returns:

The list of WKT strings representing the intersection points.

Return type:

Optional[list[str]]

get_valid_polygon_str(polygon_str: dict) str[source]#

Get a valid polygon WKT string from a dictionary.

Parameters:

polygon_str (dict) – The dictionary containing polygon information.

Returns:

The valid polygon WKT string.

Return type:

str

grid_bounds(geom, delta)[source]#

Generate a grid of polygons within the bounds of a geometry.

Parameters:
  • geom (Geometry) – The Shapely Geometry object.

  • delta (float) – The grid cell size.

Returns:

The list of grid polygons.

Return type:

list[Polygon]

load_shape_from_geo_json(file_name: str, srid_from: str | None = None, srid_to: str | None = None) Geometry[source]#

Load a shape from a GeoJSON file and optionally transform its coordinates.

Parameters:
  • file_name (str) – The path to the GeoJSON file.

  • srid_from (Optional[str], optional) – The source spatial reference system identifier. Defaults to None.

  • srid_to (Optional[str], optional) – The target spatial reference system identifier. Defaults to None.

Returns:

The loaded shape.

Return type:

Geometry

Raises:
  • FileNotFoundError – If the GeoJSON file is not found.

  • ValueError – If only one of srid_from or srid_to is provided.

move_geometry(data: dict) str[source]#
multipoint_from_multilinestring(multilinestring: MultiLineString) MultiPoint[source]#

Generate a MultiPoint from a MultiLineString by extracting unique points.

Parameters:

multilinestring (MultiLineString) – The MultiLineString object.

Returns:

The MultiPoint object containing unique points from the MultiLineString.

Return type:

MultiPoint

partition(geom: Polygon, delta: float) list[source]#

Partition a polygon into smaller polygons based on a grid.

Parameters:
  • geom (Polygon) – The Shapely Polygon object.

  • delta (float) – The grid cell size.

Returns:

The list of partitioned polygons.

Return type:

list[Polygon]

point_list_to_linestring(point_list_str: list[str]) str[source]#

Convert a list of WKT point strings to a WKT LineString.

Parameters:

point_list_str (list[str]) – The list of WKT point strings.

Returns:

The WKT LineString.

Return type:

str

remove_z_coordinates(geom: Geometry) Geometry[source]#

Remove the Z coordinates from a geometry.

Parameters:

geom (Geometry) – The Shapely Geometry object.

Returns:

The Shapely Geometry object without Z coordinates.

Return type:

Geometry

segment_list_from_multilinestring(multi_linestring: MultiLineString) list[LineString][source]#

Generate a list of LineString segments from a MultiLineString.

Parameters:

multi_linestring (MultiLineString) – The MultiLineString object.

Returns:

The list of LineString segments.

Return type:

list[LineString]

shape_coordinate_transformer(shape: Geometry, srid_from: int, srid_to: int) Geometry[source]#

Transform the coordinates of geometries from one CRS to another.

Parameters:
  • shape (Geometry) – The Polars expression containing geometries.

  • srid_from (int) – The source spatial reference system identifier.

  • srid_to (int) – The target spatial reference system identifier.

Returns:

A Polars expression with transformed geometries.

Return type:

pl.Expr

shape_list_to_wkt_list(shape_list: list[Geometry]) list[str][source]#

Convert a list of Shapely Geometry objects to a list of WKT strings.

Parameters:

shape_list (list[Geometry]) – The list of Shapely Geometry objects.

Returns:

The list of WKT strings.

Return type:

list[str]

shape_to_geoalchemy2(geo: Geometry, srid: int = 4326) str[source]#

Convert a Shapely Geometry object to a GeoAlchemy2 WKBElement string.

Parameters:
  • geo (Geometry) – The Shapely Geometry object.

  • srid (int, optional) – The spatial reference system identifier. Defaults to GPS_SRID = 4326.

Returns:

The GeoAlchemy2 WKBElement string.

Return type:

str

wkt_list_to_shape_list(str_list: list[str]) list[Geometry][source]#

Convert a list of Shapely Geometry objects to a list of WKT strings.

Parameters:

shape_list (list[Geometry]) – The list of Shapely Geometry objects.

Returns:

The list of WKT strings.

Return type:

list[str]