From 5c4a3ff31b70eb3f6c2fe7a3b239fcf3541adb79 Mon Sep 17 00:00:00 2001 From: signedav Date: Mon, 21 Oct 2024 13:08:38 +0200 Subject: [PATCH 1/4] Multiple Geometries on Geopackage ili2db parameter --- QgisModelBaker/gui/ili2db_options.py | 48 ++++++++ QgisModelBaker/ui/ili2db_options.ui | 165 +++++++++++++++------------ 2 files changed, 140 insertions(+), 73 deletions(-) diff --git a/QgisModelBaker/gui/ili2db_options.py b/QgisModelBaker/gui/ili2db_options.py index d4fa8a377..a4cdb31e9 100644 --- a/QgisModelBaker/gui/ili2db_options.py +++ b/QgisModelBaker/gui/ili2db_options.py @@ -16,6 +16,8 @@ * * ***************************************************************************/ """ +from osgeo import gdal +from qgis.core import Qgis from qgis.gui import QgsGui, QgsMessageBar from qgis.PyQt.QtCore import QSettings, Qt from qgis.PyQt.QtGui import QValidator @@ -137,6 +139,26 @@ def __init__(self, parent=None, remove_create_tid_group=True): self.create_import_tid_groupbox.setHidden(remove_create_tid_group) + # on gdal versions that dont support multiple geometries per table it's disabled + if int(gdal.VersionInfo("VERSION_NUM")) < 3080000: + self.create_gpkg_multigeom_groupbox.setHidden(True) + self.create_gpkg_multigeom_checkbox.setChecked(False) + else: + self.create_gpkg_multigeom_groupbox.setHidden(False) + self.create_gpkg_multigeom_checkbox.setChecked( + False + ) # maybe in future this could be true... + self.create_gpkg_multigeom_checkbox.setToolTip( + """ +

If the INTERLIS model has classes that contain multiple geometries, tables with multiple geometry columns can be created in GeoPackage.

+


