Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run post-process_agv.py #172

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
# %%
cloud = CloudStorage()
cloud.download_verwerkt(waterschap)

# cloud.download_basisgegevens()
# cloud.download_aangeleverd("Rijkswaterstaat")
cloud.download_verwerkt("Rijkswaterstaat")
cloud.download_basisgegevens()

# %%
verwerkt_dir = cloud.joinpath(waterschap, "verwerkt")
Expand All @@ -37,13 +36,6 @@
# Hoofdwatersysteem boundaries
hws_path = cloud.joinpath("Rijkswaterstaat/verwerkt/krw_basins_vlakken.gpkg")

# Buffer boundaries
buffer_path = cloud.joinpath("Rijkswaterstaat/verwerkt/hws_buffer_agv.gpkg")

# Buffer RWHS
rhws_path = cloud.joinpath("Rijkswaterstaat/verwerkt/agv_rhws_buffer.gpkg")


# %% Load Files
# Load HHNK files
AVG = read_gpkg_layers(
Expand All @@ -55,7 +47,7 @@
"duikersifonhevel",
"peilgebied",
"streefpeil",
"aggregation_area",
"afsluitmiddel",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We hebben er voor gekozen om niet met Afsluitmiddel data te werken, dus die kan er uit blijven. aggregation_area is daarentegen wel vereist om mee te geven. Dus als dat terug gezet kan worden is het klaar om gemerged te worden.

],
)
AVG["peilgebied"] = AVG["peilgebied"].to_crs("EPSG:28992")
Expand All @@ -66,18 +58,8 @@
# Load hws
gdf_hws = gpd.read_file(hws_path)

# Load buffer
gdf_buffer = gpd.read_file(buffer_path)
gdf_buffer = gdf_buffer.to_crs("EPSG:28992")
gdf_buffer = gdf_buffer.dissolve()

# Load rhws
# gdf_rhws = gpd.read_file(rhws_path)
# gdf_rhws = gdf_rhws.to_crs('EPSG:28992')
# gdf_rhws = gdf_rhws.dissolve()

# %%
AVG["peilgebied"].globalid.is_unique
assert AVG["peilgebied"].globalid.is_unique

# Select waterschap boundaries and clip hws layer

Expand All @@ -89,9 +71,6 @@
# Use waterschap boundaries to clip HWS layer
gdf_hws = gpd.overlay(gdf_grens, gdf_hws, how="intersection")

# Use waterschap boundaries to clip HWS layer
# gdf_rhws = gpd.overlay(gdf_grens, gdf_rhws, how='intersection')

# Peilgebied and HWS layer overlap:
# 1. Identify the overlapping areas
# 2. Clip
Expand Down Expand Up @@ -122,42 +101,16 @@
peilgebieden_cat = []

for index, row in AVG["peilgebied"].iterrows():
# if row.code == "Oosterpark" or row.code == "Vechtboezem":
if "Oosterpark" in row.code or "Vechtboezem" in row.code or "Stadsboezem Amsterdam" in row.code:
print("true")

print(f"true {row.code}")
peilgebieden_cat.append(1)
else:
peilgebieden_cat.append(0)

# Add new column and drop old HWS_BZM column
AVG["peilgebied"]["peilgebied_cat"] = peilgebieden_cat

# %% Add rhws to ['peilgebied','streefpeil']
# update peilgebied dict key
# gdf_rhws['globalid'] = 'dummy_globalid_rhws_' + gdf_rhws.index.astype(str)
# gdf_rhws['code'] = 'dummy_code_nhws_' + gdf_rhws.index.astype(str)
# gdf_rhws['nen3610id'] = 'dummy_nen3610id_rhws_' + gdf_rhws.index.astype(str)
# gdf_rhws['peilgebied_cat'] = 1

# gdf_rhws = gdf_rhws[['globalid', 'code', 'nen3610id', 'peilgebied_cat', 'geometry']]

# AVG['peilgebied'] = pd.concat([gdf_rhws, AVG['peilgebied']])

# %%
# # Create boezem streefpeil layer
# streefpeil_hws = pd.DataFrame()
# streefpeil_hws['waterhoogte'] = [np.nan] * len(gdf_rhws)
# streefpeil_hws['globalid'] = 'dummy_globalid_rhws_' + gdf_rhws.index.astype(str)
# streefpeil_hws['geometry'] = [None]* len(gdf_rhws)

