Fetch shapes
Data fetch operation for region/province/country shapes
build_nodes(prefectures, nodes_cfg)
Build the nodes, either directly at provincial (admin1) level or from adminlvk2 subregions
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefectures
|
GeoDataFrame
|
|
required |
Source code in workflow/scripts/fetch_shapes.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
cut_smaller_from_larger(row, gdf, overlaps)
automatically assign overlapping area to the smaller region
Example
areas_gdf.apply(cut_smaller_from_larger, args=(areas_gdf, overlaps), axis=1)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row
|
GeoSeries
|
the row from pandas apply |
required |
gdf
|
GeoDataFrame
|
the geodataframe on which the operation is performed |
required |
overlaps
|
DataFrame
|
the boolean overlap table |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
in case areas are exactly equal |
Returns:
| Type | Description |
|---|---|
GeoSeries
|
gpd.GeoSeries: the row with overlaps removed or not |
Source code in workflow/scripts/fetch_shapes.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
eez_by_region(eez, province_shapes, prov_key='region', simplify_tol=0.5)
break up the eez by admin1 regions based on voronoi polygons of the centroids
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eez
|
GeoDataFrame
|
description |
required |
province_shapes
|
GeoDataFrame
|
description |
required |
prov_key
|
str
|
name of the provinces col in province_shapes. Defaults to "region". |
'region'
|
simplify_tol
|
float
|
tolerance for simplifying the voronoi polygons. Defaults to 0.5. |
0.5
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
gpd.GeoDataFrame: description |
Source code in workflow/scripts/fetch_shapes.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
fetch_country_shape(outp_path)
fetch the country shape from natural earth and save it to the outpath
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outp_path
|
PathLike
|
the path to save the country shape (geojson) |
required |
Source code in workflow/scripts/fetch_shapes.py
77 78 79 80 81 82 83 84 85 86 | |
fetch_gadm(country_code='CHN', level=2)
fetch GADM shapefile for a given country and administrative level. https://gadm.org/download_country.html
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
country_code
|
str
|
ISO3 country code (e.g., 'CHN', 'USA'). |
'CHN'
|
level
|
int
|
Administrative level (0=country, 1=region, etc.). |
2
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame: Loaded shapefile as GeoDataFrame. |
Source code in workflow/scripts/fetch_shapes.py
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 | |
fetch_maritime_eez(zone_name)
fetch maritime data for a country from Maritime Gazette API# (Royal marine institute of Flanders data base)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zone_name
|
str
|
the country's zone name, e.g "Chinese" for china |
required |
Raises:
| Type | Description |
|---|---|
HTTPError
|
if the request fails |
Returns: dict: the maritime data
Source code in workflow/scripts/fetch_shapes.py
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 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 | |
fetch_natural_earth_shape(dataset_name, filter_key, filter_value='China', region_key=None)
fetch region or country shape from natural earth dataset and filter
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
str
|
the name of the natural earth dataset to fetch |
required |
filter_key
|
str
|
key to filter the records by |
required |
filter_value
|
str | list
|
filter pass value. Defaults to "China". |
'China'
|
Example
china country: build_natural_earth_shape("admin_0_countries", "ADMIN", "China") china provinces: build_natural_earth_shape("admin_1_states_provinces", "iso_a2", "CN", region_key="name_en")
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
gpd.GeoDataFrame: the filtered records |
Source code in workflow/scripts/fetch_shapes.py
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 | |
fetch_prefecture_shapes(fixes={GDAM_LV1: {'Nei Mongol': 'InnerMongolia', 'Xinjiang Uygur': 'Xinjiang', 'Hong Kong': 'HongKong', 'Ningxia Hui': 'Ningxia'}})
Fetch county-level shapefiles for China.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fixes
|
(dict, Optional)
|
Dictionary mapping old names to new names for specific columns. |
{GDAM_LV1: {'Nei Mongol': 'InnerMongolia', 'Xinjiang Uygur': 'Xinjiang', 'Hong Kong': 'HongKong', 'Ningxia Hui': 'Ningxia'}}
|
Source code in workflow/scripts/fetch_shapes.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
fetch_province_shapes()
fetch the province shapes from natural earth and save it to the outpath
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
gpd.GeoDataFrame: the province shapes |
Source code in workflow/scripts/fetch_shapes.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
has_overlap(gdf)
Check for spatial overlaps across rows
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
the geodataframe to check |
required |
Returns:
| Name | Type | Description |
|---|---|---|
DataFrame |
DataFrame
|
Index x Index boolean dataframe |
Source code in workflow/scripts/fetch_shapes.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
remove_overlaps(gdf)
remove inter row overlaps from a GeoDataFrame, cutting out the smaller region from the larger one
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
the geodataframe to be treated |
required |
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
gpd.GeoDataFrame: the treated geodataframe |
Source code in workflow/scripts/fetch_shapes.py
362 363 364 365 366 367 368 369 370 371 372 | |
split_provinces(prefectures, node_config)
Split Inner Mongolia into East and West regions based on prefectures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefectures
|
GeoDataFrame
|
Gall chinese prefectures. |
required |
node_config
|
dict
|
the configuration for node build |
required |
Returns: gpd.GeoDataFrame: Updated GeoDataFrame with Inner Mongolia split EAST/WEST.
Source code in workflow/scripts/fetch_shapes.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
validate_split_cfg(split_cfg, gdf)
validate the province split configuration. The province (admin level 1) is split by admin level 2 {subregion: [prefecture names],..}. The prefecture names must be unique and cover all admin2 in the admin1 level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
split_cfg
|
dict
|
the configuration for the prefecture split |
required |
gdf
|
GeoDataFrame
|
the geodataframe with prefecture shapes |
required |
Raises: ValueError: if the prefectures are not unique or do not cover all admin2 in the admin1 level
Source code in workflow/scripts/fetch_shapes.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |