@@ -363,6 +363,57 @@ def fake_enclosed_tessellation(**kwargs: object) -> gpd.GeoDataFrame:
363363 assert result .geometry .area .sum () == pytest .approx (enclosure .area )
364364 assert "overlapping cells" in caplog .text
365365
366+ def test_enclosed_tessellation_overlap_retry_falls_back_to_simplify_false (
367+ self ,
368+ sample_buildings_gdf : gpd .GeoDataFrame ,
369+ sample_segments_gdf : gpd .GeoDataFrame ,
370+ caplog : pytest .LogCaptureFixture ,
371+ monkeypatch : pytest .MonkeyPatch ,
372+ ) -> None :
373+ """A geometry-type error during the overlap retry should retry simplify=False."""
374+ enclosure = Polygon ([(0 , 0 ), (10 , 0 ), (10 , 10 ), (0 , 10 )])
375+ monkeypatch .setattr (
376+ momepy ,
377+ "enclosures" ,
378+ lambda ** _kwargs : gpd .GeoDataFrame (
379+ {"eID" : [0 ]},
380+ geometry = [enclosure ],
381+ crs = sample_buildings_gdf .crs ,
382+ ),
383+ )
384+
385+ sane_cells = [
386+ Polygon ([(0 , 0 ), (5 , 0 ), (5 , 10 ), (0 , 10 )]),
387+ Polygon ([(5 , 0 ), (10 , 0 ), (10 , 10 ), (5 , 10 )]),
388+ ]
389+
390+ def fake_enclosed_tessellation (** kwargs : object ) -> gpd .GeoDataFrame :
391+ # The first run silently degenerates; the coarser grid_size retry
392+ # snaps cells into non-polygonal geometry and blows up in
393+ # coverage_simplify; only simplify=False succeeds.
394+ if kwargs .get ("grid_size" ) and kwargs .get ("simplify" ) is not False :
395+ msg = "One of the Geometry inputs is of incorrect geometry type."
396+ raise TypeError (msg )
397+ cells = sane_cells if kwargs .get ("grid_size" ) else [enclosure , enclosure ]
398+ return gpd .GeoDataFrame (
399+ {"enclosure_index" : [0 , 0 ]},
400+ geometry = cells ,
401+ index = [0 , 1 ],
402+ crs = sample_buildings_gdf .crs ,
403+ )
404+
405+ monkeypatch .setattr (momepy , "enclosed_tessellation" , fake_enclosed_tessellation )
406+
407+ with caplog .at_level ("WARNING" ):
408+ result = utils .create_tessellation (
409+ sample_buildings_gdf ,
410+ primary_barriers = sample_segments_gdf ,
411+ )
412+
413+ assert len (result ) == 2
414+ assert result .geometry .area .sum () == pytest .approx (enclosure .area )
415+ assert "retrying with simplify=False" in caplog .text
416+
366417 def test_enclosed_tessellation_drops_persistently_overlapping_enclosures (
367418 self ,
368419 sample_buildings_gdf : gpd .GeoDataFrame ,
0 commit comments