Skip to content

Commit

Permalink
Merge pull request #138 from Samweli/geometry_check
Browse files Browse the repository at this point in the history
Added geometry check for imported project instances
  • Loading branch information
Samweli authored Dec 4, 2024
2 parents aacd88b + 1b84700 commit d4fa451
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
24 changes: 18 additions & 6 deletions src/qgis_gea_plugin/gui/attribute_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
"""

import os
from datetime import datetime


from qgis.PyQt import QtCore, QtGui, QtWidgets

Expand Down Expand Up @@ -50,6 +48,7 @@ def __init__(
QtCore.Qt.WindowMinimizeButtonHint | QtCore.Qt.WindowCloseButtonHint
)
self.setupUi(self)
self.parent = parent
self.layer = layer

self.project_cmb_box.addItems(PROJECT_AREAS)
Expand Down Expand Up @@ -123,9 +122,19 @@ def accept(self):
# Set attribute values
feature_area = "-"
geom = feature.geometry()
if geom is not None and geom.isGeosValid():
area = geom.area() / 10000
feature_area = f"{area:,.2f}"

if geom is None or not geom.isGeosValid():
self.parent.show_message(
tr(
"Skipped a feature with "
"an invalid geometry."
)
)
feature = next(features, None)
continue

area = geom.area() / 10000
feature_area = f"{area:,.2f}"

feature.setAttribute(
"author",
Expand All @@ -135,7 +144,10 @@ def accept(self):
"project",
self.project_cmb_box.currentText()
)
feature.setAttribute("area (ha)", feature_area)
feature.setAttribute(
"area (ha)",
feature_area
)

self.layer.updateFeature(feature)
# Retrieve the next feature
Expand Down
26 changes: 23 additions & 3 deletions src/qgis_gea_plugin/gui/qgis_gea.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@
QgsPalLayerSettings,
QgsProject,
QgsTask,
QgsTextBackgroundSettings,
QgsTextFormat,
QgsTemporalNavigationObject,
QgsUnitTypes,
QgsVectorFileWriter,
QgsVectorLayer,
QgsVectorLayerEditUtils,
QgsVectorLayerSimpleLabeling,

QgsWkbTypes
)

from qgis.gui import QgsLayerTreeView, QgsMessageBar
Expand Down Expand Up @@ -325,7 +324,28 @@ def project_instances_changed(self):
self.load_attribute_form(layer)

def load_attribute_form(self, layer):
attribute_form = AttributeForm(layer)

wkb_type = layer.wkbType()

if Qgis.QGIS_VERSION_INT < 33000:
geometry_type = QgsWkbTypes.geometryType(wkb_type)
layer_type = geometry_type == QgsWkbTypes.PolygonGeometry
else:
layer_type = QgsWkbTypes.flatType(wkb_type) in (
QgsWkbTypes.Polygon,
QgsWkbTypes.MultiPolygon
)

if not layer_type:
self.show_message(
tr(
"Selected layer doesn't "
"have a polygon geometry type."
)
)
return

attribute_form = AttributeForm(layer, parent=self)
attribute_form.exec_()

def project_folder_changed(self):
Expand Down

0 comments on commit d4fa451

Please sign in to comment.