Topo - Convert a geopandas geodataframe to a pyvista unstructured grid

[1]:
#import required packages
from bootsoff.topo.geometry import gdf_to_ug
import numpy as np
import pyvista as pv
import geopandas as gpd
from shapely.geometry import Point, LineString, Polygon

Create geodataframes from points, lines and polygon shapefiles

[2]:
gdf_points = gpd.read_file('./data_gis/wellPoints.shp')
gdf_lines = gpd.read_file('./data_gis/contoursLines.shp')
gdf_polygons = gpd.read_file('./data_gis/lakesPolygons.shp')

Merge all datasets into a single geodataframe

[3]:
gdf = gdf_points.append(gdf_lines)
gdf = gdf.append(gdf_polygons)

Convert to an unstructured grid

[4]:
unstructured_grid = gdf_to_ug(gdf, elevation='Elev')
unstructured_grid
[4]:
HeaderData Arrays
UnstructuredGridInformation
N Cells693
N Points228530
X Bounds4.544e+05, 6.429e+05
Y Bounds4.777e+06, 4.887e+06
Z Bounds6.512e+02, 2.600e+03
N Arrays1
NameFieldTypeN CompMinMax
ElevationCellsfloat6416.512e+022.600e+03

Display the unstructured grid

[5]:
unstructured_grid.plot(jupyter_backend='static')
../../_images/examples_basic_Topo_-_Convert_a_geopandas_geodataframe_to_a_pyvista_unstructured_grid_9_0.png

Save the unstructured grid into a VTK file

[6]:
unstructured_grid.save('./tmp_files/test.vtu', binary=False)