Skip to content

Commit dbd87a0

Browse files
remove fiona from all functions
1 parent 31a483c commit dbd87a0

4 files changed

Lines changed: 37 additions & 39 deletions

File tree

docsrc/conf.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,17 @@
2727
tls_verify = False
2828
# using mock to avoid nodepy documentation which is hard to import
2929
# and to reduce time with the spatial stack
30-
autodoc_mock_imports = ["nodepy","gdal","osgeo","rasterio","fiona","pyproj",
31-
"geopandas","shapely","netCDF4","rtree","param"
30+
autodoc_mock_imports = [
31+
"nodepy",
32+
"gdal",
33+
"osgeo",
34+
"rasterio",
35+
"pyproj",
36+
"geopandas",
37+
"shapely",
38+
"netCDF4",
39+
"rtree",
40+
"param",
3241
]
3342
# -- General configuration ---------------------------------------------
3443

schimpy/convert_linestrings.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from schimpy.prepare_schism import get_structures_from_yaml
88
from schimpy.schism_setup import check_and_suggest
99
from schimpy.util.yaml_load import yaml_from_file
10-
import fiona
1110
from shapely.geometry import LineString, mapping
1211
import click
1312

@@ -23,21 +22,20 @@ def convert_structures_main(input_yaml, output_fn):
2322
inputs = yaml_from_file(input_yaml)
2423
structures = inputs.get("structures")
2524
structures = get_structures_from_yaml(structures)
26-
with fiona.open(
27-
output_fn, "w", driver="ESRI Shapefile", schema=schema, crs="EPSG:26910"
28-
) as shp:
29-
for struct in structures:
30-
line = LineString(struct["end_points"])
31-
shp.write(
32-
{
33-
"geometry": mapping(line),
34-
"properties": {
35-
"name": struct["name"],
36-
"type": struct["type"],
37-
"configuration": str(struct["configuration"]),
38-
},
39-
}
40-
)
25+
# Build GeoDataFrame
26+
gdf = gpd.GeoDataFrame(
27+
[
28+
{
29+
"geometry": LineString(struct["end_points"]),
30+
"name": struct["name"],
31+
"type": struct["type"],
32+
"configuration": str(struct["configuration"]),
33+
}
34+
for struct in structures
35+
],
36+
crs="EPSG:26910",
37+
)
38+
gdf.to_file(output_fn, driver="ESRI Shapefile")
4139
else:
4240
raise ValueError(
4341
"Unsupported input file type. Only YAML (.yaml) supported for structures."

schimpy/convert_points.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,22 @@
22
# -*- coding: utf-8 -*-
33
"""Command line tool to convert SCHISM points (source and sink) in YAML to Shapefile"""
44
import click
5-
import fiona
5+
import geopandas as gpd
6+
import pandas as pd
7+
from shapely.geometry import Point
68

79

810
def df_to_shp(fpath, df):
9-
"""Convert a DataFrame to a Shapefile."""
10-
# Open a fiona object
11-
pointShp = fiona.open(
12-
fpath,
13-
mode="w",
14-
driver="ESRI Shapefile",
15-
schema={"geometry": "Point", "properties": [("site", "str"), ("stype", "str")]},
11+
"""Convert a DataFrame to a Shapefile using geopandas."""
12+
gdf = gpd.GeoDataFrame(
13+
df,
14+
geometry=[Point(row.x, row.y) for _, row in df.iterrows()],
1615
crs="EPSG:26910",
1716
)
18-
19-
for index, row in df.iterrows():
20-
rowDict = {
21-
"geometry": {"type": "Point", "coordinates": (row.x, row.y)},
22-
"properties": {"site": row.sites, "stype": row.stype},
23-
}
24-
pointShp.write(rowDict)
25-
26-
pointShp.close()
17+
# Only keep relevant columns
18+
gdf = gdf[["geometry", "sites", "stype"]]
19+
gdf = gdf.rename(columns={"sites": "site"})
20+
gdf.to_file(fpath, driver="ESRI Shapefile")
2721

2822

2923
def read_points(fpath):

schimpy/mesh_volume_tvd.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,8 @@
6161

6262
try:
6363
from shapely.geometry import Point, LineString, mapping
64-
import fiona
6564
except Exception:
66-
raise SystemExit(
67-
"This script requires shapely and fiona (pip install shapely, pip install fiona)."
68-
)
65+
raise SystemExit("This script requires shapely (pip install shapely).")
6966

7067
EdgeLabel = str # 'deep' | 'shore'
7168

0 commit comments

Comments
 (0)