@@ -19,7 +19,14 @@ def create_arg_parser():
1919 return parser
2020
2121
22- def small_areas (mesh , warn = 10.0 , fail = 1.0 , logger = None , write_out_smalls = False ):
22+ def small_areas (
23+ mesh ,
24+ warn = 10.0 ,
25+ fail = 1.0 ,
26+ logger = None ,
27+ write_out_smalls = False ,
28+ prepro_output_dir = "./" ,
29+ ):
2330 if logger is not None :
2431 logger .info (
2532 "Checking for elements with small areas. Thresholds: warn={}, fail={}" .format (
@@ -52,21 +59,23 @@ def small_areas(mesh, warn=10.0, fail=1.0, logger=None, write_out_smalls=False):
5259
5360 if areas_sorted [0 ] < fail :
5461 if write_out_smalls :
55- import shapefile as shp
62+ import geopandas as gpd
63+ from shapely .geometry import Point
5664
5765 sm_centroids = centroids [areas < fail ]
5866 sm_areas = areas [areas < fail ]
5967
60- w = shp .Writer ("small_area_centroids.shp" , shp .POINT )
61- w .autoBalance = 1 # ensures gemoetry and attributes match
62- w .field ("FID" , "N" )
63- w .field ("x" , "F" , 10 , 8 )
64- w .field ("y" , "F" , 10 , 8 )
65- w .field ("area" , "F" , 10 , 8 )
66- for i , smc in enumerate (sm_centroids ):
67- w .point (smc [0 ], smc [1 ]) # write the geometry
68- w .record (i , smc [0 ], smc [1 ], sm_areas [i ])
69- w .close ()
68+ gdf = gpd .GeoDataFrame (
69+ {
70+ "FID" : range (len (sm_centroids )),
71+ "x" : sm_centroids [:, 0 ],
72+ "y" : sm_centroids [:, 1 ],
73+ "area" : sm_areas ,
74+ },
75+ geometry = [Point (xy ) for xy in sm_centroids ],
76+ crs = "EPSG:4326" , # Change if you know the mesh CRS
77+ )
78+ gdf .to_file (f"{ prepro_output_dir } /small_area_centroids.shp" )
7079
7180 raise ValueError (
7281 "Mesh contains areas smaller than the failure threshold. Consult the log or printout above for areas and warnings"
0 commit comments