Skip to content

BUG: fix support for 3D geometries in h3fy #196

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

Merged
merged 1 commit into from
Dec 1, 2023
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
8 changes: 8 additions & 0 deletions tobler/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import geopandas
import pytest
import shapely
from libpysal.examples import load_example
from numpy.testing import assert_almost_equal

Expand Down Expand Up @@ -54,3 +55,10 @@ def test_h3_multipoly():
va = geopandas.read_file(load_example("virginia").get_path("virginia.shp"))
va = h3fy(va)
assert_almost_equal(va.to_crs(2284).unary_union.area, 1106844905155.1118, decimal=0)


def test_h3fy_3d():
gdf = sac1.copy()
gdf.geometry = shapely.force_3d(gdf.geometry)
sac_hex = h3fy(gdf, return_geoms=True)
assert sac_hex.shape == (364, 1)
3 changes: 2 additions & 1 deletion tobler/util/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import geopandas
import numpy as np
import pandas
import shapely
from shapely.geometry import Polygon


Expand Down Expand Up @@ -138,7 +139,7 @@ def h3fy(source, resolution=6, clip=False, buffer=False, return_geoms=True):
else:
source = source.to_crs(4326)

source_unary = source.unary_union
source_unary = shapely.force_2d(source.unary_union)

if type(source_unary) == Polygon:
hexagons = _to_hex(
Expand Down