import pandas as pd
import geopandas as gpd
import mikeio
ds = mikeio.read("../tests/testdata/wind_north_sea.dfsu")
ws = ds["Wind speed"][0]
ws.plot();
shp = ds.geometry.to_shapely()
type(shp)
shapely.geometry.multipolygon.MultiPolygon
Geopandas does not like multipolygon, it should be a list of polygons
poly_list = [p for p in shp.geoms]
df = pd.DataFrame({'wind_speed':ws.to_numpy()})
df.head()
wind_speed | |
---|---|
0 | 9.530760 |
1 | 9.652719 |
2 | 9.806072 |
3 | 8.775489 |
4 | 11.013206 |
gdf = gpd.GeoDataFrame(df,geometry=poly_list, crs=4326)
gdf.to_file("wind_speed.shp")
Would you prefer to have this workflow to be a method on the mikeio.Dfsu
class?
Post an issue on GitHub !
import os
files = ["wind_speed"]
exts = ["cpg","dbf","shp","shx"]
for file in files:
for ext in exts:
filename = f"{file}.{ext}"
if os.path.exists(filename):
os.remove(filename)