@@ -3022,7 +3022,7 @@ def fix_small_el(mesh_w_problem: jigsaw_msh_t,
30223022
30233023def merge_overlapping_meshes (all_msht : list ,
30243024 adjacent_layers : int = 0 ,
3025- buffer_size : float = 0.005 ,
3025+ buffer_size : float = 0.0075 ,
30263026 buffer_domain : float = 0.01 ,
30273027 min_int_ang : int = 30 ,
30283028 hfun_mesh = None ,
@@ -3088,7 +3088,9 @@ def merge_overlapping_meshes(all_msht: list,
30883088 msht
30893089 )
30903090 msht_combined = clip_mesh_by_shape (msht_combined ,
3091- domain .union_all ()
3091+ domain .union_all (),
3092+ fit_inside = False ,
3093+ check_cross_edges = True
30923094 )
30933095 del carved_mesh ,buff_mesh ,domain ,msht
30943096
@@ -3779,6 +3781,7 @@ def triangulate_poly(rm_poly):
37793781
37803782 return rm_mesh
37813783
3784+
37823785def validate_poly (gdf ):
37833786 '''
37843787 Goes over all polygons in a gpf and applied the make_valid func
@@ -3808,6 +3811,7 @@ def validate_poly(gdf):
38083811
38093812 return gdf_valid , gdf_invalid
38103813
3814+
38113815def find_polyneighbors (target_gdf , ref_gdf ):
38123816 '''
38133817 Finds all polygons in target_gdf that
@@ -3842,6 +3846,7 @@ def find_polyneighbors(target_gdf, ref_gdf):
38423846
38433847 return sjoin
38443848
3849+
38453850def validate_RMmesh (RMmesh ):
38463851 '''
38473852 Takes a mesh triangulated from a polygon and
@@ -3925,3 +3930,78 @@ def triangulate_rivermapper_poly(rm_poly):
39253930 validated_RMmesh = validate_RMmesh (RMmesh )
39263931
39273932 return validated_RMmesh
3933+
3934+
3935+ def remesh_holes (msht : jigsaw_msh_t ,
3936+ area_threshold_min : float = .0 ,
3937+ area_threshold_max : float = .002
3938+ ) -> jigsaw_msh_t :#1.0e-15
3939+ '''
3940+ Remove undesirable island and slivers based on area
3941+
3942+ Parameters
3943+ ----------
3944+ msht : jigsawpy.msh_t.jigsaw_msh_t
3945+ area_threshold_min : default=.0
3946+ area_threshold_max : default=.002
3947+
3948+ Returns
3949+ -------
3950+ jigsaw_msh_t
3951+ mesh holes remeshed
3952+
3953+ Notes
3954+ -----
3955+ 1.0e-15 is usually ideal for removing slivers
3956+ '''
3957+
3958+ mesh_poly = get_mesh_polygons (msht )
3959+ mesh_gdf = gpd .GeoDataFrame (geometry =
3960+ gpd .GeoSeries (mesh_poly ),
3961+ crs = 4326 ).dissolve ().explode ()
3962+ mesh_noholes_poly = remove_holes (
3963+ mesh_gdf .union_all ())
3964+
3965+ mesh_holes_poly = mesh_noholes_poly .difference (mesh_poly )
3966+ mesh_holes_gdf = gpd .GeoDataFrame (geometry =
3967+ gpd .GeoSeries (mesh_holes_poly ),
3968+ crs = 4326 ).dissolve ().explode ()
3969+ mesh_holes_gdf ['area' ] = mesh_holes_gdf .geometry .area
3970+ selected_holes = mesh_holes_gdf [
3971+ (mesh_holes_gdf ['area' ] >= area_threshold_min ) & \
3972+ (mesh_holes_gdf ['area' ] <= area_threshold_max )]
3973+
3974+ carved_holes = clip_mesh_by_shape (msht ,
3975+ selected_holes .union_all (),
3976+ adjacent_layers = 2 ,
3977+ inverse = True ,
3978+ )
3979+ carved_poly = get_mesh_polygons (carved_holes )
3980+ patch_poly = mesh_noholes_poly .difference (carved_poly )
3981+ patch_gdf = gpd .GeoDataFrame (geometry =
3982+ gpd .GeoSeries (patch_poly ),
3983+ crs = 4326 ).dissolve ().explode ()
3984+ patch_gdf = patch_gdf [~ patch_gdf .geometry .is_empty ]
3985+
3986+ #aux_pts:
3987+ aux_pts_mesh = clip_mesh_by_shape (msht ,
3988+ patch_gdf .union_all (),
3989+ fit_inside = True )
3990+ all_nodes = aux_pts_mesh .vert2 ['coord' ]
3991+ aux_pts = MultiPoint (all_nodes )
3992+
3993+ aux_pts = gpd .GeoDataFrame (geometry =
3994+ gpd .GeoSeries (intersection (
3995+ aux_pts ,
3996+ patch_poly .buffer (- 0.00001 ),
3997+ )))
3998+ msht_patch = triangulate_polygon_s (patch_gdf ,
3999+ aux_pts = aux_pts )
4000+
4001+ mesh_filled = merge_neighboring_meshes (carved_holes ,
4002+ msht_patch )
4003+ cleanup_duplicates (mesh_filled )
4004+ cleanup_isolates (mesh_filled )
4005+ put_id_tags (mesh_filled )
4006+
4007+ return mesh_filled
0 commit comments