pysal / libpysal

Core components of Python Spatial Analysis Library
http://pysal.org/libpysal
Other
249 stars 79 forks source link

ENH: add Graph.build_h3 #694

Closed martinfleis closed 1 month ago

martinfleis commented 3 months ago

Closes #667

I am open to API suggestions, especially regarding weight. Example usage:

import geopandas as gpd
from geodatasets import get_path
from tobler.util import h3fy

from libpysal import graph

gdf = gpd.read_file(get_path("geoda guerry"))
h3 = h3fy(gdf, resolution=4)
G = graph.Graph.build_h3(h3.index)

In theory, you can use this to do spatial stats without having any geometry, just the indices.

@ljwolf I am aware of you suggestion to support other hierarchical indices as well but I am not sure if the overall goal with that would be to have a single builder method (or of it is wise to have only one) or individual, so I went ahead with H3-specific one.

knaaptime commented 3 months ago

would it be better to move h3fy to lib?

martinfleis commented 3 months ago

would it be better to move h3fy to lib?

I got no opinion there, either way is fine with me.

codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 94.33962% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 85.0%. Comparing base (bcabdbc) to head (88c3448). Report is 2 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/pysal/libpysal/pull/694/graphs/tree.svg?width=650&height=150&src=pr&token=wgnkG5Rj0J&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal)](https://app.codecov.io/gh/pysal/libpysal/pull/694?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal) ```diff @@ Coverage Diff @@ ## main #694 +/- ## ===================================== Coverage 85.0% 85.0% ===================================== Files 141 143 +2 Lines 15203 15259 +56 ===================================== + Hits 12924 12974 +50 - Misses 2279 2285 +6 ``` | [Files](https://app.codecov.io/gh/pysal/libpysal/pull/694?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal) | Coverage Δ | | |---|---|---| | [libpysal/graph/\_indices.py](https://app.codecov.io/gh/pysal/libpysal/pull/694?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal#diff-bGlicHlzYWwvZ3JhcGgvX2luZGljZXMucHk=) | `100.0% <100.0%> (ø)` | | | [libpysal/graph/tests/test\_indices.py](https://app.codecov.io/gh/pysal/libpysal/pull/694?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal#diff-bGlicHlzYWwvZ3JhcGgvdGVzdHMvdGVzdF9pbmRpY2VzLnB5) | `100.0% <100.0%> (ø)` | | | [libpysal/graph/base.py](https://app.codecov.io/gh/pysal/libpysal/pull/694?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal#diff-bGlicHlzYWwvZ3JhcGgvYmFzZS5weQ==) | `97.0% <75.0%> (-0.9%)` | :arrow_down: | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/pysal/libpysal/pull/694/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal)