Vector to DGGS
Vector to DGGS conversion functions.
This submodule provides functions to convert vector geometries to various discrete global grid systems (DGGS).
Vector to H3 Module
This module provides functionality to convert vector geometries to H3 grid cells with flexible input and output formats.
Key Functions
geodataframe2h3(gdf, resolution=None, predicate=None, compact=False, topology=False, include_properties=True, fix_antimeridian=None)
¶
Convert a GeoDataFrame to H3 grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
GeoDataFrame to convert |
required |
resolution
|
int
|
H3 resolution [0..15]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable H3 compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint H3 cells |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame: GeoDataFrame with H3 grid cells |
Example
import geopandas as gpd from shapely.geometry import Point gdf = gpd.GeoDataFrame({ ... 'name': ['San Francisco'], ... 'geometry': [Point(-122.4194, 37.7749)] ... }) result = geodataframe2h3(gdf, 10) len(result) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2h3.py
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 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 379 380 381 382 383 384 385 386 387 388 389 390 | |
point2h3(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, fix_antimeridian=None)
¶
Convert a point geometry to H3 grid cells.
Converts point or multipoint geometries to H3 grid cells at the specified resolution. Each point is assigned to its containing H3 cell.
Parameters¶
feature : shapely.geometry.Point or shapely.geometry.MultiPoint Point geometry to convert to H3 cells. resolution : int H3 resolution level [0..15]. feature_properties : dict, optional Properties to include in output features. predicate : str, optional Spatial predicate to apply (not used for points). compact : bool, optional Enable H3 compact mode (not used for points). topology : bool, optional Enable topology preserving mode (handled by geodataframe2h3). include_properties : bool, optional Whether to include properties in output.
Returns¶
list of dict List of dictionaries representing H3 cells containing the point(s). Each dictionary contains H3 cell properties and geometry.
Examples¶
from shapely.geometry import Point point = Point(-122.4194, 37.7749) # San Francisco cells = point2h3(point, 10, {"name": "SF"}) len(cells) 1
from shapely.geometry import MultiPoint points = MultiPoint([(-122.4194, 37.7749), (-74.0060, 40.7128)]) cells = point2h3(points, 8) len(cells) 2
Source code in vgrid/conversion/vector2dggs/vector2h3.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
polygon2h3(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, fix_antimeridian=None)
¶
Convert a polygon geometry to H3 grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Polygon or MultiPolygon
|
Polygon geometry to convert |
required |
resolution
|
int
|
H3 resolution [0..15] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable H3 compact mode to reduce cell count |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2h3) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of dictionaries representing H3 cells based on predicate |
Example
from shapely.geometry import Polygon poly = Polygon([(-122.5, 37.7), (-122.3, 37.7), (-122.3, 37.9), (-122.5, 37.9)]) cells = polygon2h3(poly, 10, {"name": "area"}, predicate="intersect") len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2h3.py
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 | |
polyline2h3(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, fix_antimeridian=None)
¶
Convert a polyline geometry to H3 grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
LineString or MultiLineString
|
Polyline geometry to convert |
required |
resolution
|
int
|
H3 resolution [0..15] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply (not used for polylines) |
None
|
compact
|
bool
|
Enable H3 compact mode (not used for polylines) |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2h3) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of dictionaries representing H3 cells intersecting the polyline |
Example
from shapely.geometry import LineString line = LineString([(-122.4194, 37.7749), (-122.4000, 37.7800)]) cells = polyline2h3(line, 10, {"name": "route"}) len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2h3.py
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 | |
vector2h3(vector_data, resolution=None, predicate=None, compact=False, topology=False, output_format='gpd', include_properties=True, fix_antimeridian=None, **kwargs)
¶
Convert vector data to H3 grid cells from various input formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector_data
|
str, geopandas.GeoDataFrame, pandas.DataFrame, dict, or list
|
Input vector data |
required |
resolution
|
int
|
H3 resolution [0..15]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable H3 compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint H3 cells |
False
|
output_format
|
str
|
Output format ('gpd', 'geojson', 'csv', 'shapefile', 'gpkg', 'parquet', 'geoparquet') |
'gpd'
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
**kwargs
|
Additional arguments passed to process_input_data_vector |
{}
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame, dict, or str: Output in the specified format. If output_format is a file-based format, |
|
|
the output will be saved to a file in the current directory with a default name based on the input. |
|
|
Otherwise, returns a Python object (GeoDataFrame, dict, etc.) depending on output_format. |
Example
result = vector2h3("data/points.geojson", resolution=10, output_format="geojson") print(f"Output saved to: {result}")
Source code in vgrid/conversion/vector2dggs/vector2h3.py
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 | |
vector2h3_cli()
¶
Command-line interface for vector2h3 conversion.
This function provides a command-line interface for converting vector data to H3 grid cells. It supports various input formats and output formats, with options for resolution control, spatial predicates, compact mode, and topology preservation.
Usage
python vector2h3.py -i input.geojson -r 10 -f geojson python vector2h3.py -i input.shp -r 8 -p intersect -c -t
Source code in vgrid/conversion/vector2dggs/vector2h3.py
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 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | |
Vector to S2 Module
This module provides functionality to convert vector geometries to S2 grid cells with flexible input and output formats.
Key Functions
geodataframe2s2(gdf, resolution=None, predicate=None, compact=False, topology=False, include_properties=True, fix_antimeridian=None)
¶
Convert a GeoDataFrame to S2 grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
GeoDataFrame to convert |
required |
resolution
|
int
|
S2 resolution level [0..30]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable S2 compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint S2 cells |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame: GeoDataFrame with S2 grid cells |
Example
import geopandas as gpd from shapely.geometry import Point gdf = gpd.GeoDataFrame({ ... 'name': ['San Francisco'], ... 'geometry': [Point(-122.4194, 37.7749)] ... }) result = geodataframe2s2(gdf, 10) len(result) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2s2.py
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 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 | |
point2s2(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, fix_antimeridian=None)
¶
Convert a point geometry to S2 grid cells.
Converts point or multipoint geometries to S2 grid cells at the specified resolution. Each point is assigned to its containing S2 cell.
Parameters¶
feature : shapely.geometry.Point or shapely.geometry.MultiPoint Point geometry to convert to S2 cells. resolution : int S2 resolution level [0..30]. feature_properties : dict, optional Properties to include in output features. predicate : str, optional Spatial predicate to apply (not used for points). compact : bool, optional Enable S2 compact mode (not used for points). topology : bool, optional Enable topology preserving mode (handled by geodataframe2s2). include_properties : bool, optional Whether to include properties in output.
Returns¶
list of dict List of dictionaries representing S2 cells containing the point(s). Each dictionary contains S2 cell properties and geometry.
Examples¶
from shapely.geometry import Point point = Point(-122.4194, 37.7749) # San Francisco cells = point2s2(point, 10, {"name": "SF"}) len(cells) 1
from shapely.geometry import MultiPoint points = MultiPoint([(-122.4194, 37.7749), (-74.0060, 40.7128)]) cells = point2s2(points, 8) len(cells) 2
Source code in vgrid/conversion/vector2dggs/vector2s2.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
polygon2s2(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, all_polygons=None, fix_antimeridian=None)
¶
Convert a polygon geometry to S2 grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Polygon or MultiPolygon
|
Polygon geometry to convert |
required |
resolution
|
int
|
S2 resolution level [0..30] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable S2 compact mode to reduce cell count |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2s2) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
all_polygons
|
list
|
List of all polygons for topology preservation (not used in this function) |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of dictionaries representing S2 cells based on predicate |
Example
from shapely.geometry import Polygon poly = Polygon([(-122.5, 37.7), (-122.3, 37.7), (-122.3, 37.9), (-122.5, 37.9)]) cells = polygon2s2(poly, 10, {"name": "area"}, predicate="intersect") len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2s2.py
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 | |
polyline2s2(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, all_polylines=None, fix_antimeridian=None)
¶
Convert a polyline geometry to S2 grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
LineString or MultiLineString
|
Polyline geometry to convert |
required |
resolution
|
int
|
S2 resolution level [0..30] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply (not used for polylines) |
None
|
compact
|
bool
|
Enable S2 compact mode (not used for polylines) |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2s2) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
all_polylines
|
list
|
List of all polylines for topology preservation (not used in this function) |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of dictionaries representing S2 cells intersecting the polyline |
Example
from shapely.geometry import LineString line = LineString([(-122.4194, 37.7749), (-122.4000, 37.7800)]) cells = polyline2s2(line, 10, {"name": "route"}) len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2s2.py
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 | |
vector2s2(vector_data, resolution=None, predicate=None, compact=False, topology=False, output_format='gpd', include_properties=True, fix_antimeridian=None, **kwargs)
¶
Convert vector data to S2 grid cells from various input formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector_data
|
str, geopandas.GeoDataFrame, pandas.DataFrame, dict, or list
|
Input vector data |
required |
resolution
|
int
|
S2 resolution level [0..30]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable S2 compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint S2 cells |
False
|
output_format
|
str
|
Output format ('gpd', 'geojson', 'csv', 'shapefile', 'gpkg', 'parquet', 'geoparquet') |
'gpd'
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
**kwargs
|
Additional arguments passed to process_input_data_vector |
{}
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame, dict, or str: Output in the specified format. If output_format is a file-based format, |
|
|
the output will be saved to a file in the current directory with a default name based on the input. |
|
|
Otherwise, returns a Python object (GeoDataFrame, dict, etc.) depending on output_format. |
Example
result = vector2s2("data/points.geojson", resolution=10, output_format="geojson") print(f"Output saved to: {result}")
Source code in vgrid/conversion/vector2dggs/vector2s2.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 467 468 469 470 471 472 473 474 475 476 477 | |
vector2s2_cli()
¶
Command-line interface for vector2s2 conversion.
This function provides a command-line interface for converting vector data to S2 grid cells. It supports various input formats and output formats, with options for resolution control, spatial predicates, compact mode, and topology preservation.
Usage
python vector2s2.py -i input.geojson -r 10 -f geojson python vector2s2.py -i input.shp -r 8 -p intersect -c -t
Source code in vgrid/conversion/vector2dggs/vector2s2.py
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 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 | |
Vector to A5 Module
This module provides functionality to convert vector geometries to A5 grid cells with flexible input and output formats.
Key Functions
geodataframe2a5(gdf, resolution=None, predicate=None, compact=False, topology=False, include_properties=True, options=None, split_antimeridian=False)
¶
Convert a GeoDataFrame to A5 grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
GeoDataFrame to convert |
required |
resolution
|
int
|
A5 resolution level [0..28]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable A5 compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint A5 cells |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
options
|
dict
|
Options for a52geo. |
None
|
split_antimeridian
|
bool
|
When True, apply antimeridian fixing to the resulting polygons. |
False
|
Example
import geopandas as gpd from shapely.geometry import Point gdf = gpd.GeoDataFrame({ ... 'name': ['San Francisco'], ... 'geometry': [Point(-122.4194, 37.7749)] ... }) result = geodataframe2a5(gdf, 10) len(result) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2a5.py
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 511 512 513 514 515 516 517 518 519 520 521 522 | |
point2a5(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, options=None, split_antimeridian=False)
¶
Convert a point geometry to A5 grid cells.
Converts point or multipoint geometries to A5 grid cells at the specified resolution. Each point is assigned to its containing A5 cell.
Parameters¶
feature : shapely.geometry.Point or shapely.geometry.MultiPoint Point geometry to convert to A5 cells. resolution : int A5 resolution level [0..28]. feature_properties : dict, optional Properties to include in output features. predicate : str, optional Spatial predicate to apply (not used for points). compact : bool, optional Enable A5 compact mode (not used for points). topology : bool, optional Enable topology preserving mode (handled by geodataframe2a5). include_properties : bool, optional Whether to include properties in output. 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. Returns
list of dict List of dictionaries representing A5 cells containing the point(s). Each dictionary contains A5 cell properties and geometry.
Examples¶
from shapely.geometry import Point point = Point(-122.4194, 37.7749) # San Francisco cells = point2a5(point, 10, {"name": "SF"}) len(cells) 1
from shapely.geometry import MultiPoint points = MultiPoint([(-122.4194, 37.7749), (-74.0060, 40.7128)]) cells = point2a5(points, 8) len(cells) 2
Source code in vgrid/conversion/vector2dggs/vector2a5.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
polygon2a5(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, options=None, split_antimeridian=False)
¶
Convert a polygon geometry to A5 grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Polygon or MultiPolygon
|
Polygon geometry to convert |
required |
resolution
|
int
|
A5 resolution level [0..28] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable A5 compact mode to reduce cell count |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2a5) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
options
|
dict
|
Options for a52geo. |
None
|
split_antimeridian
|
bool
|
When True, apply antimeridian fixing to the resulting polygons. |
False
|
Example
from shapely.geometry import Polygon poly = Polygon([(-122.5, 37.7), (-122.3, 37.7), (-122.3, 37.9), (-122.5, 37.9)]) cells = polygon2a5(poly, 10, {"name": "area"}, predicate="intersect") len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2a5.py
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 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 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
polyline2a5(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, options=None, split_antimeridian=False)
¶
Convert a polyline geometry to A5 grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
LineString or MultiLineString
|
Polyline geometry to convert |
required |
resolution
|
int
|
A5 resolution level [0..28] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply (not used for polylines) |
None
|
compact
|
bool
|
Enable A5 compact mode (not used for polylines) |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2a5) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
options
|
dict
|
Options for a52geo. |
None
|
split_antimeridian
|
bool
|
When True, apply antimeridian fixing to the resulting polygons. |
False
|
Example
from shapely.geometry import LineString line = LineString([(-122.4194, 37.7749), (-122.4000, 37.7800)]) cells = polyline2a5(line, 10, {"name": "route"}) len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2a5.py
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 252 253 254 255 256 | |
vector2a5(vector_data, resolution=None, predicate=None, compact=False, topology=False, output_format='gpd', include_properties=True, options=None, split_antimeridian=False, **kwargs)
¶
Convert vector data to A5 grid cells from various input formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector_data
|
str, geopandas.GeoDataFrame, pandas.DataFrame, dict, or list
|
Input vector data |
required |
resolution
|
int
|
A5 resolution level [0..28]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable A5 compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint A5 cells |
False
|
output_format
|
str
|
Output format ('gpd', 'geojson', 'csv', 'shapefile', 'gpkg', 'parquet', 'geoparquet') |
'gpd'
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
options
|
dict
|
Options for a52geo. |
None
|
split_antimeridian
|
bool
|
When True, apply antimeridian fixing to the resulting polygons. |
False
|
**kwargs
|
Additional arguments passed to process_input_data_vector |
{}
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame, dict, or str: Output in the specified format. If output_format is a file-based format, |
|
|
the output will be saved to a file in the current directory with a default name based on the input. |
|
|
Otherwise, returns a Python object (GeoDataFrame, dict, etc.) depending on output_format. |
Example
result = vector2a5("data/points.geojson", resolution=10, output_format="geojson") print(f"Output saved to: {result}")
Source code in vgrid/conversion/vector2dggs/vector2a5.py
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 | |
vector2a5_cli()
¶
Command-line interface for vector2a5 conversion.
This function provides a command-line interface for converting vector data to A5 grid cells. It supports various input formats and output formats, with options for resolution control, spatial predicates, compact mode, and topology preservation.
Usage
python vector2a5.py -i input.geojson -r 10 -f geojson python vector2a5.py -i input.shp -r 8 -p intersect -c -t
Source code in vgrid/conversion/vector2dggs/vector2a5.py
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 | |
Vector to RHEALPix Module
This module provides functionality to convert vector geometries to RHEALPix grid cells with flexible input and output formats.
Key Functions
geodataframe2rhealpix(gdf, resolution=None, predicate=None, compact=False, topology=False, include_properties=True, fix_antimeridian=None)
¶
Convert a GeoDataFrame to rHEALPix grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
GeoDataFrame to convert |
required |
resolution
|
int
|
rHEALPix resolution level [0..30]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable rHEALPix compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint rHEALPix cells |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
fix_antimeridian
|
str
|
Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none |
None
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame: GeoDataFrame with rHEALPix grid cells |
Example
import geopandas as gpd from shapely.geometry import Point gdf = gpd.GeoDataFrame({ ... 'name': ['San Francisco'], ... 'geometry': [Point(-122.4194, 37.7749)] ... }) result = geodataframe2rhealpix(gdf, 10) len(result) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2rhealpix.py
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 | |
point2rhealpix(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, fix_antimeridian=None)
¶
Convert a point geometry to RHEALPix grid cells.
Converts point or multipoint geometries to RHEALPix grid cells at the specified resolution. Each point is assigned to its containing RHEALPix cell.
Parameters¶
feature : shapely.geometry.Point or shapely.geometry.MultiPoint Point geometry to convert to RHEALPix cells. resolution : int RHEALPix resolution level [0..30]. feature_properties : dict, optional Properties to include in output features. predicate : str, optional Spatial predicate to apply (not used for points). compact : bool, optional Enable RHEALPix compact mode (not used for points). topology : bool, optional Enable topology preserving mode (handled by geodataframe2rhealpix). include_properties : bool, optional Whether to include properties in output. fix_antimeridian : str, optional Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none Defaults to None when omitted.
Returns¶
list of dict List of dictionaries representing RHEALPix cells containing the point(s). Each dictionary contains RHEALPix cell properties and geometry.
Examples¶
from shapely.geometry import Point point = Point(-122.4194, 37.7749) # San Francisco cells = point2rhealpix(point, 10, {"name": "SF"}) len(cells) 1
from shapely.geometry import MultiPoint points = MultiPoint([(-122.4194, 37.7749), (-74.0060, 40.7128)]) cells = point2rhealpix(points, 8) len(cells) 2
Source code in vgrid/conversion/vector2dggs/vector2rhealpix.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
polygon2rhealpix(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, fix_antimeridian=None)
¶
Convert a polygon geometry to rHEALPix grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Polygon or MultiPolygon
|
Polygon geometry to convert |
required |
resolution
|
int
|
rHEALPix resolution level [0..30] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable rHEALPix compact mode to reduce cell count |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2rhealpix) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
fix_antimeridian
|
str
|
Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of dictionaries representing rHEALPix cells based on predicate |
Example
from shapely.geometry import Polygon poly = Polygon([(-122.5, 37.7), (-122.3, 37.7), (-122.3, 37.9), (-122.5, 37.9)]) cells = polygon2rhealpix(poly, 10, {"name": "area"}, predicate="intersect") len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2rhealpix.py
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 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 379 380 381 382 383 384 | |
polyline2rhealpix(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, fix_antimeridian=None)
¶
Convert a polyline geometry to rHEALPix grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
LineString or MultiLineString
|
Polyline geometry to convert |
required |
resolution
|
int
|
rHEALPix resolution level [0..30] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply (not used for polylines) |
None
|
compact
|
bool
|
Enable rHEALPix compact mode (not used for polylines) |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2rhealpix) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
fix_antimeridian
|
str
|
Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of dictionaries representing rHEALPix cells intersecting the polyline |
Example
from shapely.geometry import LineString line = LineString([(-122.4194, 37.7749), (-122.4000, 37.7800)]) cells = polyline2rhealpix(line, 10, {"name": "route"}) len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2rhealpix.py
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 | |
vector2rhealpix(vector_data, resolution=None, predicate=None, compact=False, topology=False, output_format='gpd', include_properties=True, fix_antimeridian=None, **kwargs)
¶
Convert vector data to rHEALPix grid cells from various input formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector_data
|
str, geopandas.GeoDataFrame, pandas.DataFrame, dict, or list
|
Input vector data |
required |
resolution
|
int
|
rHEALPix resolution level [0..30]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable rHEALPix compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint rHEALPix cells |
False
|
output_format
|
str
|
Output format ('gpd', 'geojson', 'csv', 'shapefile', 'gpkg', 'parquet', 'geoparquet') |
'gpd'
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
fix_antimeridian
|
str
|
Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none |
None
|
**kwargs
|
Additional arguments passed to process_input_data_vector |
{}
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame, dict, or str: Output in the specified format. If output_format is a file-based format, |
|
|
the output will be saved to a file in the current directory with a default name based on the input. |
|
|
Otherwise, returns a Python object (GeoDataFrame, dict, etc.) depending on output_format. |
Example
result = vector2rhealpix("data/points.geojson", resolution=10, output_format="geojson") print(f"Output saved to: {result}")
Source code in vgrid/conversion/vector2dggs/vector2rhealpix.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 | |
vector2rhealpix_cli()
¶
Command-line interface for vector2rhealpix conversion.
This function provides a command-line interface for converting vector data to rHEALPix grid cells. It supports various input formats and output formats, with options for resolution control, spatial predicates, compact mode, and topology preservation.
Usage
python vector2rhealpix.py -i input.geojson -r 10 -f geojson python vector2rhealpix.py -i input.shp -r 8 -p intersect -c -t
Source code in vgrid/conversion/vector2dggs/vector2rhealpix.py
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 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 | |
Vector to ISEA4T Module
This module provides functionality to convert vector geometries to ISEA4T grid cells with flexible input and output formats.
Key Functions
geodataframe2isea4t(gdf, resolution=None, predicate=None, compact=False, topology=False, include_properties=True, fix_antimeridian=None)
¶
Convert a GeoDataFrame to ISEA4T grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
GeoDataFrame to convert |
required |
resolution
|
int
|
ISEA4T resolution level [0..30]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable ISEA4T compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint ISEA4T cells |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
fix_antimeridian
|
str
|
Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none |
None
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame: GeoDataFrame with ISEA4T grid cells |
Example
import geopandas as gpd from shapely.geometry import Point gdf = gpd.GeoDataFrame({ ... 'name': ['San Francisco'], ... 'geometry': [Point(-122.4194, 37.7749)] ... }) result = geodataframe2isea4t(gdf, 10) len(result) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2isea4t.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 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 | |
point2isea4t(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, fix_antimeridian=None)
¶
Convert a point geometry to ISEA4T grid cells.
Converts point or multipoint geometries to ISEA4T grid cells at the specified resolution. Each point is assigned to its containing ISEA4T cell.
Parameters¶
feature : shapely.geometry.Point or shapely.geometry.MultiPoint Point geometry to convert to ISEA4T cells. resolution : int ISEA4T resolution level [0..30]. feature_properties : dict, optional Properties to include in output features. predicate : str, optional Spatial predicate to apply (not used for points). compact : bool, optional Enable ISEA4T compact mode (not used for points). topology : bool, optional Enable topology preserving mode (handled by geodataframe2isea4t). include_properties : bool, optional Whether to include properties in output. fix_antimeridian (str, optional): Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none
Returns¶
list of dict List of dictionaries representing ISEA4T cells containing the point(s). Each dictionary contains ISEA4T cell properties and geometry.
Examples¶
from shapely.geometry import Point point = Point(-122.4194, 37.7749) # San Francisco cells = point2isea4t(point, 10, {"name": "SF"}) len(cells) 1
from shapely.geometry import MultiPoint points = MultiPoint([(-122.4194, 37.7749), (-74.0060, 40.7128)]) cells = point2isea4t(points, 8) len(cells) 2
Source code in vgrid/conversion/vector2dggs/vector2isea4t.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
polygon2isea4t(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, fix_antimeridian=None)
¶
Convert a polygon geometry to ISEA4T grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Polygon or MultiPolygon
|
Polygon geometry to convert |
required |
resolution
|
int
|
ISEA4T resolution level [0..30] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable ISEA4T compact mode to reduce cell count |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2isea4t) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
fix_antimeridian
|
str
|
Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of dictionaries representing ISEA4T cells based on predicate |
Example
from shapely.geometry import Polygon poly = Polygon([(-122.5, 37.7), (-122.3, 37.7), (-122.3, 37.9), (-122.5, 37.9)]) cells = polygon2isea4t(poly, 10, {"name": "area"}, predicate="intersect") len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2isea4t.py
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 | |
polyline2isea4t(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, fix_antimeridian=None)
¶
Convert a polyline geometry to ISEA4T grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
LineString or MultiLineString
|
Polyline geometry to convert |
required |
resolution
|
int
|
ISEA4T resolution level [0..30] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply (not used for polylines) |
None
|
compact
|
bool
|
Enable ISEA4T compact mode (not used for polylines) |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2isea4t) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
fix_antimeridian
|
str
|
Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of dictionaries representing ISEA4T cells intersecting the polyline |
Example
from shapely.geometry import LineString line = LineString([(-122.4194, 37.7749), (-122.4000, 37.7800)]) cells = polyline2isea4t(line, 10, {"name": "route"}) len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2isea4t.py
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 | |
vector2isea4t(vector_data, resolution=None, predicate=None, compact=False, topology=False, output_format='gpd', include_properties=True, fix_antimeridian=None, **kwargs)
¶
Convert vector data to ISEA4T grid cells from various input formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector_data
|
str, geopandas.GeoDataFrame, pandas.DataFrame, dict, or list
|
Input vector data |
required |
resolution
|
int
|
ISEA4T resolution level [0..30]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable ISEA4T compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint ISEA4T cells |
False
|
output_format
|
str
|
Output format ('gpd', 'geojson', 'csv', 'shapefile', 'gpkg', 'parquet', 'geoparquet') |
'gpd'
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
fix_antimeridian
|
str
|
Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none |
None
|
**kwargs
|
Additional arguments passed to process_input_data_vector |
{}
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame, dict, or str: Output in the specified format. If output_format is a file-based format, |
|
|
the output will be saved to a file in the current directory with a default name based on the input. |
|
|
Otherwise, returns a Python object (GeoDataFrame, dict, etc.) depending on output_format. |
Example
result = vector2isea4t("data/points.geojson", resolution=10, output_format="geojson") print(f"Output saved to: {result}")
Source code in vgrid/conversion/vector2dggs/vector2isea4t.py
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 | |
vector2isea4t_cli()
¶
Command-line interface for vector2isea4t conversion.
This function provides a command-line interface for converting vector data to ISEA4T grid cells. It supports various input formats and output formats, with options for resolution control, spatial predicates, compact mode, and topology preservation.
Usage
python vector2isea4t.py -i input.geojson -r 10 -f geojson python vector2isea4t.py -i input.shp -r 8 -p intersect -c -t
Source code in vgrid/conversion/vector2dggs/vector2isea4t.py
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 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 | |
Vector to ISEA3H Module
This module provides functionality to convert vector geometries to ISEA3H grid cells with flexible input and output formats.
Key Functions
geodataframe2isea3h(gdf, resolution=None, predicate=None, compact=False, topology=False, include_properties=True, fix_antimeridian=None)
¶
Convert a GeoDataFrame to ISEA3H grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
GeoDataFrame to convert |
required |
resolution
|
int
|
ISEA3H resolution level [0..32]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable ISEA3H compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint ISEA3H cells |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
fix_antimeridian
|
str
|
Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none |
None
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame: GeoDataFrame with ISEA3H grid cells |
Example
import geopandas as gpd from shapely.geometry import Point gdf = gpd.GeoDataFrame({ ... 'name': ['San Francisco'], ... 'geometry': [Point(-122.4194, 37.7749)] ... }) result = geodataframe2isea3h(gdf, 10) len(result) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2isea3h.py
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 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 | |
point2isea3h(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, fix_antimeridian=None)
¶
Convert a point geometry to ISEA3H grid cells.
Converts point or multipoint geometries to ISEA3H grid cells at the specified resolution. Each point is assigned to its containing ISEA3H cell.
Parameters¶
feature : shapely.geometry.Point or shapely.geometry.MultiPoint Point geometry to convert to ISEA3H cells. resolution : int ISEA3H resolution level [0..32]. feature_properties : dict, optional Properties to include in output features. predicate : str, optional Spatial predicate to apply (not used for points). compact : bool, optional Enable ISEA3H compact mode (not used for points). topology : bool, optional Enable topology preserving mode (handled by geodataframe2isea3h). include_properties : bool, optional Whether to include properties in output. fix_antimeridian : str, optional Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none Defaults to None when omitted.
Returns¶
list of dict List of dictionaries representing ISEA3H cells containing the point(s). Each dictionary contains ISEA3H cell properties and geometry.
Examples¶
from shapely.geometry import Point point = Point(-122.4194, 37.7749) # San Francisco cells = point2isea3h(point, 10, {"name": "SF"}) len(cells) 1
from shapely.geometry import MultiPoint points = MultiPoint([(-122.4194, 37.7749), (-74.0060, 40.7128)]) cells = point2isea3h(points, 8) len(cells) 2
Source code in vgrid/conversion/vector2dggs/vector2isea3h.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
polygon2isea3h(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, fix_antimeridian=None)
¶
Convert a polygon geometry to ISEA3H grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Polygon or MultiPolygon
|
Polygon geometry to convert |
required |
resolution
|
int
|
ISEA3H resolution level [0..32] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable ISEA3H compact mode to reduce cell count |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2isea3h) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
fix_antimeridian
|
str
|
Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of dictionaries representing ISEA3H cells based on predicate |
Example
from shapely.geometry import Polygon poly = Polygon([(-122.5, 37.7), (-122.3, 37.7), (-122.3, 37.9), (-122.5, 37.9)]) cells = polygon2isea3h(poly, 10, {"name": "area"}, predicate="intersect") len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2isea3h.py
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 297 298 299 300 301 302 303 304 | |
polyline2isea3h(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, fix_antimeridian=None)
¶
Convert a polyline geometry to ISEA3H grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
LineString or MultiLineString
|
Polyline geometry to convert |
required |
resolution
|
int
|
ISEA3H resolution level [0..32] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply (not used for polylines) |
None
|
compact
|
bool
|
Enable ISEA3H compact mode (not used for polylines) |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2isea3h) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
fix_antimeridian
|
str
|
Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of dictionaries representing ISEA3H cells intersecting the polyline |
Example
from shapely.geometry import LineString line = LineString([(-122.4194, 37.7749), (-122.4000, 37.7800)]) cells = polyline2isea3h(line, 10, {"name": "route"}) len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2isea3h.py
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 | |
vector2isea3h(vector_data, resolution=None, predicate=None, compact=False, topology=False, output_format='gpd', include_properties=True, fix_antimeridian=None, **kwargs)
¶
Convert vector data to ISEA3H grid cells from various input formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector_data
|
str, geopandas.GeoDataFrame, pandas.DataFrame, dict, or list
|
Input vector data |
required |
resolution
|
int
|
ISEA3H resolution level [0..32]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable ISEA3H compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint ISEA3H cells |
False
|
output_format
|
str
|
Output format ('gpd', 'geojson', 'csv', 'shapefile', 'gpkg', 'parquet', 'geoparquet') |
'gpd'
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
fix_antimeridian
|
str
|
Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none |
None
|
**kwargs
|
Additional arguments passed to process_input_data_vector |
{}
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame, dict, or str: Output in the specified format. If output_format is a file-based format, |
|
|
the output will be saved to a file in the current directory with a default name based on the input. |
|
|
Otherwise, returns a Python object (GeoDataFrame, dict, etc.) depending on output_format. |
Example
result = vector2isea3h("data/points.geojson", resolution=10, output_format="geojson") print(f"Output saved to: {result}")
Source code in vgrid/conversion/vector2dggs/vector2isea3h.py
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 | |
vector2isea3h_cli()
¶
Command-line interface for vector2isea3h conversion.
This function provides a command-line interface for converting vector data to ISEA3H grid cells. It supports various input formats and output formats, with options for resolution control, spatial predicates, compact mode, and topology preservation.
Usage
python vector2isea3h.py -i input.geojson -r 10 -f geojson python vector2isea3h.py -i input.shp -r 8 -p intersect -c -t
Source code in vgrid/conversion/vector2dggs/vector2isea3h.py
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 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 | |
Vector to EASE Module
This module provides functionality to convert vector geometries to EASE grid cells with flexible input and output formats.
Key Functions
geodataframe2ease(gdf, resolution=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a GeoDataFrame to EASE grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
GeoDataFrame to convert |
required |
resolution
|
int
|
EASE resolution level [0..6]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable EASE compact mode for polygons and lines |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint EASE cells |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame: GeoDataFrame with EASE grid cells |
Source code in vgrid/conversion/vector2dggs/vector2ease.py
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 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 | |
point2ease(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a point geometry to EASE grid cells.
Converts point or multipoint geometries to EASE grid cells at the specified resolution. Each point is assigned to its containing EASE cell.
Parameters¶
feature : shapely.geometry.Point or shapely.geometry.MultiPoint Point geometry to convert to EASE cells. resolution : int EASE resolution level [0..6]. feature_properties : dict, optional Properties to include in output features. predicate : str, optional Spatial predicate to apply (not used for points). compact : bool, optional Enable EASE compact mode (not used for points). topology : bool, optional Enable topology preserving mode (handled by geodataframe2ease). include_properties : bool, optional Whether to include properties in output.
Returns¶
list of dict List of dictionaries representing EASE cells containing the point(s). Each dictionary contains EASE cell properties and geometry.
Examples¶
from shapely.geometry import Point point = Point(-122.4194, 37.7749) # San Francisco cells = point2ease(point, 4, {"name": "SF"}) len(cells) 1
from shapely.geometry import MultiPoint points = MultiPoint([(-122.4194, 37.7749), (-74.0060, 40.7128)]) cells = point2ease(points, 3) len(cells) 2
Source code in vgrid/conversion/vector2dggs/vector2ease.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
polygon2ease(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert polygon geometries (Polygon, MultiPolygon) to EASE grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Polygon or MultiPolygon
|
Polygon geometry to convert |
required |
resolution
|
int
|
EASE resolution level [0..6] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable EASE compact mode to reduce cell count |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2ease) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of GeoJSON feature dictionaries representing EASE cells based on predicate |
Source code in vgrid/conversion/vector2dggs/vector2ease.py
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 | |
polyline2ease(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert line geometries (LineString, MultiLineString) to EASE grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
LineString or MultiLineString
|
Line geometry to convert |
required |
resolution
|
int
|
EASE resolution level [0..6] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply (not used for lines) |
None
|
compact
|
bool
|
Enable EASE compact mode to reduce cell count |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2ease) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of GeoJSON feature dictionaries representing EASE cells intersecting the line |
Source code in vgrid/conversion/vector2dggs/vector2ease.py
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 | |
vector2ease(vector_data, resolution=None, predicate=None, compact=False, topology=False, output_format='gpd', include_properties=True, **kwargs)
¶
Convert vector data to EASE grid cells from various input formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector_data
|
str, geopandas.GeoDataFrame, pandas.DataFrame, dict, or list
|
Input vector data |
required |
resolution
|
int
|
EASE resolution level [0..6]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable EASE compact mode for polygons and lines |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint EASE cells |
False
|
output_format
|
str
|
Output format ('gpd', 'geojson', 'csv', 'shapefile', 'gpkg', 'parquet', 'geoparquet') |
'gpd'
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
**kwargs
|
Additional arguments passed to process_input_data_vector |
{}
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame, dict, or str: Output in the specified format. If output_format is a file-based format, |
|
|
the output will be saved to a file in the current directory with a default name based on the input. |
|
|
Otherwise, returns a Python object (GeoDataFrame, dict, etc.) depending on output_format. |
Source code in vgrid/conversion/vector2dggs/vector2ease.py
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 | |
vector2ease_cli()
¶
Command-line interface for vector2ease conversion.
Source code in vgrid/conversion/vector2dggs/vector2ease.py
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 | |
Vector to DGGAL Module
This module provides functionality to convert vector geometries to DGGAL grid cells with flexible input and output formats.
Key Functions
geodataframe2dggal(dggs_type, gdf, resolution, predicate=None, compact=False, topology=False, include_properties=True, split_antimeridian=False)
¶
Convert a GeoDataFrame to DGGAL grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
GeoDataFrame to convert |
required |
dggs_type
|
str
|
One of DGGAL_TYPES |
required |
resolution
|
int
|
Integer resolution |
required |
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable DGGAL compact mode for polygons and lines |
False
|
topology
|
bool
|
Enable topology preserving mode (not yet implemented for DGGAL) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
split_antimeridian
|
bool
|
When True, apply antimeridian fixing to the resulting polygons. |
False
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame: GeoDataFrame with DGGAL grid cells |
Example
import geopandas as gpd from shapely.geometry import Point gdf = gpd.GeoDataFrame({ ... 'name': ['San Francisco'], ... 'geometry': [Point(-122.4194, 37.7749)] ... }) result = geodataframe2dggal("isea3h", gdf, 10) len(result) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2dggal.py
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 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 | |
point2dggal(dggs_type, feature=None, resolution=None, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True, split_antimeridian=False)
¶
Convert a point geometry to DGGAL grid cells.
Converts point or multipoint geometries to DGGAL grid cells at the specified resolution. Each point is assigned to its containing DGGAL cell.
Parameters¶
dggs_type : str DGGAL DGGS type (e.g., "isea3h", "isea4t", "isea7h", "isea9h"). feature : shapely.geometry.Point or shapely.geometry.MultiPoint Point geometry to convert to DGGAL cells. resolution : int DGGAL resolution level. feature_properties : dict, optional Properties to include in output features. predicate : str, optional Spatial predicate to apply (not used for points). compact : bool, optional Enable DGGAL compact mode (not used for points). topology : bool, optional Enable topology preserving mode. include_properties : bool, optional Whether to include properties in output. split_antimeridian : bool, optional When True, apply antimeridian fixing to the resulting polygons. Defaults to False when None or omitted.
Returns¶
list of dict List of dictionaries representing DGGAL cells containing the point(s). Each dictionary contains DGGAL cell properties and geometry.
Examples¶
from shapely.geometry import Point point = Point(-122.4194, 37.7749) # San Francisco cells = point2dggal("isea3h", point, 10, {"name": "SF"}) len(cells) 1
from shapely.geometry import MultiPoint points = MultiPoint([(-122.4194, 37.7749), (-74.0060, 40.7128)]) cells = point2dggal("isea4t", points, 8) len(cells) 2
Source code in vgrid/conversion/vector2dggs/vector2dggal.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 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 | |
vector2dggal(dggs_type, vector_data, resolution, predicate=None, compact=False, topology=False, include_properties=True, output_format='gpd', split_antimeridian=False, **kwargs)
¶
Convert vector data to DGGAL grid cells for a given type and resolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dggs_type
|
str
|
One of DGGAL_TYPES |
required |
vector_data
|
str, geopandas.GeoDataFrame, pandas.DataFrame, dict, or list
|
Input vector data |
required |
resolution
|
int
|
Integer resolution |
required |
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable DGGAL compact mode for polygons and lines |
False
|
topology
|
bool
|
Enable topology preserving mode (not yet implemented for DGGAL) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
output_format
|
str
|
Output format ('gpd', 'geojson', 'csv', 'shapefile', 'gpkg', 'parquet', 'geoparquet') |
'gpd'
|
split_antimeridian
|
bool
|
When True, apply antimeridian fixing to the resulting polygons. |
False
|
**kwargs
|
Additional arguments passed to process_input_data_vector |
{}
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame, dict, or str: Output in the specified format. If output_format is a file-based format, |
|
|
the output will be saved to a file in the current directory with a default name based on the input. |
|
|
Otherwise, returns a Python object (GeoDataFrame, dict, etc.) depending on output_format. |
Example
result = vector2dggal("isea3h", "data/points.geojson", resolution=10, output_format="geojson") print(f"Output saved to: {result}")
Source code in vgrid/conversion/vector2dggs/vector2dggal.py
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 | |
Vector to DGGRID Module
This module provides functionality to convert vector geometries to DGGRID grid cells with flexible input and output formats.
Key Functions
geodataframe2dggrid(dggrid_instance, dggs_type, gdf, resolution=None, predicate=None, compact=False, topology=False, include_properties=True, output_address_type='SEQNUM', split_antimeridian=False, aggregate=False)
¶
Convert a GeoDataFrame to DGGRID grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dggrid_instance
|
DGGRIDv7 instance for grid operations |
required | |
gdf
|
GeoDataFrame
|
GeoDataFrame to convert |
required |
dggs_type
|
str
|
One of DGGRID_TYPES |
required |
resolution
|
int
|
Integer resolution |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable compact mode for polygons and lines |
False
|
topology
|
bool
|
Enable topology preserving mode |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
output_address_type
|
str
|
Output address type (SEQNUM, Q2DI, Q2DD, etc.) |
'SEQNUM'
|
split_antimeridian
|
bool
|
When True, apply antimeridian fixing to the resulting polygons. |
False
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame: GeoDataFrame with DGGRID grid cells |
Source code in vgrid/conversion/vector2dggs/vector2dggrid.py
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 451 452 453 454 | |
point2dggrid(dggrid_instance, dggs_type, feature, resolution, predicate=None, compact=False, topology=False, include_properties=True, feature_properties=None, output_address_type='SEQNUM', split_antimeridian=False, aggregate=False)
¶
Convert a point geometry to DGGRID grid cells.
Converts point or multipoint geometries to DGGRID grid cells at the specified resolution. Each point is assigned to its containing DGGRID cell.
Parameters¶
dggrid_instance : object DGGRID instance for grid operations. dggs_type : str DGGRID DGGS type (e.g., "isea4h", "fuller"). feature : shapely.geometry.Point or shapely.geometry.MultiPoint Point geometry to convert to DGGRID cells. resolution : int DGGRID resolution level. predicate : str, optional Spatial predicate to apply (not used for points). compact : bool, optional Enable DGGRID compact mode (not used for points). topology : bool, optional Enable topology preserving mode. include_properties : bool, optional Whether to include properties in output. feature_properties : dict, optional Properties to include in output features. output_address_type : str, optional Output address type (e.g., "SEQNUM", "Q2DI", "Q2DD"). Defaults to "SEQNUM". split_antimeridian : bool, optional When True, apply antimeridian fixing to the resulting polygons. Defaults to False when None or omitted.
Returns¶
geopandas.GeoDataFrame GeoDataFrame containing DGGRID cells with the point(s).
Examples¶
from shapely.geometry import Point point = Point(-122.4194, 37.7749) # San Francisco gdf = point2dggrid(dggrid_instance, "isea4h", point, 10) len(gdf) 1
from shapely.geometry import MultiPoint points = MultiPoint([(-122.4194, 37.7749), (-74.0060, 40.7128)]) gdf = point2dggrid(dggrid_instance, "fuller", points, 8) len(gdf) 2
Source code in vgrid/conversion/vector2dggs/vector2dggrid.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
polygon2dggrid(dggrid_instance, dggs_type, feature, resolution, predicate=None, compact=False, topology=False, include_properties=True, feature_properties=None, output_address_type='SEQNUM', split_antimeridian=False, aggregate=False)
¶
Generate DGGRID cells intersecting with a given polygon or multipolygon geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dggrid_instance
|
DGGRIDv7 instance for grid operations. |
required | |
dggs_type
|
str
|
Type of DGGS (e.g., ISEA4H, FULLER, etc.). |
required |
res
|
int
|
Resolution for the DGGRID. |
required |
address_type
|
str
|
Address type for the output grid cells. |
required |
geometry
|
Polygon or MultiPolygon
|
Input geometry. |
required |
split_antimeridian
|
bool
|
When True, apply antimeridian fixing to the resulting polygons. |
False
|
Source code in vgrid/conversion/vector2dggs/vector2dggrid.py
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 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 | |
polyline2dggrid(dggrid_instance, dggs_type, feature, resolution, predicate=None, compact=False, topology=False, include_properties=True, feature_properties=None, output_address_type='SEQNUM ', split_antimeridian=False, aggregate=False)
¶
Generate DGGRID cells intersecting with a LineString or MultiLineString geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dggrid_instance
|
DGGRIDv7 instance for grid operations. |
required | |
dggs_type
|
str
|
Type of DGGS (e.g., ISEA4H, FULLER, etc.). |
required |
res
|
int
|
Resolution for the DGGRID. |
required |
address_type
|
str
|
Address type for the output grid cells. |
required |
geometry
|
LineString or MultiLineString
|
Input geometry. |
required |
split_antimeridian
|
bool
|
When True, apply antimeridian fixing to the resulting polygons. |
False
|
Source code in vgrid/conversion/vector2dggs/vector2dggrid.py
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 | |
vector2dggrid(dggrid_instance, dggs_type, vector_data, resolution=None, predicate=None, compact=False, topology=False, include_properties=True, output_address_type='SEQNUM', output_format='gpd', split_antimeridian=False, aggregate=False, **kwargs)
¶
Convert vector data to DGGRID grid cells from various input formats. If output_format is a file-based format (csv, geojson, shapefile, gpkg, parquet, geoparquet), the output will be saved to a file in the current directory with a default name based on the input. Otherwise, returns a Python object (GeoDataFrame, dict, etc.) depending on output_format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Input data (file path, URL, GeoDataFrame, GeoJSON, etc.) |
required | |
dggrid_instance
|
DGGRIDv7 instance for grid operations. |
required | |
dggs_type
|
DGGS type (e.g., ISEA4H, FULLER, etc.) |
required | |
resolution
|
Resolution for the DGGRID |
None
|
|
address_type
|
Output address type (default: SEQNUM) |
required | |
output_format
|
Output format (gpd, geojson, csv, etc.) |
'gpd'
|
|
include_properties
|
Whether to include original feature properties |
True
|
|
split_antimeridian
|
When True, apply antimeridian fixing to the resulting polygons. |
False
|
|
**kwargs
|
Additional arguments passed to process_input_data_vector |
{}
|
Returns:
| Type | Description |
|---|---|
|
GeoDataFrame or file path depending on output_format |
Source code in vgrid/conversion/vector2dggs/vector2dggrid.py
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 518 | |
Vector to QTM Module
This module provides functionality to convert vector geometries to QTM grid cells with flexible input and output formats.
Key Functions
geodataframe2qtm(gdf, resolution=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a GeoDataFrame to QTM grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
GeoDataFrame to convert |
required |
resolution
|
int
|
QTM resolution [1..24]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable QTM compact mode for polygons and lines |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint QTM cells |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame: GeoDataFrame with QTM grid cells |
Source code in vgrid/conversion/vector2dggs/vector2qtm.py
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 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 | |
point2qtm(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a point geometry to QTM grid cells.
Converts point or multipoint geometries to QTM grid cells at the specified resolution. Each point is assigned to its containing QTM cell.
Parameters¶
feature : shapely.geometry.Point or shapely.geometry.MultiPoint Point geometry to convert to QTM cells. resolution : int QTM resolution level [1..24]. feature_properties : dict, optional Properties to include in output features. predicate : str, optional Spatial predicate to apply (not used for points). compact : bool, optional Enable QTM compact mode (not used for points). topology : bool, optional Enable topology preserving mode (handled by geodataframe2qtm). include_properties : bool, optional Whether to include properties in output.
Returns¶
list of dict List of dictionaries representing QTM cells containing the point(s). Each dictionary contains QTM cell properties and geometry.
Examples¶
from shapely.geometry import Point point = Point(-122.4194, 37.7749) # San Francisco cells = point2qtm(point, 10, {"name": "SF"}) len(cells) 1
from shapely.geometry import MultiPoint points = MultiPoint([(-122.4194, 37.7749), (-74.0060, 40.7128)]) cells = point2qtm(points, 8) len(cells) 2
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of GeoJSON feature dictionaries representing QTM cells containing the point |
Source code in vgrid/conversion/vector2dggs/vector2qtm.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
polygon2qtm(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert polygon geometries (Polygon, MultiPolygon) to QTM grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Polygon or MultiPolygon
|
Polygon geometry to convert |
required |
resolution
|
int
|
QTM resolution [1..24] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable QTM compact mode to reduce cell count |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2qtm) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of GeoJSON feature dictionaries representing QTM cells based on predicate |
Source code in vgrid/conversion/vector2dggs/vector2qtm.py
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 304 305 306 307 308 309 | |
polyline2qtm(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert line geometries (LineString, MultiLineString) to QTM grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
LineString or MultiLineString
|
Line geometry to convert |
required |
resolution
|
int
|
QTM resolution [1..24] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply (not used for lines) |
None
|
compact
|
bool
|
Enable QTM compact mode to reduce cell count |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2qtm) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of GeoJSON feature dictionaries representing QTM cells intersecting the line |
Source code in vgrid/conversion/vector2dggs/vector2qtm.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 | |
vector2qtm(vector_data, resolution=None, predicate=None, compact=False, topology=False, output_format='gpd', include_properties=True, **kwargs)
¶
Convert vector data to QTM grid cells from various input formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector_data
|
str, geopandas.GeoDataFrame, pandas.DataFrame, dict, or list
|
Input vector data |
required |
resolution
|
int
|
QTM resolution [1..24]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable QTM compact mode for polygons and lines |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint QTM cells |
False
|
output_format
|
str
|
Output format ('gpd', 'geojson', 'csv', 'shapefile', 'gpkg', 'parquet', 'geoparquet') |
'gpd'
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
**kwargs
|
Additional arguments passed to process_input_data_vector |
{}
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame, dict, or str: Output in the specified format. If output_format is a file-based format, |
|
|
the output will be saved to a file in the current directory with a default name based on the input. |
|
|
Otherwise, returns a Python object (GeoDataFrame, dict, etc.) depending on output_format. |
Source code in vgrid/conversion/vector2dggs/vector2qtm.py
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 | |
vector2qtm_cli()
¶
Command-line interface for vector2qtm conversion.
Source code in vgrid/conversion/vector2dggs/vector2qtm.py
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 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 | |
Vector to OLC Module
This module provides functionality to convert vector geometries to OLC grid cells with flexible input and output formats.
Key Functions
geodataframe2olc(gdf, resolution=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a GeoDataFrame to OLC grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
GeoDataFrame to convert |
required |
resolution
|
int
|
OLC resolution level [2,4,6,8,10,11,12,13,14,15]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable OLC compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint OLC cells |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame: GeoDataFrame with OLC grid cells |
Example
import geopandas as gpd from shapely.geometry import Point gdf = gpd.GeoDataFrame({ ... 'name': ['San Francisco'], ... 'geometry': [Point(-122.4194, 37.7749)] ... }) result = geodataframe2olc(gdf, 10) len(result) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2olc.py
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 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 | |
point2olc(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a point geometry to OLC grid cells.
Converts point or multipoint geometries to OLC grid cells at the specified resolution. Each point is assigned to its containing OLC cell.
Parameters¶
feature : shapely.geometry.Point or shapely.geometry.MultiPoint Point geometry to convert to OLC cells. resolution : int OLC resolution level [2,4,6,8,10,11,12,13,14,15]. feature_properties : dict, optional Properties to include in output features. predicate : str, optional Spatial predicate to apply (not used for points). compact : bool, optional Enable OLC compact mode (not used for points). topology : bool, optional Enable topology preserving mode (handled by geodataframe2olc). include_properties : bool, optional Whether to include properties in output.
Returns¶
list of dict List of dictionaries representing OLC cells containing the point(s). Each dictionary contains OLC cell properties and geometry.
Examples¶
from shapely.geometry import Point point = Point(-122.4194, 37.7749) # San Francisco cells = point2olc(point, 10, {"name": "SF"}) len(cells) 1
from shapely.geometry import MultiPoint points = MultiPoint([(-122.4194, 37.7749), (-74.0060, 40.7128)]) cells = point2olc(points, 8) len(cells) 2
Source code in vgrid/conversion/vector2dggs/vector2olc.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
polygon2olc(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a polygon geometry to OLC grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Polygon or MultiPolygon
|
Polygon geometry to convert |
required |
resolution
|
int
|
OLC resolution level [2,4,6,8,10,11,12,13,14,15] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable OLC compact mode to reduce cell count |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2olc) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of dictionaries representing OLC cells based on predicate |
Example
from shapely.geometry import Polygon poly = Polygon([(-122.5, 37.7), (-122.3, 37.7), (-122.3, 37.9), (-122.5, 37.9)]) cells = polygon2olc(poly, 10, {"name": "area"}, predicate="intersect") len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2olc.py
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 297 298 299 300 301 302 303 304 305 306 307 308 | |
polyline2olc(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a polyline geometry to OLC grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
LineString or MultiLineString
|
Polyline geometry to convert |
required |
resolution
|
int
|
OLC resolution level [2,4,6,8,10,11,12,13,14,15] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply (not used for polylines) |
None
|
compact
|
bool
|
Enable OLC compact mode (not used for polylines) |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2olc) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of dictionaries representing OLC cells intersecting the polyline |
Example
from shapely.geometry import LineString line = LineString([(-122.4194, 37.7749), (-122.4000, 37.7800)]) cells = polyline2olc(line, 10, {"name": "route"}) len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2olc.py
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 | |
vector2olc(vector_data, resolution=None, predicate=None, compact=False, topology=False, output_format='gpd', include_properties=True, **kwargs)
¶
Convert vector data to OLC grid cells from various input formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector_data
|
str, geopandas.GeoDataFrame, pandas.DataFrame, dict, or list
|
Input vector data |
required |
resolution
|
int
|
OLC resolution level [2,4,6,8,10,11,12,13,14,15]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable OLC compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint OLC cells |
False
|
output_format
|
str
|
Output format ('gpd', 'geojson', 'csv', 'shapefile', 'gpkg', 'parquet', 'geoparquet') |
'gpd'
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
**kwargs
|
Additional arguments passed to process_input_data_vector |
{}
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame, dict, or str: Output in the specified format. If output_format is a file-based format, |
|
|
the output will be saved to a file in the current directory with a default name based on the input. |
|
|
Otherwise, returns a Python object (GeoDataFrame, dict, etc.) depending on output_format. |
Example
result = vector2olc("data/points.geojson", resolution=10, output_format="geojson") print(f"Output saved to: {result}")
Source code in vgrid/conversion/vector2dggs/vector2olc.py
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 | |
vector2olc_cli()
¶
Command-line interface for vector2olc conversion.
This function provides a command-line interface for converting vector data to OLC grid cells. It supports various input formats and output formats, with options for resolution control, spatial predicates, compact mode, and topology preservation.
Usage
python vector2olc.py -i input.geojson -r 10 -f geojson python vector2olc.py -i input.shp -r 8 -p intersect -c -t
Source code in vgrid/conversion/vector2dggs/vector2olc.py
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 565 566 567 568 569 570 | |
Vector to Geohash Module
This module provides functionality to convert vector geometries to Geohash grid cells with flexible input and output formats.
Key Functions
geodataframe2geohash(gdf, resolution=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a GeoDataFrame to Geohash grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
GeoDataFrame to convert |
required |
resolution
|
int
|
Geohash resolution level [1..10]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable Geohash compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint Geohash cells |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame: GeoDataFrame with Geohash grid cells |
Example
import geopandas as gpd from shapely.geometry import Point gdf = gpd.GeoDataFrame({ ... 'name': ['San Francisco'], ... 'geometry': [Point(-122.4194, 37.7749)] ... }) result = geodataframe2geohash(gdf, 6) len(result) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2geohash.py
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 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 379 380 | |
point2geohash(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a point geometry to Geohash grid cells.
Converts point or multipoint geometries to Geohash grid cells at the specified resolution. Each point is assigned to its containing Geohash cell.
Parameters¶
feature : shapely.geometry.Point or shapely.geometry.MultiPoint Point geometry to convert to Geohash cells. resolution : int Geohash resolution level [1..10]. feature_properties : dict, optional Properties to include in output features. predicate : str, optional Spatial predicate to apply (not used for points). compact : bool, optional Enable Geohash compact mode (not used for points). topology : bool, optional Enable topology preserving mode (handled by geodataframe2geohash). include_properties : bool, optional Whether to include properties in output.
Returns¶
list of dict List of dictionaries representing Geohash cells containing the point(s). Each dictionary contains Geohash cell properties and geometry.
Examples¶
from shapely.geometry import Point point = Point(-122.4194, 37.7749) # San Francisco cells = point2geohash(point, 6, {"name": "SF"}) len(cells) 1
from shapely.geometry import MultiPoint points = MultiPoint([(-122.4194, 37.7749), (-74.0060, 40.7128)]) cells = point2geohash(points, 5) len(cells) 2
Source code in vgrid/conversion/vector2dggs/vector2geohash.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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
polygon2geohash(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a polygon geometry to Geohash grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Polygon or MultiPolygon
|
Polygon geometry to convert |
required |
resolution
|
int
|
Geohash resolution level [1..10] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable Geohash compact mode to reduce cell count |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2geohash) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of dictionaries representing Geohash cells based on predicate |
Example
from shapely.geometry import Polygon poly = Polygon([(-122.5, 37.7), (-122.3, 37.7), (-122.3, 37.9), (-122.5, 37.9)]) cells = polygon2geohash(poly, 6, {"name": "area"}, predicate="intersect") len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2geohash.py
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 | |
polyline2geohash(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a polyline geometry to Geohash grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
LineString or MultiLineString
|
Polyline geometry to convert |
required |
resolution
|
int
|
Geohash resolution level [1..10] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply (not used for polylines) |
None
|
compact
|
bool
|
Enable Geohash compact mode (not used for polylines) |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2geohash) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of dictionaries representing Geohash cells intersecting the polyline |
Example
from shapely.geometry import LineString line = LineString([(-122.4194, 37.7749), (-122.4000, 37.7800)]) cells = polyline2geohash(line, 6, {"name": "route"}) len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2geohash.py
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 | |
vector2geohash(vector_data, resolution=None, predicate=None, compact=False, topology=False, output_format='gpd', include_properties=True, **kwargs)
¶
Convert vector data to Geohash grid cells from various input formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector_data
|
str, geopandas.GeoDataFrame, pandas.DataFrame, dict, or list
|
Input vector data |
required |
resolution
|
int
|
Geohash resolution level [1..10]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable Geohash compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint Geohash cells |
False
|
output_format
|
str
|
Output format ('gpd', 'geojson', 'csv', 'shapefile', 'gpkg', 'parquet', 'geoparquet') |
'gpd'
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
**kwargs
|
Additional arguments passed to process_input_data_vector |
{}
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame, dict, or str: Output in the specified format. If output_format is a file-based format, |
|
|
the output will be saved to a file in the current directory with a default name based on the input. |
|
|
Otherwise, returns a Python object (GeoDataFrame, dict, etc.) depending on output_format. |
Example
result = vector2geohash("data/points.geojson", resolution=6, output_format="geojson") print(f"Output saved to: {result}")
Source code in vgrid/conversion/vector2dggs/vector2geohash.py
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 | |
vector2geohash_cli()
¶
Command-line interface for vector2geohash conversion.
This function provides a command-line interface for converting vector data to Geohash grid cells. It supports various input formats and output formats, with options for resolution control, spatial predicates, compact mode, and topology preservation.
Usage
python vector2geohash.py -i input.geojson -r 6 -f geojson python vector2geohash.py -i input.shp -r 5 -p intersect -c -t
Source code in vgrid/conversion/vector2dggs/vector2geohash.py
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 | |
Vector to Tilecode Module
This module provides functionality to convert vector geometries to Tilecode grid cells with flexible input and output formats. Tilecodes are hierarchical spatial identifiers in the format 'z{x}x{y}y{z}' where z is the zoom level and x,y are tile coordinates.
Key Functions
geodataframe2tilecode(gdf, resolution=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a GeoDataFrame to Tilecode grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
GeoDataFrame to convert |
required |
resolution
|
int
|
Tilecode resolution level [0..29]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable Tilecode compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint Tilecode cells |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame: GeoDataFrame with Tilecode grid cells |
Example
import geopandas as gpd from shapely.geometry import Point gdf = gpd.GeoDataFrame({ ... 'name': ['San Francisco'], ... 'geometry': [Point(-122.4194, 37.7749)] ... }) result = geodataframe2tilecode(gdf, 10) len(result) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2tilecode.py
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 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 | |
point2tilecode(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a point geometry to Tilecode grid cells.
Converts point or multipoint geometries to Tilecode grid cells at the specified resolution. Each point is assigned to its containing Tilecode cell.
Parameters¶
feature : shapely.geometry.Point or shapely.geometry.MultiPoint Point geometry to convert to Tilecode cells. resolution : int Tilecode resolution level [0..29]. feature_properties : dict, optional Properties to include in output features. predicate : str, optional Spatial predicate to apply (not used for points). compact : bool, optional Enable Tilecode compact mode (not used for points). topology : bool, optional Enable topology preserving mode (handled by geodataframe2tilecode). include_properties : bool, optional Whether to include properties in output.
Returns¶
list of dict List of dictionaries representing Tilecode cells containing the point(s). Each dictionary contains Tilecode cell properties and geometry.
Examples¶
from shapely.geometry import Point point = Point(-122.4194, 37.7749) # San Francisco cells = point2tilecode(point, 10, {"name": "SF"}) len(cells) 1
from shapely.geometry import MultiPoint points = MultiPoint([(-122.4194, 37.7749), (-74.0060, 40.7128)]) cells = point2tilecode(points, 8) len(cells) 2
Source code in vgrid/conversion/vector2dggs/vector2tilecode.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
polygon2tilecode(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a polygon geometry to Tilecode grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Polygon or MultiPolygon
|
Polygon geometry to convert |
required |
resolution
|
int
|
Tilecode resolution level [0..29] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable Tilecode compact mode to reduce cell count |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2tilecode) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of dictionaries representing Tilecode cells based on predicate |
Example
from shapely.geometry import Polygon poly = Polygon([(-122.5, 37.7), (-122.3, 37.7), (-122.3, 37.9), (-122.5, 37.9)]) cells = polygon2tilecode(poly, 10, {"name": "area"}, predicate="intersect") len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2tilecode.py
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 297 298 299 300 | |
polyline2tilecode(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a polyline geometry to Tilecode grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
LineString or MultiLineString
|
Polyline geometry to convert |
required |
resolution
|
int
|
Tilecode resolution level [0..29] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply (not used for polylines) |
None
|
compact
|
bool
|
Enable Tilecode compact mode (not used for polylines) |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2tilecode) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of dictionaries representing Tilecode cells intersecting the polyline |
Example
from shapely.geometry import LineString line = LineString([(-122.4194, 37.7749), (-122.4000, 37.7800)]) cells = polyline2tilecode(line, 10, {"name": "route"}) len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2tilecode.py
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 | |
vector2tilecode(vector_data, resolution=None, predicate=None, compact=False, topology=False, output_format='gpd', include_properties=True, **kwargs)
¶
Convert vector data to Tilecode grid cells from various input formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector_data
|
str, geopandas.GeoDataFrame, pandas.DataFrame, dict, or list
|
Input vector data |
required |
resolution
|
int
|
Tilecode resolution level [0..29]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable Tilecode compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint Tilecode cells |
False
|
output_format
|
str
|
Output format ('gpd', 'geojson', 'csv', 'shapefile', 'gpkg', 'parquet', 'geoparquet') |
'gpd'
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
**kwargs
|
Additional arguments passed to process_input_data_vector |
{}
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame, dict, or str: Output in the specified format. If output_format is a file-based format, |
|
|
the output will be saved to a file in the current directory with a default name based on the input. |
|
|
Otherwise, returns a Python object (GeoDataFrame, dict, etc.) depending on output_format. |
Example
result = vector2tilecode("data/points.geojson", resolution=10, output_format="geojson") print(f"Output saved to: {result}")
Source code in vgrid/conversion/vector2dggs/vector2tilecode.py
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 | |
vector2tilecode_cli()
¶
Command-line interface for vector2tilecode conversion.
This function provides a command-line interface for converting vector data to Tilecode grid cells. It supports various input formats and output formats, with options for resolution control, spatial predicates, compact mode, and topology preservation.
Usage
python vector2tilecode.py -i input.geojson -r 10 -f geojson python vector2tilecode.py -i input.shp -r 8 -p intersect -c -t
Source code in vgrid/conversion/vector2dggs/vector2tilecode.py
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 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 | |
Vector to Quadkey Module
This module provides functionality to convert vector geometries to Quadkey grid cells with flexible input and output formats.
Key Functions
geodataframe2quadkey(gdf, resolution=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a GeoDataFrame to Quadkey grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
GeoDataFrame to convert |
required |
resolution
|
int
|
Quadkey resolution level [0..29]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable Quadkey compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint Quadkey cells |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame: GeoDataFrame with Quadkey grid cells |
Example
import geopandas as gpd from shapely.geometry import Point gdf = gpd.GeoDataFrame({ ... 'name': ['San Francisco'], ... 'geometry': [Point(-122.4194, 37.7749)] ... }) result = geodataframe2quadkey(gdf, 10) len(result) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2quadkey.py
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 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 | |
point2quadkey(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a point geometry to Quadkey grid cells.
Converts point or multipoint geometries to Quadkey grid cells at the specified resolution. Each point is assigned to its containing Quadkey cell.
Parameters¶
feature : shapely.geometry.Point or shapely.geometry.MultiPoint Point geometry to convert to Quadkey cells. resolution : int Quadkey resolution level [0..29]. feature_properties : dict, optional Properties to include in output features. predicate : str, optional Spatial predicate to apply (not used for points). compact : bool, optional Enable Quadkey compact mode (not used for points). topology : bool, optional Enable topology preserving mode (handled by geodataframe2quadkey). include_properties : bool, optional Whether to include properties in output.
Returns¶
list of dict List of dictionaries representing Quadkey cells containing the point(s). Each dictionary contains Quadkey cell properties and geometry.
Examples¶
from shapely.geometry import Point point = Point(-122.4194, 37.7749) # San Francisco cells = point2quadkey(point, 10, {"name": "SF"}) len(cells) 1
from shapely.geometry import MultiPoint points = MultiPoint([(-122.4194, 37.7749), (-74.0060, 40.7128)]) cells = point2quadkey(points, 8) len(cells) 2
Source code in vgrid/conversion/vector2dggs/vector2quadkey.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 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 | |
polygon2quadkey(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a polygon geometry to Quadkey grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Polygon or MultiPolygon
|
Polygon geometry to convert |
required |
resolution
|
int
|
Quadkey resolution level [0..29] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable Quadkey compact mode to reduce cell count |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2quadkey) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of dictionaries representing Quadkey cells based on predicate |
Example
from shapely.geometry import Polygon poly = Polygon([(-122.5, 37.7), (-122.3, 37.7), (-122.3, 37.9), (-122.5, 37.9)]) cells = polygon2quadkey(poly, 10, {"name": "area"}, predicate="intersect") len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2quadkey.py
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 | |
polyline2quadkey(feature, resolution, feature_properties=None, predicate=None, compact=False, topology=False, include_properties=True)
¶
Convert a polyline geometry to Quadkey grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
LineString or MultiLineString
|
Polyline geometry to convert |
required |
resolution
|
int
|
Quadkey resolution level [0..29] |
required |
feature_properties
|
dict
|
Properties to include in output features |
None
|
predicate
|
str
|
Spatial predicate to apply (not used for polylines) |
None
|
compact
|
bool
|
Enable Quadkey compact mode (not used for polylines) |
False
|
topology
|
bool
|
Enable topology preserving mode (handled by geodataframe2quadkey) |
False
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of dictionaries representing Quadkey cells intersecting the polyline |
Example
from shapely.geometry import LineString line = LineString([(-122.4194, 37.7749), (-122.4000, 37.7800)]) cells = polyline2quadkey(line, 10, {"name": "route"}) len(cells) > 0 True
Source code in vgrid/conversion/vector2dggs/vector2quadkey.py
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 | |
vector2quadkey(vector_data, resolution=None, predicate=None, compact=False, topology=False, output_format='gpd', include_properties=True, **kwargs)
¶
Convert vector data to Quadkey grid cells from various input formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector_data
|
str, geopandas.GeoDataFrame, pandas.DataFrame, dict, or list
|
Input vector data |
required |
resolution
|
int
|
Quadkey resolution level [0..29]. Required when topology=False, auto-calculated when topology=True |
None
|
predicate
|
str
|
Spatial predicate to apply for polygons ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
compact
|
bool
|
Enable Quadkey compact mode for polygons |
False
|
topology
|
bool
|
Enable topology preserving mode to ensure disjoint features have disjoint Quadkey cells |
False
|
output_format
|
str
|
Output format ('gpd', 'geojson', 'csv', 'shapefile', 'gpkg', 'parquet', 'geoparquet') |
'gpd'
|
include_properties
|
bool
|
Whether to include properties in output |
True
|
**kwargs
|
Additional arguments passed to process_input_data_vector |
{}
|
Returns:
| Type | Description |
|---|---|
|
geopandas.GeoDataFrame, dict, or str: Output in the specified format. If output_format is a file-based format, |
|
|
the output will be saved to a file in the current directory with a default name based on the input. |
|
|
Otherwise, returns a Python object (GeoDataFrame, dict, etc.) depending on output_format. |
Example
result = vector2quadkey("data/points.geojson", resolution=10, output_format="geojson") print(f"Output saved to: {result}")
Source code in vgrid/conversion/vector2dggs/vector2quadkey.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 452 453 454 | |
vector2quadkey_cli()
¶
Command-line interface for vector2quadkey conversion.
This function provides a command-line interface for converting vector data to Quadkey grid cells. It supports various input formats and output formats, with options for resolution control, spatial predicates, compact mode, and topology preservation.
Usage
python vector2quadkey.py -i input.geojson -r 10 -f geojson python vector2quadkey.py -i input.shp -r 8 -p intersect -c -t
Source code in vgrid/conversion/vector2dggs/vector2quadkey.py
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 518 519 520 521 522 523 524 525 526 527 528 529 | |