Geo Utils¶
geo_from_string
¶
Conversion of WKT strings to shapely geometries.
convert_wkt_series
¶
convert_wkt_series(series: Series) -> Series
Convert a pandas Series of WKT (Well-Known Text) strings to Shapely geometry objects.
Handles None and empty string values gracefully by returning None. If a value cannot be parsed, it is left unchanged and a warning is printed if any parsing fails.
Source code in src/mesqual/utils/geo_utils/geo_from_string.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
largest_polygon
¶
The largest polygon of a multipolygon.
get_largest_sub_polygon
¶
get_largest_sub_polygon(multi_polygon: MultiPolygon) -> Polygon
Return the polygon with the largest area of a multipolygon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
multi_polygon
|
MultiPolygon
|
A |
required |
Source code in src/mesqual/utils/geo_utils/largest_polygon.py
6 7 8 9 10 11 12 13 14 15 16 17 18 | |
point_to_lat_lon
¶
Latitude and longitude of a shapely point.
get_lat_lon_from_point
¶
get_lat_lon_from_point(point: Point) -> tuple[float, float]
Return latitude and longitude of a point with x as longitude and y as latitude.
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
|
Source code in src/mesqual/utils/geo_utils/point_to_lat_lon.py
6 7 8 9 10 11 12 13 14 | |
graph_node_coordinate_interpolator
¶
Positions of graph nodes estimated from the positions of their neighbours.
InterpolationConfig
dataclass
¶
Settings of GraphNodeCoordinateInterpolator.
Attributes:
| Name | Type | Description |
|---|---|---|
move_percentage |
float
|
After the iterations, each node that shares its position with another node moves by this share of the vector to the mean of its neighbours at other positions. |
max_iterations |
int
|
Maximum number of iterations. Each iteration moves each node without known position to the mean position of its neighbours. |
tolerance |
float
|
The iterations stop when each node moves less than this distance. |
Source code in src/mesqual/utils/geo_utils/graph_node_coordinate_interpolator.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
GraphNodeCoordinateInterpolator
¶
Estimates the positions of graph nodes without known position from the positions of their neighbours.
compute places each node without known position at the center of the
bounding box of the known positions, then moves it in iterations to the
mean position of its neighbours (see InterpolationConfig). After the
iterations, each node that shares its position with another node, known
nodes included, moves by move_percentage toward the mean of its
neighbours at other positions. Nodes with the same neighbours stay
together. A component without a known node stays at the center of the
bounding box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edges
|
list[tuple[Hashable, Hashable]]
|
Node pairs of the graph. |
required |
known_node_positions
|
dict[Hashable, Point]
|
Known position per node. The iterations do not change them. The dict itself is not changed. |
required |
config
|
InterpolationConfig
|
Settings of the iterations. |
InterpolationConfig()
|
Examples:
>>> from shapely.geometry import Point
>>> interpolator = GraphNodeCoordinateInterpolator(
... [('A', 'B'), ('B', 'C')], {'A': Point(0, 0), 'C': Point(2, 0)}
... )
>>> interpolator.compute()
>>> interpolator.get_position_for_node('B')
<POINT (1 0)>
Source code in src/mesqual/utils/geo_utils/graph_node_coordinate_interpolator.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
compute
¶
compute()
Compute the positions of all nodes. Before this call, only the known positions are available.
Source code in src/mesqual/utils/geo_utils/graph_node_coordinate_interpolator.py
68 69 70 71 72 73 | |
get_position_for_node
¶
get_position_for_node(node: Hashable) -> Point
Return the position of a node.
Raises:
| Type | Description |
|---|---|
KeyError
|
The node has no position, for example a node without
known position before |
Source code in src/mesqual/utils/geo_utils/graph_node_coordinate_interpolator.py
140 141 142 143 144 145 146 147 | |
get_all_node_positions
¶
get_all_node_positions() -> dict[Hashable, Point]
Return the position per node. The dict is the internal one until the next compute, which replaces it.
Source code in src/mesqual/utils/geo_utils/graph_node_coordinate_interpolator.py
149 150 151 | |