Created
November 26, 2024 21:30
-
-
Save cboettig/c7ec9e05142493ac61199b6bb18a01da to your computer and use it in GitHub Desktop.
filter data using h3 indices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
park = (con | |
.read_geo("/vsicurl/https://huggingface.co/datasets/cboettig/biodiversity/resolve/main/data/NPS.gdb") | |
.filter(_.UNIT_NAME == "Yosemite National Park") | |
.select(_.SHAPE) | |
.mutate(SHAPE = _.SHAPE.convert('EPSG:3857', 'EPSG:4326')) | |
.mutate(lng = _.SHAPE.centroid().x(), lat = _.SHAPE.centroid().y()) | |
.mutate(h1 = h3_latlng_to_cell(_.lat, _.lng, 1) ) | |
.mutate(neighbors = h3_grid_disk(_.h1, 1)) | |
#.mutate(cells = h3_polygon_wkt_to_cells_string(_.SHAPE.as_text(),1)) | |
) | |
park = park.execute() | |
h1_neighbors = [format(i, 'X') for i in park.neighbors[0]] | |
aoi = con.create_table("aoi", {'h1': h1_neighbors}, overwrite=True) | |
aoi.execute() | |
gbif = con.read_parquet("s3://cboettig/gbif/2024-10-01/**") | |
gbif.join(aoi, "h1").count().execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment