Skip to content

Commit

Permalink
Merge pull request #841 from opengisch/delete-data
Browse files Browse the repository at this point in the history
Delete before import
  • Loading branch information
signedav authored Dec 13, 2023
2 parents a8a5898 + 9540452 commit f171fe5
Show file tree
Hide file tree
Showing 17 changed files with 1,532 additions and 19 deletions.
22 changes: 18 additions & 4 deletions QgisModelBaker/gui/panel/session_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(
baskets,
export_models,
db_action_type,
delete_data,
parent=None,
):
super().__init__(parent)
Expand All @@ -70,6 +71,7 @@ def __init__(
self.datasets = datasets
self.baskets = baskets
self.export_models = export_models
self.delete_data = delete_data

# set up the gui
self.create_text = self.tr("Run")
Expand Down Expand Up @@ -130,24 +132,36 @@ def __init__(
self.tr(
"""
<html><head/><body>
<p>Update the data in dataset <b>{dataset}</b></p>
<p>{update_word} the data in dataset <b>{dataset}</b></p>
<p>with the data from <i>{file}</i></p>
</body></html>
"""
).format(dataset=self.datasets[0], file=self.file)
).format(
update_word=self.tr("Update")
if not self.delete_data
else self.tr("Replace"),
dataset=self.datasets[0],
file=self.file,
)
)
else:
self.info_label.setText(
self.tr(
"""
<html><head/><body>
<p>Import the data from <i>{file}</i></p>
<p>{import_word} the data from <i>{file}</i></p>
</body></html>
"""
).format(file=self.file)
).format(
import_word=self.tr("Import")
if not self.delete_data
else self.tr("Delete existing data and import"),
file=self.file,
)
)

self.configuration.dataset = self.datasets[0] if self.datasets else None
self.configuration.delete_data = self.delete_data
elif self.db_action_type == DbActionType.EXPORT:
self.configuration.xtffile = self.file
self.configuration.with_exporttid = self._get_tid_handling()
Expand Down
6 changes: 5 additions & 1 deletion QgisModelBaker/gui/workflow_wizard/execution_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,14 @@ def setup_sessions(self, configuration, sessions):
sessions[key]["datasets"] if "datasets" in sessions[key] else None
)
baskets = sessions[key]["baskets"] if "baskets" in sessions[key] else None

export_models = (
sessions[key]["export_models"]
if "export_models" in sessions[key]
else None
)
delete_data = (
sessions[key]["delete_data"] if "delete_data" in sessions[key] else None
)

skipped_session_widget = self._find_skipped_session_widget(
(
Expand All @@ -111,6 +113,7 @@ def setup_sessions(self, configuration, sessions):
baskets,
export_models,
db_utils.get_schema_identificator_from_configuration(configuration),
delete_data,
)
)
if skipped_session_widget:
Expand All @@ -124,6 +127,7 @@ def setup_sessions(self, configuration, sessions):
baskets,
export_models,
self.db_action_type,
delete_data,
)
session.on_done_or_skipped.connect(self._on_done_or_skipped_received)
session.print_info.connect(self.workflow_wizard.log_panel.print_info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,20 @@ def __init__(self, parent, title):
self.remove_button.setIcon(QgsApplication.getThemeIcon("/symbologyRemove.svg"))

self.workflow_wizard.import_data_file_model.sourceModel().setHorizontalHeaderLabels(
[self.tr("Import File"), self.tr("Catalogue"), self.tr("Dataset")]
[
self.tr("Import File"),
self.tr("Delete"),
self.tr("Catalogue"),
self.tr("Dataset"),
]
)
self.file_table_view.setModel(self.workflow_wizard.import_data_file_model)
self.file_table_view.horizontalHeader().setSectionResizeMode(
gui_utils.SourceModel.Columns.SOURCE, QHeaderView.Stretch
)
self.file_table_view.horizontalHeader().setSectionResizeMode(
gui_utils.SourceModel.Columns.DELETE_DATA, QHeaderView.ResizeToContents
)
self.file_table_view.horizontalHeader().setSectionResizeMode(
gui_utils.SourceModel.Columns.IS_CATALOGUE, QHeaderView.ResizeToContents
)
Expand Down Expand Up @@ -227,6 +235,11 @@ def setup_dialog(self, basket_handling):
gui_utils.SourceModel.Columns.DATASET, True
)
self.datasetmanager_button.setHidden(True)

self.file_table_view.setItemDelegateForColumn(
gui_utils.SourceModel.Columns.DELETE_DATA,
CheckDelegate(self, role=gui_utils.SourceModel.Roles.DELETE_DATA),
)
self._update_referencedata_completer()

