diff --git a/QgisModelBaker/gui/ili2db_options.py b/QgisModelBaker/gui/ili2db_options.py index d4fa8a377..7859c18d3 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,21 @@ 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) + else: + self.create_gpkg_multigeom_groupbox.setHidden(False) + 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 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"), + ) + ) + self.bar = QgsMessageBar() self.bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) self.layout().addWidget(self.bar, 0, 0, Qt.AlignTop) @@ -177,6 +194,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 +235,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 +253,21 @@ 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) + 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)) @@ -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/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() diff --git a/QgisModelBaker/gui/workflow_wizard/project_creation_page.py b/QgisModelBaker/gui/workflow_wizard/project_creation_page.py index 013a20e85..f2efe478a 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_frame.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_frame.setVisible(self._multigeom_gpkg()) + self.workflow_wizard.busy(self, False) def _use_existing(self, state): @@ -712,6 +716,50 @@ 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: + 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: + 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): + 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.