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
Changes from 1 commit
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
Next Next commit
Fixed coordinate messup when converting H3 entities to points. Fixes #58
  • Loading branch information
nmandery committed Oct 4, 2024
commit c0b31a0d9255d702ed2bc861270300a8c2677d10
2 changes: 1 addition & 1 deletion crates/h3arrow/src/array/to_geo.rs
Original file line number Diff line number Diff line change
@@ -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 {
2 changes: 2 additions & 0 deletions h3ronpy/CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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
-------------------

2 changes: 1 addition & 1 deletion h3ronpy/pyproject.toml
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ polars = [
"polars>=1.0"
]
pandas = [
"geopandas>=0.10",
"geopandas>=1",
]
test = [
"rasterio",
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


@@ -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)
Loading
Oops, something went wrong.