def _set_basket_defaults(self):
Expand Down Expand Up @@ -256,10 +269,17 @@ def _set_basket_defaults(self):
is_xml,
int(gui_utils.SourceModel.Roles.IS_CATALOGUE),
)
self.workflow_wizard.source_model.setData(
self.workflow_wizard.source_model.index(
row, gui_utils.SourceModel.Columns.DELETE_DATA
),
False,
int(gui_utils.SourceModel.Roles.DELETE_DATA),
)

self.file_table_view.setItemDelegateForColumn(
gui_utils.SourceModel.Columns.IS_CATALOGUE,
CheckDelegate(self, gui_utils.SourceModel.Roles.IS_CATALOGUE),
CheckDelegate(self, role=gui_utils.SourceModel.Roles.IS_CATALOGUE),
)
self.file_table_view.setItemDelegateForColumn(
gui_utils.SourceModel.Columns.DATASET,
Expand Down
28 changes: 25 additions & 3 deletions QgisModelBaker/utils/gui_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,16 @@ class Roles(Enum):
DATASET_NAME = Qt.UserRole + 5
IS_CATALOGUE = Qt.UserRole + 6
ORIGIN_INFO = Qt.UserRole + 7
DELETE_DATA = Qt.UserRole + 8

def __int__(self):
return self.value

class Columns(IntEnum):
SOURCE = 0
IS_CATALOGUE = 1
DATASET = 2
DELETE_DATA = 1
IS_CATALOGUE = 2
DATASET = 3

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -375,6 +377,16 @@ def data(self, index, role):
f"../images/file_types/{type}.png",
)
)
if role == Qt.ToolTipRole:
if index.column() == SourceModel.Columns.IS_CATALOGUE:
return self.tr(
"If the data is a catalog, it is imported into the corresponding dataset (called catalogueset)."
)
if index.column() == SourceModel.Columns.DELETE_DATA:
return self.tr(
"If activated, the existing data is deleted before the import."
)

return item.data(int(role))

