This file contains 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
def list_tifs(path): | |
import glob | |
tifs = [] | |
for p in glob.glob(f"{path}/*/**/*.tif", recursive=True): | |
t = p | |
if "_HS_" not in t: | |
tifs.append(t) | |
return tifs |
This file contains 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
def _h3fy_updated(gdf, resolution): | |
""" | |
h3_radius values calculated using; | |
```python | |
import numpy as np | |
import pandas as pd | |
df = pd.read_html("https://h3geo.org/docs/core-library/restable/")[0] | |
y = df["Average Hexagon Area (km2)"].to_numpy() |
This file contains 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
import geopandas | |
import dask_geopandas | |
path = "https://geodata.ucdavis.edu/gadm/gadm4.0/gpkg/gadm40_USA.gpkg" | |
gdf = geopandas.read_file(path, layer="ADM_1") | |
gdf.head() | |
# Filter and rename cols | |
gdf = gdf[["NAME_1", "geometry"]].rename(columns={"NAME_1": "State"}) |
This file contains 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
def spatial_shuffle(ddf, by="hilbert", column=None, npartitions=20, p=10, **kwargs): | |
""" | |
A function that spatially shuffles a Dask-GeoSeries object by a method | |
or a user-defined column | |
Parameters | |
---------- | |
by : str | |
partitioning method or column |
This file contains 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
import pandas | |
import geopandas | |
import rioxarray | |
from shapely.geometry import box | |
def _polygonize(rioxarray_obj): | |
"""""" | |
poly_ls = [] |
This file contains 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
import pandas as pd | |
import geopandas as gpd | |
def multi_ring_buffers(gdf, number, distance): | |
""" | |
Apply a function to a GeoDataFrame containing Point data and compute constant multi-ring buffers | |
Parameters | |
---------- |
This file contains 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
def compute_zonal_stats(raster, vector, fid, col, statistics,tile,mode): | |
""" | |
Calculate zonal statistics using dask | |
Parameters | |
---------- | |
raster : A GeoDataFrame to create multiple copies based on the list of density thresholds |
This file contains 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
import dask | |
import dask_geomodeling | |
request = { | |
"mode": "vals", | |
"bbox": (138000, 480000, 139000, 481000), | |
"projection": "epsg:28992", | |
"width": 256, | |
"height": 256 | |
} | |
graph, name = add.get_compute_graph(**request) |
This file contains 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
# Import modules | |
from dask_geomodeling.raster import RasterBlock | |
from dask_geomodeling.raster import base | |
from dask_geomodeling.geometry import base | |
# Define paths | |
arg_rast_path = 'raster.tif' | |
arg_vec_path = 'vector.shp' | |
""" |
This file contains 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
# Load pkgs and data | |
import geopandas as gpd | |
data = gpd.read_file("https://gist.githubusercontent.com/HTenkanen/456ec4611a943955823a65729c9cf2aa/raw/be56f5e1e5c06c33cd51e89f823a7d770d8769b5/ykr_basegrid.geojson") | |
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres')) | |
# Subset argentina as single ply | |
argentina = world[world['name'] == 'Argentina' ] | |
# Define engine | |
engine = create_engine("postgresql+psycopg2://[user]:[password]@localhost:5432/[my_db]") |
NewerOlder