From 4571319481aaf09527f7c1d47997ec8ca75a4bc3 Mon Sep 17 00:00:00 2001 From: Martijn Visser Date: Mon, 25 Mar 2024 22:39:24 +0100 Subject: [PATCH] Set the Node fid back to the node_id --- python/ribasim/ribasim/model.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/python/ribasim/ribasim/model.py b/python/ribasim/ribasim/model.py index d0faaeb12..30c39270a 100644 --- a/python/ribasim/ribasim/model.py +++ b/python/ribasim/ribasim/model.py @@ -3,6 +3,7 @@ from pathlib import Path from typing import Any +import geopandas as gpd import pandas as pd import tomli import tomli_w @@ -138,6 +139,16 @@ def _save(self, directory: DirectoryPath, input_dir: DirectoryPath): for sub in self._nodes(): sub._save(directory, input_dir) + # Temporarily require unique node_id for #1262 + # and copy them to the fid for #1306. + df = gpd.read_file(db_path, layer="Node") + if not df["node_id"].is_unique: + raise ValueError("node_id must be unique") + df.set_index("node_id", drop=False, inplace=True) + df.sort_index(inplace=True) + df.index.name = "fid" + df.to_file(db_path, layer="Node", driver="GPKG", index=True) + def node_table(self) -> NodeTable: """Compute the full NodeTable from all node types.""" df_chunks = [node.node.df for node in self._nodes()]