I have a .wkt file that is multilinestring and has 3D data, I want to display it in Python, and I used the following code for this purpose.
import geopandas as gpd
from shapely.wkt import loads
from shapely.geometry import MultiLineString
def display_3d_wkt(file_path):
# Read .wkt file into a GeoDataFrame
geometry = loads(open(file_path).read())
gdf = gpd.GeoDataFrame(geometry=[MultiLineString], geometry_column='geometry')
# Create a 3D plot using Mayavi
from mayavi import mlab
# Extract coordinates from MultiLineString
x, y, z = zip(*geometry.coords.xy)
# Create a Mayavi 3D plot
mlab.figure()
mlab.plot3d(x, y, z, tube_radius=0.1)
# Show the 3D plot
mlab.show()
# Specify the .wkt file path
wkt_file_path = "expanded_skeleton4.wkt"
# Display the content of the .wkt file in 3D
display_3d_wkt(wkt_file_path)
And I get the following error. What should I do to fix it? enter image description here
I also used this code:
mayavi import mlab
from shapely.wkt import loads
def display_3d_wkt(file_path):
# Read .wkt file into a Shapely geometry
geometry = loads(open(file_path).read())
# Check if the geometry is a collection of geometries (multi-part)
if geometry.geom_type.startswith('Multi'):
# Iterate over each part of the multi-part geometry
for part in geometry:
display_3d_part(part)
else:
# Display the single-part geometry
display_3d_part(geometry)
def display_3d_part(geometry):
# Extract coordinates from the geometry
x, y, z = zip(*geometry.coords.xy)
# Create a Mayavi 3D plot
mlab.figure()
mlab.plot3d(x, y, z, tube_radius=0.1)
# Show the 3D plot
mlab.show()
# Specify the .wkt file path
wkt_file_path = "path/to/your/file.wkt"
# Display the content of the .wkt file in 3D
display_3d_wkt(wkt_file_path)
And I got the following error:type error: 'MultiLineString' object is not iterable