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

Concern multiple geometries per GeoPackage Table Frontend #970

Merged
merged 8 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
48 changes: 48 additions & 0 deletions QgisModelBaker/gui/ili2db_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
"""<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>
<p>This function is not standardized and such tables with multiple geometries require <span style=" font-weight:600;">GDAL version &gt;= 3.8</span> to run in QGIS (yours is <span style=" font-weight:600;">{gdal_version}</span>, but note that others with lower 3.8 versions <span style=" font-weight:600;">will not be able </span>to read such tables in the created QGIS project.)</p>
</body></html>""".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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand All @@ -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))

Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
42 changes: 42 additions & 0 deletions QgisModelBaker/gui/workflow_wizard/project_creation_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import re

import yaml
from osgeo import gdal
from qgis.core import Qgis, QgsApplication, QgsProject
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import QCompleter, QWizardPage
Expand Down Expand Up @@ -95,6 +96,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
Expand Down Expand Up @@ -130,6 +132,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):
Expand Down Expand Up @@ -735,6 +739,44 @@ 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(
"""
<html><head/><body style="background-color:powderblue;">
<p><b>This GeoPackage contains at least one table with multiple geometries</b></p>
<p>These tables require <span style=" font-weight:600;">GDAL version &gt;= 3.8</span> to run in QGIS, yours is <span style=" font-weight:600;">{gdal_version}</span>.</p>
<p>Means this won't work.</p>
</body></html>
""".format(
qgis_version=Qgis.QGIS_VERSION,
gdal_version=gdal.VersionInfo("RELEASE_NAME"),
)
)
self.create_project_button.setDisabled(True)
else:
self.gpkg_multigeometry_label.setText(
"""
<html><head/><body style="background-color:powderblue;">
<p><b>This GeoPackage contains at least one table with multiple geometries</b></p>
<p>These tables require <span style=" font-weight:600;">GDAL version &gt;= 3.8</span> to run in QGIS, yours is <span style=" font-weight:600;">{gdal_version}</span>.</p>
<p>But note that others with lower 3.8 version <span style=" font-weight:600;">will not be able</span> to read such tables in the created QGIS project.</p>
</body></html>
""".format(
qgis_version=Qgis.QGIS_VERSION,
gdal_version=gdal.VersionInfo("RELEASE_NAME"),
)
)
return True

def help_text(self):
logline = self.tr(
"Most of the time you won't need to change anything here.<br />Just press Generate :-)"
Expand Down
Loading