Skip to content

Commit

Permalink
Merge pull request #196 from martinfleis/3d
Browse files Browse the repository at this point in the history
  • Loading branch information
knaaptime authored Dec 1, 2023
2 parents 45b9673 + 78a5db0 commit e9ffd53
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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

0 comments on commit e9ffd53

Please sign in to comment.