def add_source(self, name, type, path, origin_info=None):
Expand All @@ -401,6 +413,10 @@ def setData(self, index, data, role):
return QStandardItemModel.setData(
self, index, data, int(SourceModel.Roles.IS_CATALOGUE)
)
if index.column() == SourceModel.Columns.DELETE_DATA:
return QStandardItemModel.setData(
self, index, data, int(SourceModel.Roles.DELETE_DATA)
)
if index.column() == SourceModel.Columns.DATASET:
return QStandardItemModel.setData(
self, index, data, int(SourceModel.Roles.DATASET_NAME)
Expand Down Expand Up @@ -784,6 +800,8 @@ def __init__(self):
def flags(self, index):
if index.column() == SourceModel.Columns.IS_CATALOGUE:
return Qt.ItemIsEnabled
if index.column() == SourceModel.Columns.DELETE_DATA:
return Qt.ItemIsEnabled
if index.column() == SourceModel.Columns.DATASET:
if self.index(index.row(), SourceModel.Columns.IS_CATALOGUE).data(
int(SourceModel.Roles.IS_CATALOGUE)
Expand All @@ -799,6 +817,9 @@ def import_sessions(self, order_list) -> dict():
source = self.index(r, SourceModel.Columns.SOURCE).data(
int(SourceModel.Roles.PATH)
)
delete_data = self.index(r, SourceModel.Columns.DELETE_DATA).data(
int(SourceModel.Roles.DELETE_DATA)
)
is_catalogue = self.index(r, SourceModel.Columns.IS_CATALOGUE).data(
int(SourceModel.Roles.IS_CATALOGUE)
)
Expand All @@ -810,7 +831,8 @@ def import_sessions(self, order_list) -> dict():
else CATALOGUE_DATASETNAME
)
sessions[source] = {}
sessions[source]["datasets"] = [dataset]
sessions[source]["datasets"] = [dataset] if dataset else []
sessions[source]["delete_data"] = delete_data
i += 1
return sessions

Expand Down
Binary file modified docs/assets/baskets_dataset_manager.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/workflow_wizard_data_import.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions docs/background_info/basket_handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@ VERSION "2020-06-22" =
OID AS INTERLIS.UUIDOID;
CLASS Buildings =
Code : MANDATORY TEXT*15;
Description : MANDATORY TEXT*99;
Address : Address;
Geometry: Surface;
Description : TEXT*99;
Geometry : Surface;
END Buildings;
CLASS Street =
Code : MANDATORY TEXT*15;
Description : MANDATORY TEXT*99;
Address : Address;
Geometry: Line;
Name : MANDATORY TEXT*99;
Geometry : Line;
END Street;
END Constructions;
Expand Down Expand Up @@ -101,7 +98,10 @@ These are basicly the data in a dataset. You might already notice the `BID` fiel

We need to import the data of Ul Qoma now into our physical model with the ili2db parameter `--dataset "Ul Qoma"`. When the dataset already exists in the physical database we do not make an `--import`, but an `--update` instead. This means all the data in this dataset are updated with the data from the `xtf` file (and removed if not existent there).

With the Model Baker we do make generally an `--update`, because we import only into exiting datasets.
With the Model Baker we do make generally an `--update`, , as we only import into existing datasets. If you want to delete all the data from this dataset first (even from baskets other than those contained in the transfer file), you can check the corresponding box. In this case, a `--replace` command will be executed instead.

!!! Note
The difference between a `--replace` and an `--update` is that the one hand with an `--update` the baskets that are not contained in the transferfile remain untouched and on the other hand the technical ids remain the physical database (because we "update"), whereas with a `--replace` the are freshly created (because here we "delete" and "insert"). This means these two commands could trigger different backend functions (e.g. trigger functions on PostgreSQL).

### Dataset Manager

Expand Down
51 changes: 51 additions & 0 deletions docs/demodata/GL_Wildruhezonen_V1_2020-03-31.ili
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
INTERLIS 2.3;

!! Version | Modification
!!----------------------------------------------------------------------------------------
!! 2020-03-13 | Erste Modellversion; Import/Erweiterung MGDM BAFU

!!@ IDGeoIV="195.1, 195.2"
!!@ technicalContact=mailto:[email protected]
!!@ furtherInformation=https://models.geo.gl.ch/pdf/GL_Wildruhezonen_V1.pdf
MODEL GL_Wildruhezonen_Codelisten_V1 (de)
AT "https://www.gl.ch"
VERSION "2020-03-13" =
IMPORTS CatalogueObjects_V1,Wildruhezonen_Codelisten_V2_1;

TOPIC Codelisten EXTENDS Wildruhezonen_Codelisten_V2_1.Codelisten =

/** Katalog der Zielarten Schutzbestimmung */
CLASS Zielarten_Catalogue EXTENDS CatalogueObjects_V1.Catalogues.Item =
/** Bezeichnung der Zielarten */
Bezeichnung : MANDATORY TEXT;
END Zielarten_Catalogue;

STRUCTURE Zielarten_CatRef EXTENDS CatalogueObjects_V1.Catalogues.MandatoryCatalogueReference =
Reference (EXTENDED) : MANDATORY REFERENCE TO (EXTERNAL) Zielarten_Catalogue;
END Zielarten_CatRef;

END Codelisten;

END GL_Wildruhezonen_Codelisten_V1.


!!@ IDGeoIV="195.1, 195.2"
!!@ technicalContact=mailto:[email protected]
!!@ furtherInformation=https://models.geo.gl.ch/pdf/GL_Wildruhezonen_V1.pdf
MODEL GL_Wildruhezonen_V1 (de)
AT "https://www.gl.ch"
VERSION "2020-03-13" =
IMPORTS GL_Wildruhezonen_Codelisten_V1,Wildruhezonen_LV95_V2_1;

TOPIC Wildruhezonen EXTENDS Wildruhezonen_LV95_V2_1.Wildruhezonen =
OID AS INTERLIS.UUIDOID;
DEPENDS ON GL_Wildruhezonen_Codelisten_V1.Codelisten;

CLASS Wildruhezone (EXTENDED) =
/** Zuordnung der Zielarten Schutzbestimmung zur Wildruhezone */
Zielart: GL_Wildruhezonen_Codelisten_V1.Codelisten.Zielarten_CatRef;
END Wildruhezone;

END Wildruhezonen;

END GL_Wildruhezonen_V1.
10 changes: 10 additions & 0 deletions docs/demodata/GL_Wildruhezonen_Zielarten.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?><TRANSFER xmlns="http://www.interlis.ch/INTERLIS2.3">
<HEADERSECTION SENDER="ili2pg-4.4.1-e9ddc1895e1a7f13ff029644af1442ddb79dcaa4" VERSION="2.3"><MODELS><MODEL NAME="CatalogueObjects_V1" VERSION="2011-08-30" URI="http://www.geo.admin.ch"></MODEL><MODEL NAME="CatalogueObjectTrees_V1" VERSION="2011-08-30" URI="http://www.geo.admin.ch"></MODEL><MODEL NAME="Units" VERSION="2012-02-20" URI="http://www.interlis.ch/models"></MODEL><MODEL NAME="CoordSys" VERSION="2015-11-24" URI="http://www.interlis.ch/models"></MODEL><MODEL NAME="InternationalCodes_V1" VERSION="2011-08-30" URI="http://www.geo.admin.ch"></MODEL><MODEL NAME="Localisation_V1" VERSION="2011-08-30" URI="http://www.geo.admin.ch"></MODEL><MODEL NAME="LocalisationCH_V1" VERSION="2011-08-30" URI="http://www.geo.admin.ch"></MODEL><MODEL NAME="Dictionaries_V1" VERSION="2011-08-30" URI="http://www.geo.admin.ch"></MODEL><MODEL NAME="DictionariesCH_V1" VERSION="2011-08-30" URI="http://www.geo.admin.ch"></MODEL><MODEL NAME="GeometryCHLV03_V1" VERSION="2017-12-04" URI="http://www.geo.admin.ch"></MODEL><MODEL NAME="GeometryCHLV95_V1" VERSION="2017-12-04" URI="http://www.geo.admin.ch"></MODEL><MODEL NAME="CHAdminCodes_V1" VERSION="2018-02-19" URI="http://www.geo.admin.ch"></MODEL><MODEL NAME="AdministrativeUnits_V1" VERSION="2011-08-30" URI="http://www.geo.admin.ch"></MODEL><MODEL NAME="AdministrativeUnitsCH_V1" VERSION="2020-04-24" URI="http://www.geo.admin.ch"></MODEL><MODEL NAME="Wildruhezonen_Codelisten_V2_1" VERSION="2020-01-23" URI="https://models.geo.admin.ch/BAFU/"></MODEL><MODEL NAME="Wildruhezonen_LV03_V2_1" VERSION="2020-04-21" URI="https://models.geo.admin.ch/BAFU/"></MODEL><MODEL NAME="Wildruhezonen_LV95_V2_1" VERSION="2020-04-21" URI="https://models.geo.admin.ch/BAFU/"></MODEL><MODEL NAME="GL_Wildruhezonen_Codelisten_V1" VERSION="2020-03-13" URI="https://www.gl.ch"></MODEL><MODEL NAME="GL_Wildruhezonen_V1" VERSION="2020-03-13" URI="https://www.gl.ch"></MODEL></MODELS></HEADERSECTION>
<DATASECTION>
<GL_Wildruhezonen_Codelisten_V1.Codelisten BID="31">
<GL_Wildruhezonen_Codelisten_V1.Codelisten.Zielarten_Catalogue TID="301d3d98-a7b0-4895-a2e2-5afe8c44d429"><Bezeichnung>Schalenwild und Raufusshühner</Bezeichnung></GL_Wildruhezonen_Codelisten_V1.Codelisten.Zielarten_Catalogue>
<GL_Wildruhezonen_Codelisten_V1.Codelisten.Zielarten_Catalogue TID="22ee2088-23b4-489f-a852-4543b2cf418a"><Bezeichnung>Raufusshühner</Bezeichnung></GL_Wildruhezonen_Codelisten_V1.Codelisten.Zielarten_Catalogue>
<GL_Wildruhezonen_Codelisten_V1.Codelisten.Zielarten_Catalogue TID="6de51dc5-d288-4b44-b419-565fbd409c98"><Bezeichnung>Schalenwild</Bezeichnung></GL_Wildruhezonen_Codelisten_V1.Codelisten.Zielarten_Catalogue>
</GL_Wildruhezonen_Codelisten_V1.Codelisten>
</DATASECTION>
</TRANSFER>
46 changes: 46 additions & 0 deletions docs/demodata/TheCityAndTheCity_V1.ili
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
INTERLIS 2.3;

MODEL City_V1 (en)
AT "https://modelbaker.ch"
VERSION "2020-06-22" =
IMPORTS GeometryCHLV95_V1;

DOMAIN
Line = POLYLINE WITH (STRAIGHTS) VERTEX GeometryCHLV95_V1.Coord2;
Surface = SURFACE WITH (STRAIGHTS) VERTEX GeometryCHLV95_V1.Coord2 WITHOUT OVERLAPS > 0.005;

STRUCTURE Address =
Street: TEXT;
Number: TEXT;
END Address;

TOPIC Constructions =
BASKET OID AS INTERLIS.UUIDOID;
OID AS INTERLIS.UUIDOID;

CLASS Buildings =
Address : Address;
Description : TEXT*99;
Geometry : Surface;
END Buildings;

CLASS Street =
Name : MANDATORY TEXT*99;
Geometry : Line;
END Street;

END Constructions;

TOPIC Nature =
BASKET OID AS INTERLIS.UUIDOID;
OID AS INTERLIS.UUIDOID;

CLASS Parks =
Name : MANDATORY TEXT*99;
Address : Address;
Geometry: Surface;
END Parks;

END Nature;

END City_V1.
Loading

0 comments on commit f171fe5

Please sign in to comment.