DGGS Compact / Expand
DGGS Compact and Expand functions.
This submodule provides functions to compact and expand various discrete global grid systems (DGGS).
a5compact_cli()
¶
Command-line interface for a5compact with flexible input/output.
Source code in vgrid/conversion/dggscompact/a5compact.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 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 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
a5expand(input_data, resolution=None, a5_hex=None, output_format='gpd', options=None, split_antimeridian=False, verbose=True, depth=None)
¶
Expand (uncompact) A5 cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down
(1 = direct children, 2 = grandchildren, and so on).
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing A5 cell IDs. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of A5 cell IDs
resolution : int, optional
Target A5 resolution to expand the cells to. Must be >= maximum input
resolution. When set, depth is ignored.
a5_hex : str, optional
Name of the column containing A5 cell IDs. Defaults to "a5".
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
options : dict, optional
Options for a52geo.
split_antimeridian : bool, optional
When True, apply antimeridian fixing to the resulting polygons.
Defaults to False when None or omitted.
depth : int, optional
Relative expansion depth (1 <= depth <= max_res). Used when
resolution is not set. Each input cell is expanded depth
levels: 1 = direct children, 2 = grandchildren, and so on.
Returns¶
geopandas.GeoDataFrame or str or dict or None The expanded A5 cells in the specified format, or None if expansion fails.
Examples¶
Expand from file¶
result = a5expand("cells.geojson", resolution=5) print(f"Expanded to {len(result)} cells")
Expand from list¶
result = a5expand(["8e65b56628e0d07"], resolution=5)
Expand mixed-resolution cells by relative depth¶
result = a5expand(cells, depth=1) result = a5expand(cells, depth=2)
Expand to GeoJSON file¶
result = a5expand("cells.geojson", resolution=5, output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/dggscompact/a5compact.py
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 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
a5expand_cli()
¶
Command-line interface for a5expand with flexible input/output.
Source code in vgrid/conversion/dggscompact/a5compact.py
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | |
dggalexpand(dggs_type, input_data, resolution=None, zone_id=None, output_format='gpd', split_antimeridian=False, verbose=True, depth=None)
¶
Expand (uncompact) DGGAL cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/dggalcompact.py
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 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
digipincompact_cli()
¶
Command-line interface for DIGIPIN compaction.
Source code in vgrid/conversion/dggscompact/digipincompact.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 | |
digipinexpand(input_data, resolution=None, digipin_id='digipin', output_format='gpd', verbose=True, depth=None)
¶
Expand (uncompact) DIGIPIN cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/digipincompact.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 | |
digipinexpand_cli()
¶
Command-line interface for DIGIPIN expansion.
Source code in vgrid/conversion/dggscompact/digipincompact.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
easecompact_cli()
¶
Command-line interface for EASE compaction.
Source code in vgrid/conversion/dggscompact/easecompact.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 289 290 291 292 293 294 295 296 297 | |
easeexpand(input_data, resolution=None, ease_id=None, output_format='gpd', verbose=True, depth=None)
¶
Expand (uncompact) EASE cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/easecompact.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 | |
easeexpand_cli()
¶
Command-line interface for EASE expansion.
Source code in vgrid/conversion/dggscompact/easecompact.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
geohashcompact_cli()
¶
Command-line interface for Geohash compaction.
Source code in vgrid/conversion/dggscompact/geohashcompact.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 | |
geohashexpand(input_data, resolution=None, geohash_id=None, output_format='gpd', verbose=True, depth=None)
¶
Expand (uncompact) Geohash cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/geohashcompact.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 | |
geohashexpand_cli()
¶
Command-line interface for Geohash expansion.
Source code in vgrid/conversion/dggscompact/geohashcompact.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
h3_compact(h3_ids, depth=-1, bags=None, verbose=True)
¶
Compact a list of H3 cell IDs by replacing complete child sets with parents.
Groups cells by their immediate parent and replaces a parent when every child
is present. Repeats until depth parent levels have been applied, or until
no further compaction is possible.
Parameters¶
h3_ids : list of str
H3 cell IDs to compact. Mixed resolutions are allowed.
depth : int, default -1
How many parent levels to climb:
- 0: do nothing (return the unique input cells)
- -1: compact as far as possible (same result as h3.compact_cells
when all inputs share a resolution)
- 1: replace complete sibling sets with their direct parent
- 2: then compact those parents (grandparents), and so on
bags : dict of list, optional
Per-cell lists of original values. When a complete child set is replaced
by its parent, child lists are concatenated onto the parent. Mutated
in place so remaining keys match the compacted IDs.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
list of str Sorted compacted H3 cell IDs.
Source code in vgrid/conversion/dggscompact/h3compact.py
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 | |
h3compact_cli()
¶
Command-line interface for h3compact with flexible input/output.
Source code in vgrid/conversion/dggscompact/h3compact.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 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 343 344 345 346 347 348 349 350 351 352 353 354 | |
h3expand(input_data, resolution=None, h3_id=None, output_format='gpd', fix_antimeridian=None, verbose=True, depth=None)
¶
Expand (uncompact) H3 cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down
(1 = direct children, 2 = grandchildren, and so on).
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing H3 cell IDs. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of H3 cell IDs
resolution : int, optional
Target H3 resolution to expand the cells to. Must be >= maximum input
resolution. When set, depth is ignored.
h3_id : str, optional
Name of the column containing H3 cell IDs. Defaults to "h3".
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
depth : int, optional
Relative expansion depth (1 <= depth <= max_res). Used when
resolution is not set. Each input cell is expanded depth
levels: 1 = direct children, 2 = grandchildren, and so on.
Returns¶
geopandas.GeoDataFrame or str or dict or None The expanded H3 cells in the specified format, or None if expansion fails.
Examples¶
Expand from file¶
result = h3expand("cells.geojson", resolution=5) print(f"Expanded to {len(result)} cells")
Expand from list¶
result = h3expand(["83754efffffffff"], resolution=5)
Expand mixed-resolution cells by relative depth¶
result = h3expand(cells, depth=1) result = h3expand(cells, depth=2)
Expand to GeoJSON file¶
result = h3expand("cells.geojson", resolution=5, output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/dggscompact/h3compact.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 | |
h3expand_cli()
¶
Command-line interface for h3expand with flexible input/output.
Source code in vgrid/conversion/dggscompact/h3compact.py
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
isea3hcompact_cli()
¶
Command-line interface for ISEA3H compaction.
Source code in vgrid/conversion/dggscompact/isea3hcompact.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 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 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
isea3hexpand(input_data, resolution=None, isea3h_id=None, output_format='gpd', fix_antimeridian=None, verbose=True, depth=None)
¶
Expand (uncompact) ISEA3H cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/isea3hcompact.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | |
isea3hexpand_cli()
¶
Command-line interface for ISEA3H expansion.
Source code in vgrid/conversion/dggscompact/isea3hcompact.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 | |
isea4texpand(input_data, resolution=None, isea4t_id=None, output_format='gpd', fix_antimeridian=None, verbose=True, depth=None)
¶
Expand (uncompact) ISEA4T cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/isea4tcompact.py
367 368 369 370 371 372 373 374 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 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | |
olccompact_cli()
¶
Command-line interface for OLC compaction.
Source code in vgrid/conversion/dggscompact/olccompact.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 289 290 291 292 293 294 295 296 | |
olcexpand(input_data, resolution=None, olc_id=None, output_format='gpd', verbose=True, depth=None)
¶
Expand (uncompact) OLC cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute code length (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded depth OLC steps down.
Source code in vgrid/conversion/dggscompact/olccompact.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 425 426 | |
olcexpand_cli()
¶
Command-line interface for OLC expansion.
Source code in vgrid/conversion/dggscompact/olccompact.py
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 | |
qtmcompact_cli()
¶
Command-line interface for QTM compaction.
Source code in vgrid/conversion/dggscompact/qtmcompact.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 289 290 291 292 293 | |
qtmexpand(input_data, resolution=None, qtm_id='qtm', output_format='gpd', verbose=True, depth=None)
¶
Expand (uncompact) QTM cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/qtmcompact.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 | |
qtmexpand_cli()
¶
Command-line interface for QTM expansion.
Source code in vgrid/conversion/dggscompact/qtmcompact.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
quadkeycompact_cli()
¶
Command-line interface for Quadkey compaction.
Source code in vgrid/conversion/dggscompact/quadkeycompact.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 | |
quadkeyexpand(input_data, resolution=None, quadkey_id='quadkey', output_format='gpd', verbose=True, depth=None)
¶
Expand (uncompact) Quadkey cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/quadkeycompact.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 | |
quadkeyexpand_cli()
¶
Command-line interface for Quadkey expansion.
Source code in vgrid/conversion/dggscompact/quadkeycompact.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
rhealpixexpand(input_data, resolution=None, rhealpix_id='rhealpix', output_format='gpd', fix_antimeridian=None, verbose=True, depth=None)
¶
Expand (uncompact) RHEALPix cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/rhealpixcompact.py
369 370 371 372 373 374 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 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
s2compact_cli()
¶
Command-line interface for s2compact with flexible input/output.
Source code in vgrid/conversion/dggscompact/s2compact.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
s2expand(input_data, resolution=None, s2_token='s2', output_format='gpd', fix_antimeridian=None, verbose=True, depth=None)
¶
Expand (uncompact) S2 cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down
(1 = direct children, 2 = grandchildren, and so on).
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing S2 cell tokens. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of S2 cell tokens
resolution : int, optional
Target S2 resolution to expand the cells to. Must be >= maximum input
resolution. When set, depth is ignored.
s2_token : str, default "s2"
Name of the column containing S2 cell tokens.
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
depth : int, optional
Relative expansion depth (1 <= depth <= max_res). Used when
resolution is not set. Each input cell is expanded depth
levels: 1 = direct children, 2 = grandchildren, and so on.
Returns¶
geopandas.GeoDataFrame or str or dict or None The expanded S2 cells in the specified format, or None if expansion fails.
Examples¶
result = s2expand("cells.geojson", resolution=10) result = s2expand(["31752f45cc94"], resolution=10) result = s2expand(cells, depth=1)
Source code in vgrid/conversion/dggscompact/s2compact.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
s2expand_cli()
¶
Command-line interface for s2expand with flexible input/output.
Source code in vgrid/conversion/dggscompact/s2compact.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 | |
tilecodecompact_cli()
¶
Command-line interface for Tilecode compaction.
Source code in vgrid/conversion/dggscompact/tilecodecompact.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 | |
tilecodeexpand(input_data, resolution=None, tilecode_id='tilecode', output_format='gpd', verbose=True, depth=None)
¶
Expand (uncompact) Tilecode cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/tilecodecompact.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 | |
tilecodeexpand_cli()
¶
Command-line interface for Tilecode expansion.
Source code in vgrid/conversion/dggscompact/tilecodecompact.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
H3 Compact Module
This module provides functionality to compact and expand H3 cells with flexible input and output formats.
Key Functions
h3_compact(h3_ids, depth=-1, bags=None, verbose=True)
¶
Compact a list of H3 cell IDs by replacing complete child sets with parents.
Groups cells by their immediate parent and replaces a parent when every child
is present. Repeats until depth parent levels have been applied, or until
no further compaction is possible.
Parameters¶
h3_ids : list of str
H3 cell IDs to compact. Mixed resolutions are allowed.
depth : int, default -1
How many parent levels to climb:
- 0: do nothing (return the unique input cells)
- -1: compact as far as possible (same result as h3.compact_cells
when all inputs share a resolution)
- 1: replace complete sibling sets with their direct parent
- 2: then compact those parents (grandparents), and so on
bags : dict of list, optional
Per-cell lists of original values. When a complete child set is replaced
by its parent, child lists are concatenated onto the parent. Mutated
in place so remaining keys match the compacted IDs.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
list of str Sorted compacted H3 cell IDs.
Source code in vgrid/conversion/dggscompact/h3compact.py
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 | |
h3_expand(h3_ids, resolution=None, depth=None, verbose=True)
¶
Expand H3 cell IDs to a target resolution, or by a relative child depth.
When resolution is set, depth is ignored and all cells are uncompacted
to that absolute resolution. When only depth is set, resolution is
ignored and each cell (at any resolution) is expanded to its descendants
depth levels down (1 = direct children, 2 = grandchildren, and
so on).
Parameters¶
h3_ids : list of str
H3 cell IDs to expand. Mixed resolutions are allowed when expanding
by depth.
resolution : int, optional
Target H3 resolution to expand all cells to. When set, depth is
ignored.
depth : int, optional
Relative expansion depth (1 <= depth <= max_res). Used when
resolution is not set. 1 expands each cell to its direct
children; 2 to the next level, and so on.
Returns¶
list of str Expanded H3 cell IDs.
Examples¶
h3_ids = ["83754efffffffff"] expanded = h3_expand(h3_ids, resolution=5) children = h3_expand(h3_ids, depth=1) grandchildren = h3_expand(h3_ids, depth=2)
Source code in vgrid/conversion/dggscompact/h3compact.py
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 | |
h3compact(input_data, h3_id=None, depth=-1, agg='count', numeric_col=None, output_format='gpd', fix_antimeridian=None, verbose=True)
¶
Compact H3 cells to their covering set at a given parent depth.
Compacts a set of H3 cells by replacing complete sets of children with their
parent cells. Unlike h3.compact_cells, mixed input resolutions are allowed
and depth limits how far up the hierarchy to merge.
When a complete sibling set is replaced by its parent, original child values
are combined with agg (same options as h3bin). If agg is
"count", numeric_col is ignored and the output count is the
number of original input cells in each compacted cell.
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing H3 cell IDs. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of H3 cell IDs
h3_id : str, optional
Name of the column containing H3 cell IDs. Defaults to "h3".
depth : int, default -1
Compaction depth: 0 leaves cells unchanged, -1 compact as far as
possible, 1 merges to the direct parent, 2 to the grandparent, etc.
agg : str, default "count"
Aggregation applied to original child values when cells compact into a
parent. Same options as h3bin (count, min, max, sum,
mean, median, std, var, range, minority,
majority, variety).
numeric_col : str, optional
Numeric field to aggregate. Required when agg is not "count";
ignored when agg is "count".
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
geopandas.GeoDataFrame or str or dict or None The compacted H3 cells in the specified format, or None if no valid cells found.
Examples¶
Compact from file¶
result = h3compact("cells.geojson") print(f"Compacted to {len(result)} cells")
Compact from list¶
result = h3compact(["8e65b56628e0d07", "8e65b56628e0d08"])
Compact only one parent level¶
result = h3compact(cells, depth=1)
Mean of a numeric field on compacted parents¶
result = h3compact(cells, agg="mean", numeric_col="value")
Compact to GeoJSON file¶
result = h3compact("cells.geojson", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/dggscompact/h3compact.py
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 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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
h3compact_cli()
¶
Command-line interface for h3compact with flexible input/output.
Source code in vgrid/conversion/dggscompact/h3compact.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 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 343 344 345 346 347 348 349 350 351 352 353 354 | |
h3expand(input_data, resolution=None, h3_id=None, output_format='gpd', fix_antimeridian=None, verbose=True, depth=None)
¶
Expand (uncompact) H3 cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down
(1 = direct children, 2 = grandchildren, and so on).
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing H3 cell IDs. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of H3 cell IDs
resolution : int, optional
Target H3 resolution to expand the cells to. Must be >= maximum input
resolution. When set, depth is ignored.
h3_id : str, optional
Name of the column containing H3 cell IDs. Defaults to "h3".
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
depth : int, optional
Relative expansion depth (1 <= depth <= max_res). Used when
resolution is not set. Each input cell is expanded depth
levels: 1 = direct children, 2 = grandchildren, and so on.
Returns¶
geopandas.GeoDataFrame or str or dict or None The expanded H3 cells in the specified format, or None if expansion fails.
Examples¶
Expand from file¶
result = h3expand("cells.geojson", resolution=5) print(f"Expanded to {len(result)} cells")
Expand from list¶
result = h3expand(["83754efffffffff"], resolution=5)
Expand mixed-resolution cells by relative depth¶
result = h3expand(cells, depth=1) result = h3expand(cells, depth=2)
Expand to GeoJSON file¶
result = h3expand("cells.geojson", resolution=5, output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/dggscompact/h3compact.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 | |
h3expand_cli()
¶
Command-line interface for h3expand with flexible input/output.
Source code in vgrid/conversion/dggscompact/h3compact.py
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
S2 Compact Module
This module provides functionality to compact and expand S2 cells with flexible input and output formats.
Key Functions
s2_compact(s2_tokens, depth=-1, bags=None, verbose=True)
¶
Compact a list of S2 cell tokens by replacing complete child sets with parents.
Groups cells by their immediate parent and replaces a parent when every child
is present. Repeats until depth parent levels have been applied, or until
no further compaction is possible.
Parameters¶
s2_tokens : list of str
S2 cell tokens to compact. Mixed resolutions are allowed.
depth : int, default -1
How many parent levels to climb:
- 0: do nothing (return the unique input cells)
- -1: compact as far as possible
- 1: replace complete sibling sets with their direct parent
- 2: then compact those parents (grandparents), and so on
bags : dict of list, optional
Per-cell lists of original values. When a complete child set is replaced
by its parent, child lists are concatenated onto the parent. Mutated
in place so remaining keys match the compacted IDs.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
list of str Sorted compacted S2 cell tokens.
Source code in vgrid/conversion/dggscompact/s2compact.py
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 | |
s2_expand(s2_tokens, resolution=None, depth=None, verbose=True)
¶
Expand S2 cell tokens to a target resolution, or by a relative child depth.
When resolution is set, depth is ignored and all cells are uncompacted
to that absolute resolution. When only depth is set, resolution is
ignored and each cell (at any resolution) is expanded to its descendants
depth levels down (1 = direct children, 2 = grandchildren, and
so on).
Source code in vgrid/conversion/dggscompact/s2compact.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
s2compact(input_data, s2_token='s2', depth=-1, agg='count', numeric_col=None, output_format='gpd', fix_antimeridian=None, verbose=True)
¶
Compact S2 cells to their covering set at a given parent depth.
Compacts a set of S2 cells by replacing complete sets of children with their
parent cells. Mixed input resolutions are allowed and depth limits how
far up the hierarchy to merge.
When a complete sibling set is replaced by its parent, original child values
are combined with agg. If agg is "count", numeric_col is
ignored and the output count is the number of original input cells in
each compacted cell.
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing S2 cell tokens. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of S2 cell tokens
s2_token : str, default "s2"
Name of the column containing S2 cell tokens.
depth : int, default -1
Compaction depth: 0 leaves cells unchanged, -1 compact as far as
possible, 1 merges to the direct parent, 2 to the grandparent, etc.
agg : str, default "count"
Aggregation applied to original child values when cells compact into a
parent. Same options as DGGS binning (count, min, max,
sum, mean, median, std, var, range,
minority, majority, variety).
numeric_col : str, optional
Numeric field to aggregate. Required when agg is not "count";
ignored when agg is "count".
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
geopandas.GeoDataFrame or str or dict or None The compacted S2 cells in the specified format, or None if no valid cells found.
Examples¶
Compact from file¶
result = s2compact("cells.geojson") print(f"Compacted to {len(result)} cells")
Compact from list¶
result = s2compact(["31752f45cc94", "31752f45cc95"])
Compact only one parent level¶
result = s2compact(cells, depth=1)
Mean of a numeric field on compacted parents¶
result = s2compact(cells, agg="mean", numeric_col="value")
Compact to GeoJSON file¶
result = s2compact("cells.geojson", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/dggscompact/s2compact.py
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 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 | |
s2compact_cli()
¶
Command-line interface for s2compact with flexible input/output.
Source code in vgrid/conversion/dggscompact/s2compact.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
s2expand(input_data, resolution=None, s2_token='s2', output_format='gpd', fix_antimeridian=None, verbose=True, depth=None)
¶
Expand (uncompact) S2 cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down
(1 = direct children, 2 = grandchildren, and so on).
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing S2 cell tokens. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of S2 cell tokens
resolution : int, optional
Target S2 resolution to expand the cells to. Must be >= maximum input
resolution. When set, depth is ignored.
s2_token : str, default "s2"
Name of the column containing S2 cell tokens.
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
depth : int, optional
Relative expansion depth (1 <= depth <= max_res). Used when
resolution is not set. Each input cell is expanded depth
levels: 1 = direct children, 2 = grandchildren, and so on.
Returns¶
geopandas.GeoDataFrame or str or dict or None The expanded S2 cells in the specified format, or None if expansion fails.
Examples¶
result = s2expand("cells.geojson", resolution=10) result = s2expand(["31752f45cc94"], resolution=10) result = s2expand(cells, depth=1)
Source code in vgrid/conversion/dggscompact/s2compact.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
s2expand_cli()
¶
Command-line interface for s2expand with flexible input/output.
Source code in vgrid/conversion/dggscompact/s2compact.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 | |
A5 Compact Module
This module provides functionality to compact and expand A5 cells with flexible input and output formats.
Key Functions
a5_compact(a5_hexes, depth=-1, bags=None, verbose=True)
¶
Compact a list of A5 hex cell IDs by replacing complete child sets with parents.
Groups cells by their immediate parent and replaces a parent when every child
is present. Repeats until depth parent levels have been applied, or until
no further compaction is possible.
Parameters¶
a5_hexes : list of str
A5 hex string cell IDs to compact. Mixed resolutions are allowed.
depth : int, default -1
How many parent levels to climb (-1 to max_res):
- 0: do nothing (return the unique input cells)
- -1: compact as far as possible
- 1: replace complete sibling sets with their direct parent
- 2: then compact those parents (grandparents), and so on
bags : dict of list, optional
Per-cell lists of original values. When a complete child set is replaced
by its parent, child lists are concatenated onto the parent. Mutated
in place so remaining keys match the compacted IDs.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
list of str Sorted compacted A5 hex string cell IDs.
Source code in vgrid/conversion/dggscompact/a5compact.py
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 | |
a5_expand(a5_hexes, resolution=None, depth=None, verbose=True)
¶
Expand A5 hex strings to a target resolution, or by a relative child depth.
When resolution is set, depth is ignored and all cells are uncompacted
to that absolute resolution. When only depth is set, resolution is
ignored and each cell (at any resolution) is expanded to its descendants
depth levels down (1 = direct children, 2 = grandchildren, and
so on).
Parameters¶
a5_hexes : list of str
List of A5 hex string cell IDs. Mixed resolutions are allowed when
expanding by depth.
resolution : int, optional
Target A5 resolution to expand all cells to. When set, depth is
ignored.
depth : int, optional
Relative expansion depth (1 <= depth <= max_res). Used when
resolution is not set. 1 expands each cell to its direct
children; 2 to the next level, and so on.
Returns¶
list of str List of expanded A5 hex string cell IDs.
Examples¶
hexes = ["8e65b56628e0d07"] expanded = a5_expand(hexes, resolution=5) children = a5_expand(hexes, depth=1) grandchildren = a5_expand(hexes, depth=2)
Source code in vgrid/conversion/dggscompact/a5compact.py
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 | |
a5compact(input_data, a5_hex=None, depth=-1, agg='count', numeric_col=None, output_format='gpd', options=None, split_antimeridian=False, verbose=True)
¶
Compact A5 cells to their covering set at a given parent depth.
Compacts a set of A5 cells by replacing complete sets of children with their
parent cells. Mixed input resolutions are allowed and depth limits how
far up the hierarchy to merge.
When a complete sibling set is replaced by its parent, original child values
are combined with agg. If agg is "count", numeric_col is
ignored and the output count is the number of original input cells in
each compacted cell.
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing A5 cell IDs. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of A5 cell IDs
a5_hex : str, optional
Name of the column containing A5 cell IDs. Defaults to "a5".
depth : int, default -1
Compaction depth (-1 to max_res): 0 leaves cells unchanged,
-1 compact as far as possible, 1 merges to the direct parent,
2 to the grandparent, etc.
agg : str, default "count"
Aggregation applied to original child values when cells compact into a
parent. Same options as DGGS binning (count, min, max,
sum, mean, median, std, var, range,
minority, majority, variety).
numeric_col : str, optional
Numeric field to aggregate. Required when agg is not "count";
ignored when agg is "count".
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
options : dict, optional
Options for a52geo.
split_antimeridian : bool, optional
When True, apply antimeridian fixing to the resulting polygons.
Defaults to False when None or omitted.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
geopandas.GeoDataFrame or str or dict or None The compacted A5 cells in the specified format, or None if no valid cells found.
Examples¶
Compact from file¶
result = a5compact("cells.geojson") print(f"Compacted to {len(result)} cells")
Compact from list¶
result = a5compact(["8e65b56628e0d07", "8e65b56628e0d08"])
Compact only one parent level¶
result = a5compact(cells, depth=1)
Mean of a numeric field on compacted parents¶
result = a5compact(cells, agg="mean", numeric_col="value")
Compact to GeoJSON file¶
result = a5compact("cells.geojson", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/dggscompact/a5compact.py
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 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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 | |
a5compact_cli()
¶
Command-line interface for a5compact with flexible input/output.
Source code in vgrid/conversion/dggscompact/a5compact.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 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 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
a5expand(input_data, resolution=None, a5_hex=None, output_format='gpd', options=None, split_antimeridian=False, verbose=True, depth=None)
¶
Expand (uncompact) A5 cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down
(1 = direct children, 2 = grandchildren, and so on).
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing A5 cell IDs. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of A5 cell IDs
resolution : int, optional
Target A5 resolution to expand the cells to. Must be >= maximum input
resolution. When set, depth is ignored.
a5_hex : str, optional
Name of the column containing A5 cell IDs. Defaults to "a5".
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
options : dict, optional
Options for a52geo.
split_antimeridian : bool, optional
When True, apply antimeridian fixing to the resulting polygons.
Defaults to False when None or omitted.
depth : int, optional
Relative expansion depth (1 <= depth <= max_res). Used when
resolution is not set. Each input cell is expanded depth
levels: 1 = direct children, 2 = grandchildren, and so on.
Returns¶
geopandas.GeoDataFrame or str or dict or None The expanded A5 cells in the specified format, or None if expansion fails.
Examples¶
Expand from file¶
result = a5expand("cells.geojson", resolution=5) print(f"Expanded to {len(result)} cells")
Expand from list¶
result = a5expand(["8e65b56628e0d07"], resolution=5)
Expand mixed-resolution cells by relative depth¶
result = a5expand(cells, depth=1) result = a5expand(cells, depth=2)
Expand to GeoJSON file¶
result = a5expand("cells.geojson", resolution=5, output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/dggscompact/a5compact.py
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 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
a5expand_cli()
¶
Command-line interface for a5expand with flexible input/output.
Source code in vgrid/conversion/dggscompact/a5compact.py
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | |
RHEALPix Compact Module
This module provides functionality to compact and expand RHEALPix cells with flexible input and output formats.
Key Functions
rhealpix_compact(rhealpix_ids, depth=-1, bags=None, verbose=True)
¶
Compact a list of RHEALPix cell IDs by replacing complete child sets with parents.
Groups cells by their immediate parent and replaces a parent when every child
is present. Repeats until depth parent levels have been applied, or until
no further compaction is possible.
Parameters¶
rhealpix_ids : list of str
List of RHEALPix cell IDs to compact. Mixed resolutions are allowed.
depth : int, default -1
How many parent levels to climb:
- 0: do nothing (return the unique input cells)
- -1: compact as far as possible
- 1: replace complete sibling sets with their direct parent
- 2: then compact those parents (grandparents), and so on
bags : dict of list, optional
Per-cell lists of original values. When a complete child set is replaced
by its parent, child lists are concatenated onto the parent. Mutated
in place so remaining keys match the compacted IDs.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
list of str Sorted compacted RHEALPix cell IDs.
Examples¶
rhealpix_ids = ["A0", "A1", "A2", "A3"] compacted = rhealpix_compact(rhealpix_ids) print(f"Compacted {len(rhealpix_ids)} cells to {len(compacted)} cells")
Source code in vgrid/conversion/dggscompact/rhealpixcompact.py
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 | |
rhealpix_expand(rhealpix_ids, resolution=None, depth=None, verbose=True)
¶
Expand RHEALPix cells to a target resolution, or by a relative child depth.
When resolution is set, depth is ignored and all cells are expanded
to that absolute resolution. When only depth is set, resolution is
ignored and each cell is expanded depth levels down (1 = direct
children, 2 = grandchildren, and so on).
Returns cell objects (callers typically convert with str(cell)).
Source code in vgrid/conversion/dggscompact/rhealpixcompact.py
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 | |
rhealpixcompact(input_data, rhealpix_id='rhealpix', depth=-1, agg='count', numeric_col=None, output_format='gpd', fix_antimeridian=None, verbose=True)
¶
Compact RHEALPix cells to their covering set at a given parent depth.
Compacts a set of RHEALPix cells by replacing complete sets of children with
their parent cells. Mixed input resolutions are allowed and depth limits
how far up the hierarchy to merge.
When a complete sibling set is replaced by its parent, original child values
are combined with agg. If agg is "count", numeric_col is
ignored and the output count is the number of original input cells in
each compacted cell.
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing RHEALPix cell IDs. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of RHEALPix cell IDs
rhealpix_id : str, default "rhealpix"
Name of the column containing RHEALPix cell IDs.
depth : int, default -1
Compaction depth: 0 leaves cells unchanged, -1 compact as far as
possible, 1 merges to the direct parent, 2 to the grandparent, etc.
agg : str, default "count"
Aggregation applied to original child values when cells compact into a
parent. Same options as DGGS binning (count, min, max,
sum, mean, median, std, var, range,
minority, majority, variety).
numeric_col : str, optional
Numeric field to aggregate. Required when agg is not "count";
ignored when agg is "count".
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
fix_antimeridian : Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none
When True, apply antimeridian fixing to the resulting polygons.
Defaults to False when None or omitted.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
geopandas.GeoDataFrame or str or dict or None The compacted RHEALPix cells in the specified format, or None if no valid cells found.
Examples¶
Compact from file¶
result = rhealpixcompact("cells.geojson") print(f"Compacted to {len(result)} cells")
Compact from list¶
result = rhealpixcompact(["A0", "A1", "A2", "A3"])
Compact only one parent level¶
result = rhealpixcompact(cells, depth=1)
Mean of a numeric field on compacted parents¶
result = rhealpixcompact(cells, agg="mean", numeric_col="value")
Compact to GeoJSON file¶
result = rhealpixcompact("cells.geojson", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/dggscompact/rhealpixcompact.py
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 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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 | |
rhealpixexpand(input_data, resolution=None, rhealpix_id='rhealpix', output_format='gpd', fix_antimeridian=None, verbose=True, depth=None)
¶
Expand (uncompact) RHEALPix cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/rhealpixcompact.py
369 370 371 372 373 374 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 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
DGGAL Compact Module
This module provides functionality to compact and expand DGGAL cells with flexible input and output formats.
Key Functions
dggal_compact(dggs_type, zone_ids, depth=-1, bags=None, verbose=True)
¶
Compact a list of DGGAL cell IDs by replacing complete child sets with parents.
A zone may have multiple parents. Groups cells by every parent and replaces a
parent when every child is present. Repeats until depth parent levels have
been applied, or until no further compaction is possible.
Parameters¶
dggs_type : str
DGGAL DGGS type (e.g., "isea3h", "isea4t", "rhealpix").
zone_ids : list of str
DGGAL zone IDs to compact. Mixed resolutions are allowed.
depth : int, default -1
How many parent levels to climb:
- 0: do nothing (return the unique input cells)
- -1: compact as far as possible
- 1: replace complete sibling sets with their direct parent
- 2: then compact those parents (grandparents), and so on
bags : dict of list, optional
Per-cell lists of original values. When a complete child set is replaced
by its parent, child lists are concatenated onto the parent. Mutated
in place so remaining keys match the compacted IDs.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
list of str Sorted compacted DGGAL zone IDs.
Source code in vgrid/conversion/dggscompact/dggalcompact.py
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 | |
dggal_expand(dggs_type, zone_ids, resolution=None, depth=None, verbose=True)
¶
Expand DGGAL zone IDs to a target resolution, or by a relative child depth.
When resolution is set, depth is ignored and all cells are expanded
to that absolute resolution. When only depth is set, resolution is
ignored and each cell is expanded depth levels down (1 = direct
children, 2 = grandchildren, and so on).
Source code in vgrid/conversion/dggscompact/dggalcompact.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
dggalcompact(dggs_type, input_data, zone_id=None, depth=-1, agg='count', numeric_col=None, output_format='gpd', split_antimeridian=False, verbose=True)
¶
Compact DGGAL cells to their covering set at a given parent depth.
Compacts a set of DGGAL cells by replacing complete sets of children with their
parent cells. Mixed input resolutions are allowed and depth limits how far
up the hierarchy to merge.
When a complete sibling set is replaced by its parent, original child values
are combined with agg. If agg is "count", numeric_col is
ignored and the output count is the number of original input cells in
each compacted cell.
Parameters¶
dggs_type : str
DGGAL DGGS type (e.g., "isea3h", "isea4t", "rhealpix").
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing DGGAL zone IDs. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of DGGAL zone IDs
zone_id : str, optional
Name of the column containing DGGAL zone IDs. Defaults to "dggal_{dggs_type}".
depth : int, default -1
Compaction depth: 0 leaves cells unchanged, -1 compact as far as
possible, 1 merges to the direct parent, 2 to the grandparent, etc.
agg : str, default "count"
Aggregation applied to original child values when cells compact into a
parent (count, min, max, sum, mean, median,
std, var, range, minority, majority, variety).
numeric_col : str, optional
Numeric field to aggregate. Required when agg is not "count";
ignored when agg is "count".
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
split_antimeridian : bool, optional
When True, apply antimeridian fixing to the resulting polygons.
Defaults to False when None or omitted.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
geopandas.GeoDataFrame or str or dict or None The compacted DGGAL cells in the specified format, or None if no valid cells found.
Examples¶
Compact from file¶
result = dggalcompact("isea3h", "cells.geojson") print(f"Compacted to {len(result)} cells")
Compact from list¶
result = dggalcompact("isea3h", ["A0", "A1", "A2", "A3"])
Compact only one parent level¶
result = dggalcompact("isea3h", cells, depth=1)
Mean of a numeric field on compacted parents¶
result = dggalcompact("isea3h", cells, agg="mean", numeric_col="value")
Compact to GeoJSON file¶
result = dggalcompact("isea3h", "cells.geojson", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/dggscompact/dggalcompact.py
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 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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
dggalexpand(dggs_type, input_data, resolution=None, zone_id=None, output_format='gpd', split_antimeridian=False, verbose=True, depth=None)
¶
Expand (uncompact) DGGAL cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/dggalcompact.py
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 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
ISEA4T Compact Module
This module provides functionality to compact and expand ISEA4T cells with flexible input and output formats.
Key Functions
get_isea4t_cell_children(isea4t_cell, resolution)
¶
Recursively expands a DGGS cell until all children reach the desired resolution.
Source code in vgrid/conversion/dggscompact/isea4tcompact.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
isea4t_compact(isea4t_ids, depth=-1, bags=None, verbose=True)
¶
Compact a list of ISEA4T cell IDs by replacing complete child sets with parents.
Groups cells by their immediate parent and replaces a parent when every child
is present. Repeats until depth parent levels have been applied, or until
no further compaction is possible.
Parameters¶
isea4t_ids : list of str
ISEA4T cell IDs to compact. Mixed resolutions are allowed.
depth : int, default -1
How many parent levels to climb:
- 0: do nothing (return the unique input cells)
- -1: compact as far as possible
- 1: replace complete sibling sets with their direct parent
- 2: then compact those parents (grandparents), and so on
bags : dict of list, optional
Per-cell lists of original values. When a complete child set is replaced
by its parent, child lists are concatenated onto the parent. Mutated
in place so remaining keys match the compacted IDs.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
list of str Sorted compacted ISEA4T cell IDs.
Source code in vgrid/conversion/dggscompact/isea4tcompact.py
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 | |
isea4t_expand(isea4t_ids, resolution=None, depth=None, verbose=True)
¶
Expand ISEA4T cells to a target resolution, or by a relative child depth.
When resolution is set, depth is ignored and all cells are expanded
to that absolute resolution. When only depth is set, resolution is
ignored and each cell is expanded depth levels down (1 = direct
children, 2 = grandchildren, and so on).
Returns cell objects (callers typically map .get_cell_id()).
Source code in vgrid/conversion/dggscompact/isea4tcompact.py
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 | |
isea4tcompact(input_data, isea4t_id=None, depth=-1, agg='count', numeric_col=None, output_format='gpd', fix_antimeridian=None, verbose=True)
¶
Compact ISEA4T cells to their covering set at a given parent depth.
Compacts a set of ISEA4T cells by replacing complete sets of children with their
parent cells. Mixed input resolutions are allowed and depth limits how far
up the hierarchy to merge.
When a complete sibling set is replaced by its parent, original child values
are combined with agg. If agg is "count", numeric_col is
ignored and the output count is the number of original input cells in
each compacted cell.
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing ISEA4T cell IDs. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of ISEA4T cell IDs
isea4t_id : str, optional
Name of the column containing ISEA4T cell IDs. Defaults to "isea4t".
depth : int, default -1
Compaction depth: 0 leaves cells unchanged, -1 compact as far as
possible, 1 merges to the direct parent, 2 to the grandparent, etc.
agg : str, default "count"
Aggregation applied to original child values when cells compact into a
parent (count, min, max, sum, mean, median,
std, var, range, minority, majority, variety).
numeric_col : str, optional
Numeric field to aggregate. Required when agg is not "count";
ignored when agg is "count".
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
fix_antimeridian : str, optional
Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none
Defaults to None when omitted.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
geopandas.GeoDataFrame or str or dict or None The compacted ISEA4T cells in the specified format, or None if no valid cells found.
Examples¶
Compact from file¶
result = isea4tcompact("cells.geojson") print(f"Compacted to {len(result)} cells")
Compact from list¶
result = isea4tcompact(["A0", "A1", "A2", "A3"])
Compact only one parent level¶
result = isea4tcompact(cells, depth=1)
Mean of a numeric field on compacted parents¶
result = isea4tcompact(cells, agg="mean", numeric_col="value")
Compact to GeoJSON file¶
result = isea4tcompact("cells.geojson", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/dggscompact/isea4tcompact.py
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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 | |
isea4texpand(input_data, resolution=None, isea4t_id=None, output_format='gpd', fix_antimeridian=None, verbose=True, depth=None)
¶
Expand (uncompact) ISEA4T cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/isea4tcompact.py
367 368 369 370 371 372 373 374 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 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | |
ISEA3H Compact Module
This module provides functionality to compact and expand ISEA3H cells with flexible input and output formats.
Key Functions
get_isea3h_cell_children(isea3h_cell, resolution)
¶
Recursively expands a DGGS cell until all children reach the desired resolution.
Source code in vgrid/conversion/dggscompact/isea3hcompact.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
get_isea3h_resolution(isea3h_id)
¶
Get the resolution of an ISEA3H cell ID.
Source code in vgrid/conversion/dggscompact/isea3hcompact.py
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 | |
isea3h_compact(isea3h_ids, depth=-1, bags=None, verbose=True)
¶
Compact a list of ISEA3H cell IDs by replacing complete child sets with parents.
A cell may have multiple parents. Groups cells by every parent and replaces a
parent when every child is present. Repeats until depth parent levels have
been applied, or until no further compaction is possible.
Parameters¶
isea3h_ids : list of str
ISEA3H cell IDs to compact. Mixed resolutions are allowed.
depth : int, default -1
How many parent levels to climb:
- 0: do nothing (return the unique input cells)
- -1: compact as far as possible
- 1: replace complete sibling sets with their direct parent
- 2: then compact those parents (grandparents), and so on
bags : dict of list, optional
Per-cell lists of original values. When a complete child set is replaced
by its parent, child lists are concatenated onto the parent. Mutated
in place so remaining keys match the compacted IDs.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
list of str Sorted compacted ISEA3H cell IDs.
Source code in vgrid/conversion/dggscompact/isea3hcompact.py
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 152 153 154 155 156 157 158 159 | |
isea3h_expand(isea3h_ids, resolution=None, depth=None, verbose=True)
¶
Expand ISEA3H cells to a target resolution, or by a relative child depth.
When resolution is set, depth is ignored and all cells are expanded
to that absolute resolution. When only depth is set, resolution is
ignored and each cell is expanded depth levels down (1 = direct
children, 2 = grandchildren, and so on).
Returns cell objects (callers typically map .get_cell_id()).
Source code in vgrid/conversion/dggscompact/isea3hcompact.py
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 | |
isea3hcompact(input_data, isea3h_id=None, depth=-1, agg='count', numeric_col=None, output_format='gpd', fix_antimeridian=None, verbose=True)
¶
Compact ISEA3H cells to their covering set at a given parent depth.
Compacts a set of ISEA3H cells by replacing complete sets of children with their
parent cells. Mixed input resolutions are allowed and depth limits how far
up the hierarchy to merge.
When a complete sibling set is replaced by its parent, original child values
are combined with agg. If agg is "count", numeric_col is
ignored and the output count is the number of original input cells in
each compacted cell.
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing ISEA3H cell IDs. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of ISEA3H cell IDs
isea3h_id : str, optional
Name of the column containing ISEA3H cell IDs. Defaults to "isea3h".
depth : int, default -1
Compaction depth: 0 leaves cells unchanged, -1 compact as far as
possible, 1 merges to the direct parent, 2 to the grandparent, etc.
agg : str, default "count"
Aggregation applied to original child values when cells compact into a
parent (count, min, max, sum, mean, median,
std, var, range, minority, majority, variety).
numeric_col : str, optional
Numeric field to aggregate. Required when agg is not "count";
ignored when agg is "count".
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
fix_antimeridian : str, optional
Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none
Defaults to None when omitted.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
geopandas.GeoDataFrame or str or dict or None The compacted ISEA3H cells in the specified format, or None if no valid cells found.
Examples¶
Compact from file¶
result = isea3hcompact("cells.geojson") print(f"Compacted to {len(result)} cells")
Compact from list¶
result = isea3hcompact(["A0", "A1", "A2", "A3", "A4", "A5"])
Compact only one parent level¶
result = isea3hcompact(cells, depth=1)
Mean of a numeric field on compacted parents¶
result = isea3hcompact(cells, agg="mean", numeric_col="value")
Compact to GeoJSON file¶
result = isea3hcompact("cells.geojson", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/dggscompact/isea3hcompact.py
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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 289 290 291 292 293 294 295 296 | |
isea3hcompact_cli()
¶
Command-line interface for ISEA3H compaction.
Source code in vgrid/conversion/dggscompact/isea3hcompact.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 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 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
isea3hexpand(input_data, resolution=None, isea3h_id=None, output_format='gpd', fix_antimeridian=None, verbose=True, depth=None)
¶
Expand (uncompact) ISEA3H cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/isea3hcompact.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | |
isea3hexpand_cli()
¶
Command-line interface for ISEA3H expansion.
Source code in vgrid/conversion/dggscompact/isea3hcompact.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 | |
EASE Compact Module
This module provides functionality to compact and expand EASE cells with flexible input and output formats.
Key Functions
ease_compact(ease_ids, depth=-1, bags=None, verbose=True)
¶
Compact a list of EASE cell IDs by replacing complete child sets with parents.
Groups cells by their immediate parent and replaces a parent when every child
is present. Repeats until depth parent levels have been applied, or until
no further compaction is possible.
Parameters¶
ease_ids : list of str
List of EASE cell IDs to compact. Mixed resolutions are allowed.
depth : int, default -1
How many parent levels to climb:
- 0: do nothing (return the unique input cells)
- -1: compact as far as possible
- 1: replace complete sibling sets with their direct parent
- 2: then compact those parents (grandparents), and so on
bags : dict of list, optional
Per-cell lists of original values. When a complete child set is replaced
by its parent, child lists are concatenated onto the parent. Mutated
in place so remaining keys match the compacted IDs.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
list of str Sorted compacted EASE cell IDs.
Examples¶
ease_ids = ["L4.165767.02.02.20.71", "L4.165767.02.02.20.72"] compacted = ease_compact(ease_ids) print(f"Compacted {len(ease_ids)} cells to {len(compacted)} cells")
Source code in vgrid/conversion/dggscompact/easecompact.py
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 | |
ease_expand(ease_ids, resolution=None, depth=None, verbose=True)
¶
Expand EASE cell IDs to a target resolution, or by a relative child depth.
When resolution is set, depth is ignored. When only depth is
set, each cell is expanded depth levels down (1 = direct children,
2 = grandchildren, and so on).
Source code in vgrid/conversion/dggscompact/easecompact.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
easecompact(input_data, ease_id=None, depth=-1, agg='count', numeric_col=None, output_format='gpd', verbose=True)
¶
Compact EASE cells to their covering set at a given parent depth.
Compacts a set of EASE cells by replacing complete sets of children with
their parent cells. Mixed input resolutions are allowed and depth limits
how far up the hierarchy to merge.
When a complete sibling set is replaced by its parent, original child values
are combined with agg. If agg is "count", numeric_col is
ignored and the output count is the number of original input cells in
each compacted cell.
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing EASE cell IDs. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of EASE cell IDs
ease_id : str, optional
Name of the column containing EASE cell IDs. Defaults to "ease".
depth : int, default -1
Compaction depth: 0 leaves cells unchanged, -1 compact as far as
possible, 1 merges to the direct parent, 2 to the grandparent, etc.
agg : str, default "count"
Aggregation applied to original child values when cells compact into a
parent. Same options as DGGS binning (count, min, max,
sum, mean, median, std, var, range,
minority, majority, variety).
numeric_col : str, optional
Numeric field to aggregate. Required when agg is not "count";
ignored when agg is "count".
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
geopandas.GeoDataFrame or str or dict or None The compacted EASE cells in the specified format, or None if no valid cells found.
Examples¶
Compact from file¶
result = easecompact("cells.geojson") print(f"Compacted to {len(result)} cells")
Compact from list¶
result = easecompact(["L4.165767.02.02.20.71", "L4.165767.02.02.20.72"])
Compact only one parent level¶
result = easecompact(cells, depth=1)
Mean of a numeric field on compacted parents¶
result = easecompact(cells, agg="mean", numeric_col="value")
Compact to GeoJSON file¶
result = easecompact("cells.geojson", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/dggscompact/easecompact.py
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 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 225 226 227 228 229 | |
easecompact_cli()
¶
Command-line interface for EASE compaction.
Source code in vgrid/conversion/dggscompact/easecompact.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 289 290 291 292 293 294 295 296 297 | |
easeexpand(input_data, resolution=None, ease_id=None, output_format='gpd', verbose=True, depth=None)
¶
Expand (uncompact) EASE cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/easecompact.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 | |
easeexpand_cli()
¶
Command-line interface for EASE expansion.
Source code in vgrid/conversion/dggscompact/easecompact.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
QTM Compact Module
This module provides functionality to compact and expand QTM cells with flexible input and output formats.
Key Functions
get_qtm_resolution(qtm_id)
¶
Get the resolution of a QTM cell ID.
Source code in vgrid/conversion/dggscompact/qtmcompact.py
37 38 39 40 41 42 | |
qtm_compact(qtm_ids, depth=-1, bags=None, verbose=True)
¶
Compact a list of QTM cell IDs by replacing complete child sets with parents.
Groups cells by their immediate parent and replaces a parent when every child
is present. Repeats until depth parent levels have been applied, or until
no further compaction is possible.
Parameters¶
qtm_ids : list of str
QTM cell IDs to compact. Mixed resolutions are allowed.
depth : int, default -1
How many parent levels to climb:
- 0: do nothing (return the unique input cells)
- -1: compact as far as possible
- 1: replace complete sibling sets with their direct parent
- 2: then compact those parents (grandparents), and so on
bags : dict of list, optional
Per-cell lists of original values. When a complete child set is replaced
by its parent, child lists are concatenated onto the parent. Mutated
in place so remaining keys match the compacted IDs.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
list of str Sorted compacted QTM cell IDs.
Source code in vgrid/conversion/dggscompact/qtmcompact.py
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 | |
qtm_expand(qtm_ids, resolution=None, depth=None, verbose=True)
¶
Expand QTM cell IDs to a target resolution, or by a relative child depth.
When resolution is set, depth is ignored and all cells are expanded
to that absolute resolution. When only depth is set, resolution is
ignored and each cell is expanded depth levels down (1 = direct
children, 2 = grandchildren, and so on).
Source code in vgrid/conversion/dggscompact/qtmcompact.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
qtmcompact(input_data, qtm_id='qtm', depth=-1, agg='count', numeric_col=None, output_format='gpd', verbose=True)
¶
Compact QTM cells to their covering set at a given parent depth.
Compacts a set of QTM cells by replacing complete sets of children with
their parent cells. depth limits how far up the hierarchy to merge.
When a complete sibling set is replaced by its parent, original child values
are combined with agg (same options as h3bin). If agg is
"count", numeric_col is ignored and the output count is the
number of original input cells in each compacted cell.
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing QTM cell IDs. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of QTM cell IDs
qtm_id : str, default "qtm"
Name of the column containing QTM cell IDs.
depth : int, default -1
Compaction depth: 0 leaves cells unchanged, -1 compact as far as
possible, 1 merges to the direct parent, 2 to the grandparent, etc.
agg : str, default "count"
Aggregation applied to original child values when cells compact into a
parent. Same options as h3bin (count, min, max, sum,
mean, median, std, var, range, minority,
majority, variety).
numeric_col : str, optional
Numeric field to aggregate. Required when agg is not "count";
ignored when agg is "count".
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
geopandas.GeoDataFrame or str or dict or None The compacted QTM cells in the specified format, or None if no valid cells found.
Examples¶
Compact from file¶
result = qtmcompact("cells.geojson") print(f"Compacted to {len(result)} cells")
Compact from list¶
result = qtmcompact(["A0", "A1", "A2", "A3"])
Compact only one parent level¶
result = qtmcompact(cells, depth=1)
Mean of a numeric field on compacted parents¶
result = qtmcompact(cells, agg="mean", numeric_col="value")
Compact to GeoJSON file¶
result = qtmcompact("cells.geojson", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/dggscompact/qtmcompact.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 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 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 225 | |
qtmcompact_cli()
¶
Command-line interface for QTM compaction.
Source code in vgrid/conversion/dggscompact/qtmcompact.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 289 290 291 292 293 | |
qtmexpand(input_data, resolution=None, qtm_id='qtm', output_format='gpd', verbose=True, depth=None)
¶
Expand (uncompact) QTM cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/qtmcompact.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 | |
qtmexpand_cli()
¶
Command-line interface for QTM expansion.
Source code in vgrid/conversion/dggscompact/qtmcompact.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
OLC Compact Module
This module provides functionality to compact and expand OLC cells with flexible input and output formats.
Key Functions
get_olc_resolution(olc_id)
¶
Get the resolution of an OLC cell ID.
Source code in vgrid/conversion/dggscompact/olccompact.py
38 39 40 41 42 43 44 | |
olc_compact(olc_ids, depth=-1, bags=None, verbose=True)
¶
Compact a list of OLC cell IDs by replacing complete child sets with parents.
Groups cells by their immediate parent and replaces a parent when every child
is present. Repeats until depth parent levels have been applied, or until
no further compaction is possible.
Parameters¶
olc_ids : list of str
OLC cell IDs to compact. Mixed resolutions are allowed.
depth : int, default -1
How many parent levels to climb:
- 0: do nothing (return the unique input cells)
- -1: compact as far as possible
- 1: replace complete sibling sets with their direct parent
- 2: then compact those parents (grandparents), and so on
bags : dict of list, optional
Per-cell lists of original values. When a complete child set is replaced
by its parent, child lists are concatenated onto the parent. Mutated
in place so remaining keys match the compacted IDs.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
list of str Sorted compacted OLC cell IDs.
Source code in vgrid/conversion/dggscompact/olccompact.py
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 | |
olc_expand(olc_ids, resolution=None, depth=None, verbose=True)
¶
Expand OLC cell IDs to a target resolution, or by a relative child depth.
When resolution is set, depth is ignored and all cells are expanded
to that absolute code length. When only depth is set, resolution is
ignored and each cell is expanded depth OLC steps down (1 = next
valid OLC resolution, 2 = the one after that, and so on). OLC
resolutions are not linear: [2, 4, 6, 8, 10, 11, 12, 13, 14, 15].
Source code in vgrid/conversion/dggscompact/olccompact.py
315 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 343 344 345 346 347 | |
olccompact(input_data, olc_id=None, depth=-1, agg='count', numeric_col=None, output_format='gpd', verbose=True)
¶
Compact OLC cells to their covering set at a given parent depth.
Compacts a set of OLC cells by replacing complete sets of children with
their parent cells. depth limits how far up the hierarchy to merge.
When a complete sibling set is replaced by its parent, original child values
are combined with agg (same options as h3bin). If agg is
"count", numeric_col is ignored and the output count is the
number of original input cells in each compacted cell.
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing OLC cell IDs. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of OLC cell IDs
olc_id : str, optional
Name of the column containing OLC cell IDs. Defaults to "olc".
depth : int, default -1
Compaction depth: 0 leaves cells unchanged, -1 compact as far as
possible, 1 merges to the direct parent, 2 to the grandparent, etc.
agg : str, default "count"
Aggregation applied to original child values when cells compact into a
parent. Same options as h3bin (count, min, max, sum,
mean, median, std, var, range, minority,
majority, variety).
numeric_col : str, optional
Numeric field to aggregate. Required when agg is not "count";
ignored when agg is "count".
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
geopandas.GeoDataFrame or str or dict or None The compacted OLC cells in the specified format, or None if no valid cells found.
Examples¶
Compact from file¶
result = olccompact("cells.geojson") print(f"Compacted to {len(result)} cells")
Compact from list¶
result = olccompact(["7P28QPG4+4P7", "7P28QPG4+4P8"])
Compact only one parent level¶
result = olccompact(cells, depth=1)
Mean of a numeric field on compacted parents¶
result = olccompact(cells, agg="mean", numeric_col="value")
Compact to GeoJSON file¶
result = olccompact("cells.geojson", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/dggscompact/olccompact.py
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 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 225 226 227 228 | |
olccompact_cli()
¶
Command-line interface for OLC compaction.
Source code in vgrid/conversion/dggscompact/olccompact.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 289 290 291 292 293 294 295 296 | |
olcexpand(input_data, resolution=None, olc_id=None, output_format='gpd', verbose=True, depth=None)
¶
Expand (uncompact) OLC cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute code length (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded depth OLC steps down.
Source code in vgrid/conversion/dggscompact/olccompact.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 425 426 | |
olcexpand_cli()
¶
Command-line interface for OLC expansion.
Source code in vgrid/conversion/dggscompact/olccompact.py
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 | |
Geohash Compact Module
This module provides functionality to compact and expand Geohash cells with flexible input and output formats.
Key Functions
geohash_compact(geohash_ids, depth=-1, bags=None, verbose=True)
¶
Compact a list of Geohash cell IDs by replacing complete child sets with parents.
Groups cells by their immediate parent and replaces a parent when every child
is present. Repeats until depth parent levels have been applied, or until
no further compaction is possible.
Parameters¶
geohash_ids : list of str
Geohash cell IDs to compact. Mixed resolutions are allowed.
depth : int, default -1
How many parent levels to climb:
- 0: do nothing (return the unique input cells)
- -1: compact as far as possible
- 1: replace complete sibling sets with their direct parent
- 2: then compact those parents (grandparents), and so on
bags : dict of list, optional
Per-cell lists of original values. When a complete child set is replaced
by its parent, child lists are concatenated onto the parent. Mutated
in place so remaining keys match the compacted IDs.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
list of str Sorted compacted Geohash cell IDs.
Source code in vgrid/conversion/dggscompact/geohashcompact.py
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 | |
geohash_expand(geohash_ids, resolution=None, depth=None, verbose=True)
¶
Expand Geohash cell IDs to a target resolution, or by a relative child depth.
When resolution is set, depth is ignored and all cells are expanded
to that absolute resolution. When only depth is set, resolution is
ignored and each cell is expanded depth levels down (1 = direct
children, 2 = grandchildren, and so on).
Source code in vgrid/conversion/dggscompact/geohashcompact.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
geohashcompact(input_data, geohash_id=None, depth=-1, agg='count', numeric_col=None, output_format='gpd', verbose=True)
¶
Compact Geohash cells to their covering set at a given parent depth.
Compacts a set of Geohash cells by replacing complete sets of children with
their parent cells. depth limits how far up the hierarchy to merge.
When a complete sibling set is replaced by its parent, original child values
are combined with agg (same options as h3bin). If agg is
"count", numeric_col is ignored and the output count is the
number of original input cells in each compacted cell.
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing Geohash cell IDs. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of Geohash cell IDs
geohash_id : str, optional
Name of the column containing Geohash cell IDs. Defaults to "geohash".
depth : int, default -1
Compaction depth: 0 leaves cells unchanged, -1 compact as far as
possible, 1 merges to the direct parent, 2 to the grandparent, etc.
agg : str, default "count"
Aggregation applied to original child values when cells compact into a
parent. Same options as h3bin (count, min, max, sum,
mean, median, std, var, range, minority,
majority, variety).
numeric_col : str, optional
Numeric field to aggregate. Required when agg is not "count";
ignored when agg is "count".
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
geopandas.GeoDataFrame or str or dict or None The compacted Geohash cells in the specified format, or None if no valid cells found.
Examples¶
Compact from file¶
result = geohashcompact("cells.geojson") print(f"Compacted to {len(result)} cells")
Compact from list¶
result = geohashcompact(["w3gvk1td8", "w3gvk1td9"])
Compact only one parent level¶
result = geohashcompact(cells, depth=1)
Mean of a numeric field on compacted parents¶
result = geohashcompact(cells, agg="mean", numeric_col="value")
Compact to GeoJSON file¶
result = geohashcompact("cells.geojson", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/dggscompact/geohashcompact.py
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 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 | |
geohashcompact_cli()
¶
Command-line interface for Geohash compaction.
Source code in vgrid/conversion/dggscompact/geohashcompact.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 | |
geohashexpand(input_data, resolution=None, geohash_id=None, output_format='gpd', verbose=True, depth=None)
¶
Expand (uncompact) Geohash cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/geohashcompact.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 | |
geohashexpand_cli()
¶
Command-line interface for Geohash expansion.
Source code in vgrid/conversion/dggscompact/geohashcompact.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
get_geohash_resolution(geohash_id)
¶
Get the resolution of a Geohash cell ID.
Source code in vgrid/conversion/dggscompact/geohashcompact.py
37 38 39 | |
Tilecode Compact Module
This module provides functionality to compact and expand Tilecode cells with flexible input and output formats.
Key Functions
tilecode_compact(tilecode_ids, depth=-1, bags=None, verbose=True)
¶
Compact a list of Tilecode cell IDs by replacing complete child sets with parents.
Groups cells by their immediate parent and replaces a parent when every child
is present. Repeats until depth parent levels have been applied, or until
no further compaction is possible.
Parameters¶
tilecode_ids : list of str
Tilecode cell IDs to compact. Mixed resolutions are allowed.
depth : int, default -1
How many parent levels to climb:
- 0: do nothing (return the unique input cells)
- -1: compact as far as possible
- 1: replace complete sibling sets with their direct parent
- 2: then compact those parents (grandparents), and so on
bags : dict of list, optional
Per-cell lists of original values. When a complete child set is replaced
by its parent, child lists are concatenated onto the parent. Mutated
in place so remaining keys match the compacted IDs.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
list of str Sorted compacted Tilecode cell IDs.
Source code in vgrid/conversion/dggscompact/tilecodecompact.py
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 | |
tilecode_expand(tilecode_ids, resolution=None, depth=None, verbose=True)
¶
Expand Tilecode cell IDs to a target resolution, or by a relative child depth.
When resolution is set, depth is ignored and all cells are expanded
to that absolute resolution. When only depth is set, resolution is
ignored and each cell is expanded depth levels down (1 = direct
children, 2 = grandchildren, and so on).
Source code in vgrid/conversion/dggscompact/tilecodecompact.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
tilecodecompact(input_data, tilecode_id='tilecode', depth=-1, agg='count', numeric_col=None, output_format='gpd', verbose=True)
¶
Compact Tilecode cells to their covering set at a given parent depth.
Compacts a set of Tilecode cells by replacing complete sets of children with
their parent cells. depth limits how far up the hierarchy to merge.
When a complete sibling set is replaced by its parent, original child values
are combined with agg (same options as h3bin). If agg is
"count", numeric_col is ignored and the output count is the
number of original input cells in each compacted cell.
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing Tilecode cell IDs. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of Tilecode cell IDs
tilecode_id : str, default "tilecode"
Name of the column containing Tilecode cell IDs.
depth : int, default -1
Compaction depth: 0 leaves cells unchanged, -1 compact as far as
possible, 1 merges to the direct parent, 2 to the grandparent, etc.
agg : str, default "count"
Aggregation applied to original child values when cells compact into a
parent. Same options as h3bin (count, min, max, sum,
mean, median, std, var, range, minority,
majority, variety).
numeric_col : str, optional
Numeric field to aggregate. Required when agg is not "count";
ignored when agg is "count".
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
geopandas.GeoDataFrame or str or dict or None The compacted Tilecode cells in the specified format, or None if no valid cells found.
Examples¶
Compact from file¶
result = tilecodecompact("cells.geojson") print(f"Compacted to {len(result)} cells")
Compact from list¶
result = tilecodecompact(["z3x1y1", "z3x1y2", "z3x2y1", "z3x2y2"])
Compact only one parent level¶
result = tilecodecompact(cells, depth=1)
Mean of a numeric field on compacted parents¶
result = tilecodecompact(cells, agg="mean", numeric_col="value")
Compact to GeoJSON file¶
result = tilecodecompact("cells.geojson", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/dggscompact/tilecodecompact.py
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 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 | |
tilecodecompact_cli()
¶
Command-line interface for Tilecode compaction.
Source code in vgrid/conversion/dggscompact/tilecodecompact.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 | |
tilecodeexpand(input_data, resolution=None, tilecode_id='tilecode', output_format='gpd', verbose=True, depth=None)
¶
Expand (uncompact) Tilecode cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/tilecodecompact.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 | |
tilecodeexpand_cli()
¶
Command-line interface for Tilecode expansion.
Source code in vgrid/conversion/dggscompact/tilecodecompact.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
Quadkey Compact Module
This module provides functionality to compact and expand Quadkey cells with flexible input and output formats.
Key Functions
quadkey_compact(quadkey_ids, depth=-1, bags=None, verbose=True)
¶
Compact a list of Quadkey cell IDs by replacing complete child sets with parents.
Groups cells by their immediate parent and replaces a parent when every child
is present. Repeats until depth parent levels have been applied, or until
no further compaction is possible.
Parameters¶
quadkey_ids : list of str
Quadkey cell IDs to compact. Mixed resolutions are allowed.
depth : int, default -1
How many parent levels to climb:
- 0: do nothing (return the unique input cells)
- -1: compact as far as possible
- 1: replace complete sibling sets with their direct parent
- 2: then compact those parents (grandparents), and so on
bags : dict of list, optional
Per-cell lists of original values. When a complete child set is replaced
by its parent, child lists are concatenated onto the parent. Mutated
in place so remaining keys match the compacted IDs.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
list of str Sorted compacted Quadkey cell IDs.
Source code in vgrid/conversion/dggscompact/quadkeycompact.py
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 | |
quadkey_expand(quadkey_ids, resolution=None, depth=None, verbose=True)
¶
Expand Quadkey cell IDs to a target resolution, or by a relative child depth.
When resolution is set, depth is ignored and all cells are expanded
to that absolute resolution. When only depth is set, resolution is
ignored and each cell is expanded depth levels down (1 = direct
children, 2 = grandchildren, and so on).
Source code in vgrid/conversion/dggscompact/quadkeycompact.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
quadkeycompact(input_data, quadkey_id='quadkey', depth=-1, agg='count', numeric_col=None, output_format='gpd', verbose=True)
¶
Compact Quadkey cells to their covering set at a given parent depth.
Compacts a set of Quadkey cells by replacing complete sets of children with
their parent cells. depth limits how far up the hierarchy to merge.
When a complete sibling set is replaced by its parent, original child values
are combined with agg (same options as h3bin). If agg is
"count", numeric_col is ignored and the output count is the
number of original input cells in each compacted cell.
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing Quadkey cell IDs. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of Quadkey cell IDs
quadkey_id : str, default "quadkey"
Name of the column containing Quadkey cell IDs.
depth : int, default -1
Compaction depth: 0 leaves cells unchanged, -1 compact as far as
possible, 1 merges to the direct parent, 2 to the grandparent, etc.
agg : str, default "count"
Aggregation applied to original child values when cells compact into a
parent. Same options as h3bin (count, min, max, sum,
mean, median, std, var, range, minority,
majority, variety).
numeric_col : str, optional
Numeric field to aggregate. Required when agg is not "count";
ignored when agg is "count".
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
geopandas.GeoDataFrame or str or dict or None The compacted Quadkey cells in the specified format, or None if no valid cells found.
Examples¶
Compact from file¶
result = quadkeycompact("cells.geojson") print(f"Compacted to {len(result)} cells")
Compact from list¶
result = quadkeycompact(["13223011131020220011133", "13223011131020220011134"])
Compact only one parent level¶
result = quadkeycompact(cells, depth=1)
Mean of a numeric field on compacted parents¶
result = quadkeycompact(cells, agg="mean", numeric_col="value")
Compact to GeoJSON file¶
result = quadkeycompact("cells.geojson", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/dggscompact/quadkeycompact.py
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 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 | |
quadkeycompact_cli()
¶
Command-line interface for Quadkey compaction.
Source code in vgrid/conversion/dggscompact/quadkeycompact.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 | |
quadkeyexpand(input_data, resolution=None, quadkey_id='quadkey', output_format='gpd', verbose=True, depth=None)
¶
Expand (uncompact) Quadkey cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/quadkeycompact.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 | |
quadkeyexpand_cli()
¶
Command-line interface for Quadkey expansion.
Source code in vgrid/conversion/dggscompact/quadkeycompact.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
Digipin Compact Module
This module provides functionality to compact and expand DIGIPIN cells with flexible input and output formats.
Key Functions
digipin_compact(digipin_ids, depth=-1, bags=None, verbose=True)
¶
Compact a list of DIGIPIN cell IDs by replacing complete child sets with parents.
Groups cells by their immediate parent and replaces a parent when every child
is present. Repeats until depth parent levels have been applied, or until
no further compaction is possible.
Parameters¶
digipin_ids : list of str
DIGIPIN cell IDs to compact. Mixed resolutions are allowed.
depth : int, default -1
How many parent levels to climb:
- 0: do nothing (return the unique input cells)
- -1: compact as far as possible
- 1: replace complete sibling sets with their direct parent
- 2: then compact those parents (grandparents), and so on
bags : dict of list, optional
Per-cell lists of original values. When a complete child set is replaced
by its parent, child lists are concatenated onto the parent. Mutated
in place so remaining keys match the compacted IDs.
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
list of str Sorted compacted DIGIPIN cell IDs.
Source code in vgrid/conversion/dggscompact/digipincompact.py
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 | |
digipin_expand(digipin_ids, resolution=None, depth=None, verbose=True)
¶
Expand DIGIPIN cell IDs to a target resolution, or by a relative child depth.
When resolution is set, depth is ignored and all cells are expanded
to that absolute resolution. When only depth is set, resolution is
ignored and each cell is expanded depth levels down (1 = direct
children, 2 = grandchildren, and so on).
Source code in vgrid/conversion/dggscompact/digipincompact.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
digipincompact(input_data, digipin_id='digipin', depth=-1, agg='count', numeric_col=None, output_format='gpd', verbose=True)
¶
Compact DIGIPIN cells to their covering set at a given parent depth.
Compacts a set of DIGIPIN cells by replacing complete sets of children with
their parent cells. depth limits how far up the hierarchy to merge.
When a complete sibling set is replaced by its parent, original child values
are combined with agg (same options as h3bin). If agg is
"count", numeric_col is ignored and the output count is the
number of original input cells in each compacted cell.
Parameters¶
input_data : str, dict, geopandas.GeoDataFrame, or list
Input data containing DIGIPIN cell IDs. Can be:
- File path (GeoJSON, Shapefile, CSV, Parquet)
- URL to a file
- GeoJSON dictionary
- GeoDataFrame
- List of DIGIPIN cell IDs
digipin_id : str, default "digipin"
Name of the column containing DIGIPIN cell IDs.
depth : int, default -1
Compaction depth: 0 leaves cells unchanged, -1 compact as far as
possible, 1 merges to the direct parent, 2 to the grandparent, etc.
agg : str, default "count"
Aggregation applied to original child values when cells compact into a
parent. Same options as h3bin (count, min, max, sum,
mean, median, std, var, range, minority,
majority, variety).
numeric_col : str, optional
Numeric field to aggregate. Required when agg is not "count";
ignored when agg is "count".
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
verbose : bool, default True
Show tqdm progress bars. Use False to hide them.
Returns¶
geopandas.GeoDataFrame or str or dict or None The compacted DIGIPIN cells in the specified format, or None if no valid cells found.
Examples¶
Compact from file¶
result = digipincompact("cells.geojson") print(f"Compacted to {len(result)} cells")
Compact from list¶
result = digipincompact(["F3K-F", "F3K-C", "F3K-9", "F3K-8"])
Compact only one parent level¶
result = digipincompact(cells, depth=1)
Mean of a numeric field on compacted parents¶
result = digipincompact(cells, agg="mean", numeric_col="value")
Compact to GeoJSON file¶
result = digipincompact("cells.geojson", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/dggscompact/digipincompact.py
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 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 | |
digipincompact_cli()
¶
Command-line interface for DIGIPIN compaction.
Source code in vgrid/conversion/dggscompact/digipincompact.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 | |
digipinexpand(input_data, resolution=None, digipin_id='digipin', output_format='gpd', verbose=True, depth=None)
¶
Expand (uncompact) DIGIPIN cells to a target resolution or by a relative depth.
When resolution is set, depth is ignored and cells are expanded to
that absolute resolution (must be >= the maximum input resolution). When
only depth is set, resolution is ignored: mixed-resolution input is
allowed and each cell is expanded to its descendants depth levels down.
Source code in vgrid/conversion/dggscompact/digipincompact.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 | |
digipinexpand_cli()
¶
Command-line interface for DIGIPIN expansion.
Source code in vgrid/conversion/dggscompact/digipincompact.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |