Topo - Convert a geopandas geodataframe to a pyvista unstructured grid¶
O. KAUFMANN, 2021.
gdf_to_ug is based on ideas from https://hatarilabs.com/ih-en/tutorial-to-convert-geospatial-data-shapefile-to-3d-data-vtk-with-python-geopandas-pyvista
[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]:
Header | Data Arrays | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
Save the unstructured grid into a VTK file¶
[6]:
unstructured_grid.save('./tmp_files/test.vtu', binary=False)