This function is not standardized and requires GDAL version >= 3.8 to run in QGIS (your current QGIS version is {qgis_version} with GDAL {gdal_version}, but note that others with lower 3.8 versions will not be able to read this GeoPackage or create a QGIS project from it.

+ """.format( + qgis_version=Qgis.QGIS_VERSION, + gdal_version=gdal.VersionInfo("RELEASE_NAME"), + ) + ) + self.bar = QgsMessageBar() self.bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) self.layout().addWidget(self.bar, 0, 0, Qt.AlignTop) @@ -177,6 +199,9 @@ def create_import_tid(self): def create_basket_col(self): return self.create_basket_col_checkbox.isChecked() + def create_gpkg_multigeom(self): + return self.create_gpkg_multigeom_checkbox.isChecked() + def inheritance_type(self): if self.smart1_radio_button.isChecked(): return "smart1" @@ -215,6 +240,9 @@ def save_configuration(self): settings.setValue( "QgisModelBaker/ili2db/create_import_tid", self.create_import_tid() ) + settings.setValue( + "QgisModelBaker/ili2db/create_gpkg_multigeom", self.create_gpkg_multigeom() + ) settings.setValue("QgisModelBaker/ili2db/stroke_arcs", self.stroke_arcs()) def restore_configuration(self): @@ -230,12 +258,16 @@ def restore_configuration(self): create_import_tid = settings.value( "QgisModelBaker/ili2db/create_import_tid", defaultValue=True, type=bool ) + create_gpkg_multigeom = settings.value( + "QgisModelBaker/ili2db/create_gpkg_multigeom", defaultValue=True, type=bool + ) stroke_arcs = settings.value( "QgisModelBaker/ili2db/stroke_arcs", defaultValue=True, type=bool ) self.create_basket_col_checkbox.setChecked(create_basket_col) self.create_import_tid_checkbox.setChecked(create_import_tid) + self.create_gpkg_multigeom_checkbox.setChecked(create_gpkg_multigeom) self.stroke_arcs_checkbox.setChecked(stroke_arcs) self.toml_file_line_edit.setText(settings.value(self.toml_file_key)) @@ -258,6 +290,10 @@ def load_metaconfig(self, metaconfig_ili2db): self.create_import_tid_checkbox.setChecked( self.current_metaconfig_ili2db.getboolean("importTid") ) + if "gpkgMultiGeomPerTable" in self.current_metaconfig_ili2db: + self.create_gpkg_multigeom.setChecked( + self.current_metaconfig_ili2db.getboolean("gpkgMultiGeomPerTable") + ) if "strokeArcs" in self.current_metaconfig_ili2db: self.stroke_arcs_checkbox.setChecked( self.current_metaconfig_ili2db.getboolean("strokeArcs") @@ -333,6 +369,18 @@ def _restyle_concerning_metaconfig(self): self.create_import_tid_checkbox.setStyleSheet( f"color:{self.COLOR_WARNING}" ) + if "gpkgMultiGeomPerTable" in self.current_metaconfig_ili2db: + if ( + self.current_metaconfig_ili2db.getboolean("gpkgMultiGeomPerTable") + == self.create_gpkg_multigeom_checkbox.isChecked() + ): + self.create_gpkg_multigeom_checkbox.setStyleSheet( + f"color:{self.COLOR_TOPPING}" + ) + else: + self.create_gpkg_multigeom_checkbox.setStyleSheet( + f"color:{self.COLOR_WARNING}" + ) if "strokeArcs" in self.current_metaconfig_ili2db: if ( self.current_metaconfig_ili2db.getboolean("strokeArcs") diff --git a/QgisModelBaker/ui/ili2db_options.ui b/QgisModelBaker/ui/ili2db_options.ui index 57c255756..58d91fc58 100644 --- a/QgisModelBaker/ui/ili2db_options.ui +++ b/QgisModelBaker/ui/ili2db_options.ui @@ -7,7 +7,7 @@ 0 0 552 - 557 + 622 @@ -17,62 +17,58 @@ true - - - - Stroke arcs + + + + <html><head/><body><p><span style=" font-size:large; color:#341d5c;">▪ </span><span style=" color:#341d5c;">corresponds to the metaconfig </span><span style=" font-size:large; color:#c64600;">▪ </span><span style=" color:#c64600;">deviates from the metaconfig</span></p></body></html> + + + Qt::RichText - - - - - If this option is activated, circular arcs are stroked when importing the data - - - Stroke Arcs - - - - - - + + - Inheritance type + Create Import Tid - - - + + + - Form the inheritance hierarchy with a dynamic strategy. The NewClass strategy is used for classes that are -referenced and whose base classes are not mapped using a NewClass strategy. Abstract classes are mapped -using a SubClass strategy. Concrete classes, without a base class or their direct base classes with a SubClass -strategy are mapped using a NewClass strategy. All other classes are mapped using a SuperClass strategy. + <html><head/><body><p>Creates a new column t_ili_tid in all classes, which is mandatory and should be unique, not only for across the current database, but across the whole system.</p><p>Normally you should not enable this option directly, but rely on the INTERLIS model and ili2db. The former should have a line enabling OIDs (preferably with UUIDs) and the latter will make sure the database updates the new column every time a new record is created.</p><p><br/></p></body></html> - smart1Inheritance + Create Import Tid true - - + + + + + + + Create Basket Column + + + + - Form the inheritance hierarchy with a dymamic strategy. Abstract classes are mapped using a SubClass -strategy. Concrete classes are mapped using a NewAndSubClass strategy. + <html><head/><body><p>Creates a new column t_basket in class tables which references entries in the additional table t_ili2db_basket.</p><p>The T_basket column needs to be filled with the basket to which an object belongs.</p><p><span style=" font-weight:600;">Warning</span></p><p>If this option is enabled, it is required to make sure that this column is filled by the database, by default values on QGIS side or manually from the user.</p><p>If<span style=" font-style:italic;"> BASKET OID</span> is defined in the model, it's required to use the basket handling in QGIS. This is currently not automatically detected by the Model Baker and needs to be assured by the user.</p></body></html> - smart2Inheritance + Create Basket Column - + SQL scripts @@ -141,7 +137,36 @@ strategy. Concrete classes are mapped using a NewAndSubClass strategy. - + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Stroke arcs + + + + + + If this option is activated, circular arcs are stroked when importing the data + + + Stroke Arcs + + + + + + + QFrame::StyledPanel @@ -180,67 +205,61 @@ strategy. Concrete classes are mapped using a NewAndSubClass strategy. - - + + - Create Basket Column + Inheritance type - - - + + + - <html><head/><body><p>Creates a new column t_basket in class tables which references entries in the additional table t_ili2db_basket.</p><p>The T_basket column needs to be filled with the basket to which an object belongs.</p><p><span style=" font-weight:600;">Warning</span></p><p>If this option is enabled, it is required to make sure that this column is filled by the database, by default values on QGIS side or manually from the user.</p><p>If<span style=" font-style:italic;"> BASKET OID</span> is defined in the model, it's required to use the basket handling in QGIS. This is currently not automatically detected by the Model Baker and needs to be assured by the user.</p></body></html> + Form the inheritance hierarchy with a dynamic strategy. The NewClass strategy is used for classes that are +referenced and whose base classes are not mapped using a NewClass strategy. Abstract classes are mapped +using a SubClass strategy. Concrete classes, without a base class or their direct base classes with a SubClass +strategy are mapped using a NewClass strategy. All other classes are mapped using a SuperClass strategy. - Create Basket Column + smart1Inheritance + + + true + + + + + + + Form the inheritance hierarchy with a dymamic strategy. Abstract classes are mapped using a SubClass +strategy. Concrete classes are mapped using a NewAndSubClass strategy. + + + smart2Inheritance - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - + + - Create Import Tid + Multiple Geometries per Table in GeoPackage - + - + - <html><head/><body><p>Creates a new column t_ili_tid in all classes, which is mandatory and should be unique, not only for across the current database, but across the whole system.</p><p>Normally you should not enable this option directly, but rely on the INTERLIS model and ili2db. The former should have a line enabling OIDs (preferably with UUIDs) and the latter will make sure the database updates the new column every time a new record is created.</p><p><br/></p></body></html> + <html><head/><body><p>If the INTERLIS model has classes that contain <span style=" font-weight:600;">multiple geometries</span>, tables with multiple geometry columns can be created in <span style=" font-weight:600;">GeoPackage</span>.</p></body></html> - Create Import Tid - - - true + Create Multiple Geometry Columns per Table - - - - <html><head/><body><p><span style=" font-size:large; color:#341d5c;">▪ </span><span style=" color:#341d5c;">corresponds to the metaconfig </span><span style=" font-size:large; color:#c64600;">▪ </span><span style=" color:#c64600;">deviates from the metaconfig</span></p></body></html> - - - Qt::RichText - - - From 7930ffa1c215c2f6241f82721e8e9c90d7725ee0 Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 25 Oct 2024 16:58:35 +0200 Subject: [PATCH 2/4] add setting for multigeom on gpkg --- QgisModelBaker/gui/ili2db_options.py | 16 ++++++++-------- .../import_schema_configuration_page.py | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/QgisModelBaker/gui/ili2db_options.py b/QgisModelBaker/gui/ili2db_options.py index a4cdb31e9..7859c18d3 100644 --- a/QgisModelBaker/gui/ili2db_options.py +++ b/QgisModelBaker/gui/ili2db_options.py @@ -142,17 +142,12 @@ def __init__(self, parent=None, remove_create_tid_group=True): # on gdal versions that dont support multiple geometries per table it's disabled if int(gdal.VersionInfo("VERSION_NUM")) < 3080000: self.create_gpkg_multigeom_groupbox.setHidden(True) - self.create_gpkg_multigeom_checkbox.setChecked(False) else: self.create_gpkg_multigeom_groupbox.setHidden(False) - self.create_gpkg_multigeom_checkbox.setChecked( - False - ) # maybe in future this could be true... self.create_gpkg_multigeom_checkbox.setToolTip( """

If the INTERLIS model has classes that contain multiple geometries, tables with multiple geometry columns can be created in GeoPackage.

-


This function is not standardized and requires GDAL version >= 3.8 to run in QGIS (your current QGIS version is {qgis_version} with GDAL {gdal_version}, but note that others with lower 3.8 versions will not be able to read this GeoPackage or create a QGIS project from it.

+

This function is not standardized and such tables with multiple geometries require GDAL version >= 3.8 to run in QGIS (your current QGIS version is {qgis_version} with GDAL {gdal_version}, but note that others with lower 3.8 versions will not be able to read such tables in the created QGIS project.

""".format( qgis_version=Qgis.QGIS_VERSION, gdal_version=gdal.VersionInfo("RELEASE_NAME"), @@ -259,7 +254,9 @@ def restore_configuration(self): "QgisModelBaker/ili2db/create_import_tid", defaultValue=True, type=bool ) create_gpkg_multigeom = settings.value( - "QgisModelBaker/ili2db/create_gpkg_multigeom", defaultValue=True, type=bool + "QgisModelBaker/ili2db/create_gpkg_multigeom", + defaultValue=True, + type=bool, ) stroke_arcs = settings.value( "QgisModelBaker/ili2db/stroke_arcs", defaultValue=True, type=bool @@ -267,7 +264,10 @@ def restore_configuration(self): self.create_basket_col_checkbox.setChecked(create_basket_col) self.create_import_tid_checkbox.setChecked(create_import_tid) - self.create_gpkg_multigeom_checkbox.setChecked(create_gpkg_multigeom) + if int(gdal.VersionInfo("VERSION_NUM")) >= 3080000: + self.create_gpkg_multigeom_checkbox.setChecked(create_gpkg_multigeom) + else: + self.create_gpkg_multigeom_checkbox.setChecked(False) self.stroke_arcs_checkbox.setChecked(stroke_arcs) self.toml_file_line_edit.setText(settings.value(self.toml_file_key)) diff --git a/QgisModelBaker/gui/workflow_wizard/import_schema_configuration_page.py b/QgisModelBaker/gui/workflow_wizard/import_schema_configuration_page.py index 837f2ee65..cbc847daf 100644 --- a/QgisModelBaker/gui/workflow_wizard/import_schema_configuration_page.py +++ b/QgisModelBaker/gui/workflow_wizard/import_schema_configuration_page.py @@ -136,6 +136,9 @@ def update_configuration(self, configuration): configuration.inheritance = self.ili2db_options.inheritance_type() configuration.create_basket_col = self.ili2db_options.create_basket_col() configuration.create_import_tid = self.ili2db_options.create_import_tid() + configuration.create_gpkg_multigeom = ( + self.ili2db_options.create_gpkg_multigeom() + ) configuration.stroke_arcs = self.ili2db_options.stroke_arcs() configuration.pre_script = self.ili2db_options.pre_script() configuration.post_script = self.ili2db_options.post_script() From 848ce1778e5877a5844c1c62c5af57730d86c4bd Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 25 Oct 2024 16:59:09 +0200 Subject: [PATCH 3/4] warning on create project - needs to be finalized --- .../workflow_wizard/project_creation_page.py | 30 +++++++++++ .../ui/workflow_wizard/project_creation.ui | 51 +++++++++++-------- 2 files changed, 59 insertions(+), 22 deletions(-) diff --git a/QgisModelBaker/gui/workflow_wizard/project_creation_page.py b/QgisModelBaker/gui/workflow_wizard/project_creation_page.py index 013a20e85..d2df9aecf 100644 --- a/QgisModelBaker/gui/workflow_wizard/project_creation_page.py +++ b/QgisModelBaker/gui/workflow_wizard/project_creation_page.py @@ -22,6 +22,7 @@ import re import yaml +from osgeo import gdal from qgis.core import Qgis, QgsProject from qgis.PyQt.QtCore import Qt from qgis.PyQt.QtWidgets import QCompleter, QWizardPage @@ -93,6 +94,7 @@ def __init__(self, parent, title): self.fileValidator = gui_utils.FileValidator( pattern=["*." + ext for ext in self.ValidExtensions], allow_empty=False ) + self.gpkg_multigeometry_info.setVisible(False) def isComplete(self): return self.is_complete @@ -125,6 +127,8 @@ def restore_configuration(self, configuration): else: self._use_existing(False) + self.gpkg_multigeometry_info.setVisible(self._multigeom_gpkg()) + self.workflow_wizard.busy(self, False) def _use_existing(self, state): @@ -712,6 +716,32 @@ def _inheritance(self): if setting_record["tag"] == "ch.ehi.ili2db.inheritanceTrafo": return setting_record["setting"] + def _multigeom_gpkg(self): + # this concerns only geopackage + if not (self.workflow_wizard.import_schema_configuration.tool & DbIliMode.gpkg): + return False + + # and when this geopackage has multiple geometry columns in a table + if len(self.db_connector.multiple_geometry_tables()) == 0: + return False + + if int(gdal.VersionInfo("VERSION_NUM")) < 3080000: + # if our GDAL is not able to handle, we tell it and maybe block the project creation + self.gpkg_multigeometry_info.setText("Oh oh, this is not gonna work") + else: + # if our GDAL is able to handle, we give a warning that others might not be able to read the project + self.gpkg_multigeometry_info.setText( + "It's gonna work but be aware of..." + ) + + return True + + def _multiple_geometry_gpkg_table(self): + if self.db_connector.multiple_geometry_tables() > 0: + return True + + return false + def help_text(self): logline = self.tr( "Most of the time you won't need to change anything here.
Just press Generate :-)" diff --git a/QgisModelBaker/ui/workflow_wizard/project_creation.ui b/QgisModelBaker/ui/workflow_wizard/project_creation.ui index 4478ecc5f..72b66e96e 100644 --- a/QgisModelBaker/ui/workflow_wizard/project_creation.ui +++ b/QgisModelBaker/ui/workflow_wizard/project_creation.ui @@ -14,18 +14,12 @@ Select Files - - - - Qt::Horizontal - - - - 40 - 20 - + + + + Generate - +
@@ -92,6 +86,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -117,7 +124,7 @@ - + Qt::Vertical @@ -130,13 +137,6 @@ - - - - 0 - - - @@ -190,10 +190,17 @@ - - + + + + 0 + + + + + - Generate + GPKG info From 5db55f5bad66c271decb1990d2bed01e026bcd1e Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 25 Oct 2024 21:58:59 +0200 Subject: [PATCH 4/4] nice box in gui and text --- .../workflow_wizard/project_creation_page.py | 34 ++++-- .../ui/workflow_wizard/project_creation.ui | 105 +++++++++++------- 2 files changed, 89 insertions(+), 50 deletions(-) diff --git a/QgisModelBaker/gui/workflow_wizard/project_creation_page.py b/QgisModelBaker/gui/workflow_wizard/project_creation_page.py index d2df9aecf..f2efe478a 100644 --- a/QgisModelBaker/gui/workflow_wizard/project_creation_page.py +++ b/QgisModelBaker/gui/workflow_wizard/project_creation_page.py @@ -94,7 +94,7 @@ def __init__(self, parent, title): self.fileValidator = gui_utils.FileValidator( pattern=["*." + ext for ext in self.ValidExtensions], allow_empty=False ) - self.gpkg_multigeometry_info.setVisible(False) + self.gpkg_multigeometry_frame.setVisible(False) def isComplete(self): return self.is_complete @@ -127,7 +127,7 @@ def restore_configuration(self, configuration): else: self._use_existing(False) - self.gpkg_multigeometry_info.setVisible(self._multigeom_gpkg()) + self.gpkg_multigeometry_frame.setVisible(self._multigeom_gpkg()) self.workflow_wizard.busy(self, False) @@ -726,14 +726,32 @@ def _multigeom_gpkg(self): return False if int(gdal.VersionInfo("VERSION_NUM")) < 3080000: - # if our GDAL is not able to handle, we tell it and maybe block the project creation - self.gpkg_multigeometry_info.setText("Oh oh, this is not gonna work") + self.gpkg_multigeometry_label.setText( + """ + +

This GeoPackage contains at least one table with multiple geometries

+

These tables require GDAL version >= 3.8 to run in QGIS.
Your current QGIS version is {qgis_version} with GDAL {gdal_version}.

+

Means this won't work.

+ + """.format( + qgis_version=Qgis.QGIS_VERSION, + gdal_version=gdal.VersionInfo("RELEASE_NAME"), + ) + ) + self.create_project_button.setDisabled(True) else: - # if our GDAL is able to handle, we give a warning that others might not be able to read the project - self.gpkg_multigeometry_info.setText( - "It's gonna work but be aware of..." + self.gpkg_multigeometry_label.setText( + """ + +

This GeoPackage contains at least one table with multiple geometries

+

These tables require GDAL version >= 3.8 to run in QGIS.
Your current QGIS version is {qgis_version} with GDAL {gdal_version}.

+

But note that others with lower 3.8 version will not be able to read such tables in the created QGIS project.

+ + """.format( + qgis_version=Qgis.QGIS_VERSION, + gdal_version=gdal.VersionInfo("RELEASE_NAME"), + ) ) - return True def _multiple_geometry_gpkg_table(self): diff --git a/QgisModelBaker/ui/workflow_wizard/project_creation.ui b/QgisModelBaker/ui/workflow_wizard/project_creation.ui index 72b66e96e..ae71b09b2 100644 --- a/QgisModelBaker/ui/workflow_wizard/project_creation.ui +++ b/QgisModelBaker/ui/workflow_wizard/project_creation.ui @@ -14,6 +14,31 @@ Select Files + + + + + 0 + 0 + + + + + 75 + true + + + + Generate a QGIS Project from an existing database. + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + @@ -99,44 +124,6 @@ - - - - - 0 - 0 - - - - - 75 - true - - - - Generate a QGIS Project from an existing database. - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - @@ -197,11 +184,45 @@ - - - - GPKG info + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + background-color: rgb(255, 200, 0); + + + QFrame::StyledPanel + + QFrame::Raised + + + + + + + + + GPKG info + + + true + + + +