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

cells_to_wkb_points returning longitude for both coordinates #58

Closed
zacdezgeo opened this issue Oct 3, 2024 · 2 comments
Closed

cells_to_wkb_points returning longitude for both coordinates #58

zacdezgeo opened this issue Oct 3, 2024 · 2 comments

Comments

@zacdezgeo
Copy link

zacdezgeo commented Oct 3, 2024

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:

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!

@nmandery
Copy link
Owner

nmandery commented Oct 4, 2024

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 ;)

@nmandery
Copy link
Owner

nmandery commented Oct 4, 2024

The fix will be in v0.21.1 and is currently build on GH actions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants