base_network: return zero underwater fraction if no link geometry given (closes #53)

fixes #53
This commit is contained in:
Fabian Neumann 2019-08-11 16:59:56 +02:00 committed by GitHub
parent 4a6355265b
commit f7159de47f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -412,6 +412,9 @@ def _replace_b2b_converter_at_country_border_by_link(n):
def _set_links_underwater_fraction(n):
if n.links.empty: return
if not hasattr(n.links, 'geometry'):
n.links['underwater_fraction'] = 0.
else:
offshore_shape = gpd.read_file(snakemake.input.offshore_shapes).unary_union
links = gpd.GeoSeries(n.links.geometry.dropna().map(shapely.wkt.loads))
n.links['underwater_fraction'] = links.intersection(offshore_shape).length / links.length