@@ -1260,31 +1260,38 @@ def configure(self, configure_context, input_schema):
12601260 return knext .Schema .from_columns (
12611261 [
12621262 knext .Column (knext .string (), self ._COL_ID ),
1263- knext .Column (input_schema [ self . geo_col ]. ktype , self ._COL_GEOMETRY ),
1263+ knext .Column (knut . TYPE_POLYGON , self ._COL_GEOMETRY ),
12641264 ]
12651265 )
12661266
12671267 def execute (self , exec_context : knext .ExecutionContext , input_table ):
12681268 import h3
1269- from shapely .geometry import Polygon
1269+ from shapely .geometry import Polygon , mapping
1270+ from shapely .ops import unary_union
12701271 import geopandas as gpd
12711272 import pandas as pd
12721273
12731274 gdf_boundary = knut .load_geo_data_frame (input_table , self .geo_col , exec_context )
12741275
12751276 knut .check_canceled (exec_context )
12761277 exec_context .set_progress (0.1 , "Projecting input polygon..." )
1277- gdf_boundary .to_crs (4326 , inplace = True )
1278+ USE_CRS = 4326
1279+ gdf_boundary .to_crs (USE_CRS , inplace = True )
12781280
12791281 knut .check_canceled (exec_context )
12801282 exec_context .set_progress (0.3 , "Combining input polygon..." )
1281- gdf_boundary ["geometry" ] = gdf_boundary .unary_union
1283+ gdf_boundary = unary_union (gdf_boundary [self .geo_col ])
1284+ gdf_boundary = gpd .GeoDataFrame (geometry = [gdf_boundary ], crs = USE_CRS )
1285+
1286+ knut .check_canceled (exec_context )
1287+ exec_context .set_progress (0.4 , "Exploding input polygon..." )
1288+ gdf_boundary = gdf_boundary .explode (index_parts = True )
1289+ gdf_boundary .reset_index (drop = True , inplace = True )
12821290
12831291 knut .check_canceled (exec_context )
12841292 exec_context .set_progress (0.5 , "Computing H3 hexagons..." )
1285- h3_hexes = h3 .polyfill_geojson (
1286- gdf_boundary .geometry .__geo_interface__ ["features" ][0 ]["geometry" ],
1287- self .zoom ,
1293+ h3_hexes = set ().union (
1294+ * [h3 .polyfill_geojson (mapping (p ), self .zoom ) for p in gdf_boundary .geometry ]
12881295 )
12891296
12901297 knut .check_canceled (exec_context )
@@ -1295,9 +1302,10 @@ def execute(self, exec_context: knext.ExecutionContext, input_table):
12951302 Polygon (h3 .h3_to_geo_boundary (h3_hex , geo_json = True ))
12961303 for h3_hex in h3_hexes
12971304 ],
1298- crs = gdf_boundary . crs ,
1305+ crs = USE_CRS ,
12991306 )
1300- grid .rename_geometry (self ._COL_GEOMETRY , True )
1307+ # rename the geometry column
1308+ knut .rename_geometry (grid , self ._COL_GEOMETRY )
13011309
13021310 return knut .to_table (grid , exec_context )
13031311
@@ -1409,7 +1417,7 @@ def execute(self, exec_context: knext.ExecutionContext, input_table):
14091417 crs = gdf .crs ,
14101418 )
14111419 # rename the geometry column
1412- grid .rename_geometry (_COL_GEOMETRY , inplace = True )
1420+ knut .rename_geometry (grid , _COL_GEOMETRY )
14131421
14141422 if self .keep_original_table :
14151423 grid = pd .concat ([gdf , grid ], axis = 1 )
0 commit comments