# AVG['streefpeil'] = pd.concat([streefpeil_hws, AVG['streefpeil']])
# AVG['streefpeil'] = gpd.GeoDataFrame(AVG['streefpeil'])

# Add nhws to ['peilgebied','streefpeil']

# %%
# update peilgebied dict key
# %% update peilgebied dict key
gdf_hws["globalid"] = "dummy_globalid_nhws_" + gdf_hws.index.astype(str)
gdf_hws["code"] = "dummy_code_nhws_" + gdf_hws.index.astype(str)
gdf_hws["nen3610id"] = "dummy_nen3610id_nhws_" + gdf_hws.index.astype(str)
Expand All @@ -167,8 +120,7 @@

AVG["peilgebied"] = pd.concat([gdf_hws, AVG["peilgebied"]])

# %%
# Create boezem streefpeil layer
# %% Create boezem streefpeil layer
streefpeil_hws = pd.DataFrame()
streefpeil_hws["waterhoogte"] = [np.nan] * len(gdf_hws)
streefpeil_hws["globalid"] = "dummy_globalid_nhws_" + gdf_hws.index.astype(str)
Expand All @@ -177,44 +129,6 @@
AVG["streefpeil"] = pd.concat([streefpeil_hws, AVG["streefpeil"]])
AVG["streefpeil"] = gpd.GeoDataFrame(AVG["streefpeil"])

# %% Create buffer polygon between NHWS and peilgebied/RHWS
# buffer_polygon = gdf_buffer.geometry.iat[0].intersection(gdf_grens.geometry.iat[0])
# buffer_polygon = buffer_polygon.difference(shapely.geometry.MultiPolygon(gdf_hws.geometry.tolist()))
# buffer_polygon = buffer_polygon.difference(shapely.ops.unary_union(AVG['peilgebied'].geometry.tolist()))

# buffer_polygon = gpd.GeoDataFrame(buffer_polygon)
# buffer_polygon = buffer_polygon.set_geometry(0)
# buffer_polygon = buffer_polygon.dissolve()
# buffer_polygon = buffer_polygon.rename(columns={0:'geometry'})
# buffer_polygon = buffer_polygon.set_geometry('geometry')
# buffer_polygon = buffer_polygon.set_crs('EPSG:28992')


# %% Add buffer to ['peilgebied','streefpeil']

# update peilgebied dict key
# buffer_polygon = gpd.GeoDataFrame(buffer_polygon)
# buffer_polygon['globalid'] = 'dummy_globalid_nhws_buffer_' + buffer_polygon.index.astype(str)
# buffer_polygon['code'] = 'dummy_code_nhws_buffer_' + buffer_polygon.index.astype(str)
# buffer_polygon['nen3610id'] = 'dummy_nen3610id_nhws_buffer_' + buffer_polygon.index.astype(str)
# buffer_polygon['peilgebied_cat'] = 2
# buffer_polygon = buffer_polygon.rename(columns={0:'geometry'})
# buffer_polygon = buffer_polygon[['globalid', 'code', 'nen3610id', 'peilgebied_cat', 'geometry']]

# AVG['peilgebied'] = pd.concat([buffer_polygon, AVG['peilgebied']])
# AVG['peilgebied'] = gpd.GeoDataFrame(AVG['peilgebied'])

# %%
# # Create boezem streefpeil layer
# streefpeil_buffer = pd.DataFrame()
# streefpeil_buffer['waterhoogte'] = [np.nan]
# streefpeil_buffer['globalid'] = 'dummy_globalid_nhws_buffer_' + buffer_polygon.index.astype(str)
# streefpeil_buffer['geometry'] = [None]


# AVG['streefpeil'] = pd.concat([streefpeil_buffer, AVG['streefpeil']])
# AVG['streefpeil'] = gpd.GeoDataFrame(AVG['streefpeil'])

# %%
if remove_cat_2:
AVG["peilgebied"] = AVG["peilgebied"].loc[AVG["peilgebied"].peilgebied_cat != 2]
Expand All @@ -227,6 +141,6 @@
print(key)
AVG[str(key)].to_file(output_gpkg_path, layer=str(key), driver="GPKG")

cloud.upload_verwerkt(output_gpkg_path)
cloud.upload_verwerkt(waterschap)
# %%
AVG["peilgebied"]["peilgebied_cat"].unique()
Loading