Repository: nmandery/h3ronpy (language: python)

Issue:
cells_to_wkb_points returning longitude for both coordinates
Hi! I've been migrating a project to `h3ronpy` but I've been running into an issue returning the centroids of hexagons. It seems that the coordinates returned have exactly the same value:

```python
import h3ronpy
from shapely.geometry import Point
from h3ronpy.arrow.vector import geometry_to_cells, cells_to_wkb_points
import pyarrow as pa
from shapely import wkb

# 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)

# Step 4: Decode the WKB point to a Shapely geometry
for wkb_point in wkb_points:
    if isinstance(wkb_point, pa.Scalar):  # Ensure it's a pyarrow Scalar
        shapely_point = wkb.loads(wkb_point.as_buffer().to_pybytes())
        print(f"Shapely Geometry: {shapely_point}")
    else:
        print(f"Unexpected Type: {type(wkb_point)}")
```

Returns:
```
Shapely Geometry: POINT (-122.41827103692466 -122.41827103692466)
```

I'd be happy to help with the fix! 


Discussion / hints:
Hi. Thanks for bringing this up (and the offer to help) - this is definitely a bug. I just checked and it happens with geopandas as well. I will look into this. 

Seems having more tests would have helped to catch this earlier ;)

Fix patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 878f731..ddc4b64 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -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
@@ -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:
@@ -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
diff --git a/crates/h3arrow/src/array/to_geo.rs b/crates/h3arrow/src/array/to_geo.rs
index 0c9d3ca..d9149c5 100644
--- a/crates/h3arrow/src/array/to_geo.rs
+++ b/crates/h3arrow/src/array/to_geo.rs
@@ -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 {
diff --git a/h3ronpy/CHANGES.rst b/h3ronpy/CHANGES.rst
index 42a0896..3dc62d2 100644
--- a/h3ronpy/CHANGES.rst
+++ b/h3ronpy/CHANGES.rst
@@ -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
 -------------------
 
diff --git a/h3ronpy/pyproject.toml b/h3ronpy/pyproject.toml
index 0fdaebb..f5643b9 100644
--- a/h3ronpy/pyproject.toml
+++ b/h3ronpy/pyproject.toml
@@ -37,6 +37,7 @@ polars = [
 ]
 pandas = [
     "geopandas>=0.10",
+    "fiona<1.10"
 ]
 test = [
     "rasterio",


Test patch:
diff --git a/h3ronpy/tests/arrow/test_vector.py b/h3ronpy/tests/arrow/test_vector.py
index 64debb2..cfd7b65 100644
--- a/h3ronpy/tests/arrow/test_vector.py
+++ b/h3ronpy/tests/arrow/test_vector.py
@@ -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
 
 
@@ -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
+        shapely_point = wkb.loads(wkb_point.as_buffer().to_pybytes())
+        assert int(lat) == int(shapely_point.y)
+        assert int(lon) == int(shapely_point.x)