88import pandas as pd
99import geopandas as gpd
1010
11- from h3 import h3
11+ import h3
1212from pandas .core .frame import DataFrame
1313from geopandas .geodataframe import GeoDataFrame
1414
1515from .const import COLUMN_H3_POLYFILL , COLUMN_H3_LINETRACE
1616from .util .decorator import catch_invalid_h3_address , doc_standard
1717from .util .functools import wrapped_partial
18- from .util .shapely import polyfill , linetrace
18+ from .util .shapely import cell_to_boundary_lng_lat , polyfill , linetrace , _switch_lat_lng
1919
2020AnyDataFrame = Union [DataFrame , GeoDataFrame ]
2121
@@ -92,7 +92,7 @@ def geo_to_h3(
9292 lats = self ._df [lat_col ]
9393
9494 h3addresses = [
95- h3 .geo_to_h3 (lat , lng , resolution ) for lat , lng in zip (lats , lngs )
95+ h3 .latlng_to_cell (lat , lng , resolution ) for lat , lng in zip (lats , lngs )
9696 ]
9797
9898 colname = self ._format_resolution (resolution )
@@ -130,9 +130,9 @@ def h3_to_geo(self) -> GeoDataFrame:
130130
131131 """
132132 return self ._apply_index_assign (
133- h3 .h3_to_geo ,
133+ h3 .cell_to_latlng ,
134134 "geometry" ,
135- lambda x : shapely .geometry .Point ( reversed (x )),
135+ lambda x : _switch_lat_lng ( shapely .geometry .Point (x )),
136136 lambda x : gpd .GeoDataFrame (x , crs = "epsg:4326" ),
137137 )
138138
@@ -158,10 +158,9 @@ def h3_to_geo_boundary(self) -> GeoDataFrame:
158158 881e2659c3fffff 1 POLYGON ((14.99201 51.00565, 14.98973 51.00133...
159159 """
160160 return self ._apply_index_assign (
161- wrapped_partial (h3 . h3_to_geo_boundary , geo_json = True ),
161+ wrapped_partial (cell_to_boundary_lng_lat ),
162162 "geometry" ,
163- lambda x : shapely .geometry .Polygon (x ),
164- lambda x : gpd .GeoDataFrame (x , crs = "epsg:4326" ),
163+ finalizer = lambda x : gpd .GeoDataFrame (x , crs = "epsg:4326" ),
165164 )
166165
167166 @doc_standard ("h3_resolution" , "containing the resolution of each H3 address" )
@@ -176,7 +175,7 @@ def h3_get_resolution(self) -> AnyDataFrame:
176175 881e309739fffff 5 8
177176 881e2659c3fffff 1 8
178177 """
179- return self ._apply_index_assign (h3 .h3_get_resolution , "h3_resolution" )
178+ return self ._apply_index_assign (h3 .get_resolution , "h3_resolution" )
180179
181180 @doc_standard ("h3_base_cell" , "containing the base cell of each H3 address" )
182181 def h3_get_base_cell (self ):
@@ -190,7 +189,7 @@ def h3_get_base_cell(self):
190189 881e309739fffff 5 15
191190 881e2659c3fffff 1 15
192191 """
193- return self ._apply_index_assign (h3 .h3_get_base_cell , "h3_base_cell" )
192+ return self ._apply_index_assign (h3 .get_base_cell_number , "h3_base_cell" )
194193
195194 @doc_standard ("h3_is_valid" , "containing the validity of each H3 address" )
196195 def h3_is_valid (self ):
@@ -203,7 +202,7 @@ def h3_is_valid(self):
203202 881e309739fffff 5 True
204203 INVALID 1 False
205204 """
206- return self ._apply_index_assign (h3 .h3_is_valid , "h3_is_valid" )
205+ return self ._apply_index_assign (h3 .is_valid_cell , "h3_is_valid" )
207206
208207 @doc_standard (
209208 "h3_k_ring" , "containing a list H3 addresses within a distance of `k`"
@@ -250,7 +249,7 @@ def k_ring(self, k: int = 1, explode: bool = False) -> AnyDataFrame:
250249 881e309739fffff 5 881e309739fffff
251250 881e309739fffff 5 881e309731fffff
252251 """
253- func = wrapped_partial (h3 .k_ring , k = k )
252+ func = wrapped_partial (h3 .grid_disk , k = k )
254253 column_name = "h3_k_ring"
255254 if explode :
256255 return self ._apply_index_explode (func , column_name , list )
@@ -295,7 +294,7 @@ def hex_ring(self, k: int = 1, explode: bool = False) -> AnyDataFrame:
295294 881e309739fffff 5 881e309715fffff
296295 881e309739fffff 5 881e309731fffff
297296 """
298- func = wrapped_partial (h3 .hex_ring , k = k )
297+ func = wrapped_partial (h3 .grid_ring , k = k )
299298 column_name = "h3_hex_ring"
300299 if explode :
301300 return self ._apply_index_explode (func , column_name , list )
@@ -330,7 +329,7 @@ def h3_to_parent(self, resolution: int = None) -> AnyDataFrame:
330329 else "h3_parent"
331330 )
332331 return self ._apply_index_assign (
333- wrapped_partial (h3 .h3_to_parent , res = resolution ), column
332+ wrapped_partial (h3 .cell_to_parent , res = resolution ), column
334333 )
335334
336335 @doc_standard ("h3_center_child" , "containing the center child of each H3 address" )
@@ -352,7 +351,7 @@ def h3_to_center_child(self, resolution: int = None) -> AnyDataFrame:
352351 881e2659c3fffff 1 891e2659c23ffff
353352 """
354353 return self ._apply_index_assign (
355- wrapped_partial (h3 .h3_to_center_child , res = resolution ), "h3_center_child"
354+ wrapped_partial (h3 .cell_to_center_child , res = resolution ), "h3_center_child"
356355 )
357356
358357 @doc_standard (
@@ -395,7 +394,7 @@ def polyfill(self, resolution: int, explode: bool = False) -> AnyDataFrame:
395394 """
396395
397396 def func (row ):
398- return list (polyfill (row .geometry , resolution , True ))
397+ return list (polyfill (row .geometry , resolution ))
399398
400399 result = self ._df .apply (func , axis = 1 )
401400
@@ -553,7 +552,7 @@ def h3_to_parent_aggregate(
553552 811e3ffffffffff 6
554553 """
555554 parent_h3addresses = [
556- catch_invalid_h3_address (h3 .h3_to_parent )(h3address , resolution )
555+ catch_invalid_h3_address (h3 .cell_to_parent )(h3address , resolution )
557556 for h3address in self ._df .index
558557 ]
559558 h3_parent_column = self ._format_resolution (resolution )
@@ -758,9 +757,7 @@ def polyfill_resample(
758757
759758 return result .h3 .h3_to_geo_boundary () if return_geometry else result
760759
761- def linetrace (
762- self , resolution : int , explode : bool = False
763- ) -> AnyDataFrame :
760+ def linetrace (self , resolution : int , explode : bool = False ) -> AnyDataFrame :
764761 """Experimental. An H3 cell representation of a (Multi)LineString,
765762 which permits repeated cells, but not if they are repeated in
766763 immediate sequence.
@@ -792,6 +789,7 @@ def linetrace(
792789 0 LINESTRING (0.00000 0.00000, 1.00000 0.00000, ... 837541fffffffff
793790
794791 """
792+
795793 def func (row ):
796794 return list (linetrace (row .geometry , resolution ))
797795
0 commit comments