matching
facilities_to_gdf(facilities)
Converts a Polars DataFrame of facilities to a GeoPandas GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
facilities
|
DataFrame
|
Polars DataFrame with 'latitude' and 'longitude' columns. |
required |
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
GeoDataFrame with Point geometry. |
Source code in src/nemdb/geodata/matching.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
find_nearest_gis_feature(facilities_gdf, targets, distance_col='distance_m')
For each facility, finds the nearest target GIS feature using sjoin_nearest.
Both inputs are reprojected to a metric CRS for accurate distance calculation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
facilities_gdf
|
GeoDataFrame
|
GeoDataFrame of facilities (in any CRS). |
required |
targets
|
GeoDataFrame
|
GeoDataFrame of target features (in any CRS). |
required |
distance_col
|
str
|
Name of the output distance column. |
'distance_m'
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
GeoDataFrame with facility rows joined to their nearest target and a |
GeoDataFrame
|
distance column in meters. Preserves the original facility index order. |
Source code in src/nemdb/geodata/matching.py
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 | |
find_nearest_powerstation(facilities, powerstations)
For each facility, finds the nearest powerstation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
facilities
|
DataFrame
|
Polars DataFrame of facilities. |
required |
powerstations
|
GeoDataFrame
|
GeoPandas GeoDataFrame of powerstations. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Polars DataFrame containing facilities joined with their nearest powerstation |
DataFrame
|
and the distance in meters. |
Source code in src/nemdb/geodata/matching.py
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 | |
match_facilities_to_gis(facilities=None, powerstations=None, substations=None, source='pooch')
Match OpenNEM facilities to the nearest GIS power station or substation.
Uses a two-pass approach: first matches against powerstations, then against substations, and keeps whichever match is closer for each facility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
facilities
|
DataFrame | None
|
OpenNEM facilities DataFrame. When None the data is
fetched automatically according to |
None
|
powerstations
|
GeoDataFrame | None
|
GA powerstations GeoDataFrame (fetched if None). |
None
|
substations
|
GeoDataFrame | None
|
GA substations GeoDataFrame (fetched if None). |
None
|
source
|
Literal['pooch', 'api']
|
How to obtain facilities when |
'pooch'
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
GeoDataFrame with facility info plus |
GeoDataFrame
|
("powerstation" or "substation"), and |
Source code in src/nemdb/geodata/matching.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |