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

Fix coordinate messup when converting H3 entities to points. Fixes #58 #60

Merged
merged 4 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
run: |
set -e
pip install --force-reinstall dist/*.whl
pytest -s h3ronpy/tests
python -m pytest -s h3ronpy/tests

linux-aarch64:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
run: |
set -e
pip install --force-reinstall dist/*.whl
pytest h3ronpy/tests
python -m pytest h3ronpy/tests

macos-x86_64:
needs:
Expand Down Expand Up @@ -162,7 +162,7 @@ jobs:
# run: |
# set -e
# pip install --force-reinstall --verbose dist/*.whl
# pytest h3ronpy/tests
# python -m pytest h3ronpy/tests

macos-aarch64:
runs-on: macos-latest
Expand Down
2 changes: 1 addition & 1 deletion crates/h3arrow/src/array/to_geo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ macro_rules! impl_iter_points {
let pt: Point = if use_degrees {
Coord {
x: ll.lng(),
y: ll.lng(),
y: ll.lat(),
}
.into()
} else {
Expand Down
2 changes: 2 additions & 0 deletions h3ronpy/CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Versioning <https://semver.org/spec/v2.0.0.html>`__.
Unreleased
----------

- Fixed coordinate messup when converting H3 entities to points (issue #58).

0.21.0 - 2024-07-01
-------------------

Expand Down
1 change: 1 addition & 0 deletions h3ronpy/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ polars = [
]
pandas = [
"geopandas>=0.10",
"fiona>=1.9"
nmandery marked this conversation as resolved.
Show resolved Hide resolved
]
test = [
"rasterio",
Expand Down
25 changes: 24 additions & 1 deletion h3ronpy/tests/arrow/test_vector.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from h3ronpy.arrow.vector import geometry_to_cells, ContainmentMode
from h3ronpy.arrow.vector import geometry_to_cells, ContainmentMode, cells_to_wkb_points
import pyarrow as pa
import shapely
from shapely.geometry import Point
from shapely import wkb
import h3.api.numpy_int as h3


Expand All @@ -20,3 +21,25 @@ def test_geometry_to_cells_central_park():
arr = geometry_to_cells(point, 8).to_numpy()
assert len(arr) == 1
assert arr[0] == h3.geo_to_h3(point.y, point.x, 8)


def test_coordinate_values_are_not_equal_issue_58():
# Step 1: Create a point (latitude and longitude)
lat, lon = 37.7749, -122.4194 # Example coordinates (San Francisco)
point = Point(lon, lat) # shapely expects (longitude, latitude)

# Step 2: Convert the point to an H3 cell (resolution 9 for example)
resolution = 9
h3_cells = geometry_to_cells(point, resolution)

# Step 3: Convert the H3 cell back to WKB points
wkb_points = cells_to_wkb_points(h3_cells)

assert len(wkb_points) == 1

# Step 4: Decode the WKB point to a Shapely geometry
for wkb_point in wkb_points:
assert isinstance(wkb_point, pa.Scalar) # Ensure it's a pyarrow Scalar
nmandery marked this conversation as resolved.
Show resolved Hide resolved
shapely_point = wkb.loads(wkb_point.as_buffer().to_pybytes())
assert int(lat) == int(shapely_point.y)
assert int(lon) == int(shapely_point.x)
Loading