Skip to content
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

update h3 to v4 #254

Merged
merged 1 commit into from
Oct 22, 2024
Merged
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
438 changes: 223 additions & 215 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ numpy = [
{ version = ">=1.21,<3", python = "<3.9" },
{ version = ">=1.23,<3", python = ">=3.9" }
]
h3 = ">=3.7.6,<4" # python3.11 support
h3 = ">4"
cffi = ">=1.15.1,<2"
# build dependencies. workaround to always have these installed
setuptools = ">=65.5"
Expand Down
14 changes: 7 additions & 7 deletions scripts/file_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ class Hex:

@classmethod
def from_id(cls, id: int):
res = h3.h3_get_resolution(id)
coord_pairs = h3.h3_to_geo_boundary(id)
res = h3.get_resolution(id)
coord_pairs = h3.cell_to_boundary(id)
# ATTENTION: (lat, lng)! pairs
coords = to_numpy_polygon(coord_pairs, flipped=True)
x_coords, y_coords = coords[0], coords[1]
Expand Down Expand Up @@ -510,7 +510,7 @@ def true_parents(self) -> HexIdSet:
lower_res = self.res - 1
# NOTE: (lat,lng) pairs!
coord_pairs = h3.h3_to_geo_boundary(self.id)
return {h3.geo_to_h3(pt[0], pt[1], lower_res) for pt in coord_pairs}
return {h3.latlng_to_cell(pt[0], pt[1], lower_res) for pt in coord_pairs}


@functools.lru_cache(maxsize=int(1e6))
Expand Down Expand Up @@ -610,8 +610,8 @@ def compile_shortcut_mapping(output_path: Path) -> int:
return shortcut_space


def geo_to_h3(lng: float, lat: float) -> int:
return h3.geo_to_h3(lat, lng, SHORTCUT_H3_RES)
def latlng_to_cell(lng: float, lat: float) -> int:
return h3.latlng_to_cell(lat, lng, SHORTCUT_H3_RES)


def validate_shortcut_completeness(mapping: ShortcutMapping):
Expand All @@ -624,7 +624,7 @@ def validate_shortcut_completeness(mapping: ShortcutMapping):
# ATTENTION: int to coord conversion required!
lng = int2coord(pt[0])
lat = int2coord(pt[1])
hex_id = geo_to_h3(lng, lat)
hex_id = latlng_to_cell(lng, lat)
try:
shortcut_entries = mapping[hex_id]
except KeyError:
Expand All @@ -644,7 +644,7 @@ def validate_shortcut_completeness(mapping: ShortcutMapping):

def validate_shortcut_resolution(mapping: ShortcutMapping):
for hex_id in mapping.keys():
assert h3.h3_get_resolution(hex_id) == SHORTCUT_H3_RES
assert h3.get_resolution(hex_id) == SHORTCUT_H3_RES


def validate_unused_polygons(shortcuts: ShortcutMapping):
Expand Down
2 changes: 1 addition & 1 deletion tests/shortcut_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_import_export():

def test_resolutions():
shortcut_hex_ids = shortcuts.keys()
resolutions = [h3.h3_get_resolution(h) for h in shortcut_hex_ids]
resolutions = [h3.get_resolution(h) for h in shortcut_hex_ids]
res_matched = [res == configs.SHORTCUT_H3_RES for res in resolutions]
assert all(
res_matched
Expand Down
4 changes: 2 additions & 2 deletions timezonefinder/hex_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ def read_shortcuts_binary(path2shortcuts: Path) -> ShortcutMapping:


def lies_in_h3_cell(h: int, lng: float, lat: float) -> bool:
res = h3.h3_get_resolution(h)
return h3.geo_to_h3(lat, lng, res) == h
res = h3.get_resolution(h)
return h3.latlng_to_cell(lat, lng, res) == h
2 changes: 1 addition & 1 deletion timezonefinder/timezonefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def get_shortcut_polys(self, *, lng: float, lat: float) -> np.ndarray:
:param lat: The latitude of the point in degrees (90.0 to -90.0).
:return: An array of polygon IDs.
"""
hex_id = h3.geo_to_h3(lat, lng, SHORTCUT_H3_RES)
hex_id = h3.latlng_to_cell(lat, lng, SHORTCUT_H3_RES)
shortcut_poly_ids = self.shortcut_mapping[hex_id]
return shortcut_poly_ids

Expand Down