def create_mesh(layer, max_area=10000000, max_angle=30, saveFig=False): ''' Function that create a triangular mesh based on a layer input. The max_area and max_angle parameter control the shape of the triangular shape. The saveFig parameter if True save the create mesh to pdf. The path to the triangular.exe must be change inside the function regarding the location. ''' #Extract the points that compose the geometry layer_pts = [] for x, y in zip(layer.geometry[0].boundary.xy[0], layer.geometry[0].boundary.xy[1]): layer_pts.append((float(x), float(y))) #Create a directory to store the mesh/mf6 files path_ws = './mesh' if os.path.exists(path_ws): shutil.rmtree(path_ws) os.makedirs(path_ws) #Build the grid path_tri1 = '/mnt/c/Users/wdall/switchdrive/00_Institution/03_Code_Python/3.0/04_Trend/01_FloPy/MODFLOW/bin/triangle.exe' path_tri2 = '/home/valentin/ownCloud/00_Institution/03_Code_Python/3.0/04_Trend/01_FloPy/linux_bin/triangle' grid = Triangle(maximum_area=max_area, angle=max_angle, model_ws=path_ws, exe_name=path_tri2) grid.add_polygon(layer_pts) grid.build() #Plot the grid fig = plt.figure(figsize=(5, 5)) ax = plt.subplot(1, 1, 1, aspect='equal') pc = grid.plot() start, end = ax.get_xlim() locx = plticker.MultipleLocator( base=(end - start) / 15) # this locator puts ticks at regular intervals start, end = ax.get_ylim() locy = plticker.MultipleLocator( base=(end - start) / 20) # this locator puts ticks at regular intervals ax.xaxis.set_major_locator(locx) ax.yaxis.set_major_locator(locy) plt.xticks(rotation=90) #minor_ticks_x = np.arange(660000, 710000, (710000-660000)/25) #minor_ticks_y = np.arange(6150000, 6210000, (6210000-6150000)/30) #ax.set_xticks(minor_ticks_x, minor=True) #ax.set_yticks(minor_ticks_y, minor=True) ax.grid(c='lightblue', which='minor', alpha=0.8) ax.grid(c='tan', which='major') plt.tight_layout() if saveFig == True: fig.savefig('mesh.pdf') return layer_pts, grid
def create_mesh(layer, max_area=10000000, max_angle=30, saveFig=False): ''' Function that create a triangular mesh based on a layer input. The created mesh is then plot. The max_area and max_angle parameter control the shape of the triangular shape. The saveFig parameter if True save the create mesh to pdf. The path to the triangular.exe must be change inside the function regarding the location. Inputs : ----------- layer : geopanda layer geometry, created with the create_grid function max_area : maximum area of a cell max_angle : maximum angle of a cell saveFig : store the to pdf the created mesh (boolean). Outputs : ----------- layer_pts : coordinates of the points geometry. mesh : triangular mesh ''' #Extract the points that compose the geometry layer_pts = [] for x, y in zip(layer.geometry[0].boundary.xy[0], layer.geometry[0].boundary.xy[1]): layer_pts.append((float(x), float(y))) #Create a directory to store the mesh/mf6 files path_ws = './mesh' if os.path.exists(path_ws): shutil.rmtree(path_ws) os.makedirs(path_ws) #Build the mesh path_tri = './linux_bin/triangle' mesh = Triangle(maximum_area=max_area, angle=max_angle, model_ws=path_ws, exe_name=path_tri) mesh.add_polygon(layer_pts) mesh.build() #Plot the mesh fig = plt.figure(figsize=(5, 5)) ax = plt.subplot(1, 1, 1, aspect='equal') pc = mesh.plot() start, end = ax.get_xlim() locx = plticker.MultipleLocator( base=(end - start) / 15) # this locator puts ticks at regular intervals start, end = ax.get_ylim() locy = plticker.MultipleLocator( base=(end - start) / 20) # this locator puts ticks at regular intervals ax.xaxis.set_major_locator(locx) ax.yaxis.set_major_locator(locy) plt.xticks(rotation=90) ax.grid(c='lightblue', which='minor', alpha=0.8) ax.grid(c='tan', which='major') plt.tight_layout() if saveFig == True: fig.savefig('mesh.pdf') return layer_pts, mesh