Skip to content

Make spatial sorting optional #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ python = "^3.11"
gdal = "3.8.4"
geopandas = "^1.0.1"
h3pandas = "^0.2.6"
h3 = "<4"
dask-geopandas = "^0.4.1"
dask = "^2024.8.0"
click = "^8.1.7"
Expand Down
20 changes: 13 additions & 7 deletions vector2dggs/h3.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ def polyfill(
Reads a geoparquet, performs H3 polyfilling (for Polygon),
linetracing (for LineString), and writes out to parquet.
"""
df = gpd.read_parquet(pq_in).reset_index().drop(columns=[spatial_sort_col])
df = gpd.read_parquet(pq_in).reset_index()

if spatial_sort_col != "none":
df = df.drop(columns=[spatial_sort_col])

if len(df.index) == 0:
# Input is empty, nothing to polyfill
return None
Expand Down Expand Up @@ -248,11 +252,13 @@ def _index(

ddf = dgpd.from_geopandas(df, chunksize=max(1, chunksize), sort=True)

LOGGER.info("Spatially sorting and partitioning (%s)", spatial_sorting)
ddf = ddf.spatial_shuffle(by=spatial_sorting)
if spatial_sorting != "none":
LOGGER.info("Spatially sorting and partitioning (%s)", spatial_sorting)
ddf = ddf.spatial_shuffle(by=spatial_sorting)

spatial_sort_col = (
spatial_sorting
if spatial_sorting == "geohash"
if (spatial_sorting == "geohash" or spatial_sorting == "none")
else f"{spatial_sorting}_distance"
)

Expand Down Expand Up @@ -330,9 +336,9 @@ def _index(
@click.option(
"-s",
"--spatial_sorting",
type=click.Choice(["hilbert", "morton", "geohash"]),
default="hilbert",
help="Spatial sorting method when perfoming spatial partitioning.",
type=click.Choice(["hilbert", "morton", "geohash", "none"]),
default="none",
help="Spatial sorting method when perfoming spatial partitioning. Disabled (by default) with option 'none'. May improve performance in some situations.",
)
@click.option(
"-crs",
Expand Down
Loading