diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 5c2262c..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Python: QGIS Plugin", - "type": "python", - "request": "attach", - "port": 5678, - "host": "localhost" - } - ] -} \ No newline at end of file diff --git a/los_tools/__init__.py b/los_tools/__init__.py index 5422d2b..056720c 100755 --- a/los_tools/__init__.py +++ b/los_tools/__init__.py @@ -26,7 +26,7 @@ __date__ = "2020-03-05" __copyright__ = "(C) 2020 by Jan Caha" -from .los_tools_plugin import LoSToolsPlugin +from los_tools.los_tools_plugin import LoSToolsPlugin # noinspection PyPep8Naming diff --git a/los_tools/constants/fields.py b/los_tools/constants/fields.py index 21ffb31..7bb434f 100644 --- a/los_tools/constants/fields.py +++ b/los_tools/constants/fields.py @@ -1,27 +1,21 @@ -from qgis.core import Qgis, QgsField, QgsFields -from qgis.PyQt.QtCore import QMetaType, QVariant +from qgis.core import QgsField, QgsFields from los_tools.constants.field_names import FieldNames +from los_tools.utils import COLUMN_TYPE, COLUMN_TYPE_STRING class Fields: - if Qgis.versionInt() >= 33800: - source_type = QMetaType.Type - source_type_string = source_type.QString - else: - source_type = QVariant.Type - source_type_string = source_type.String - - _field_azimuth = QgsField(FieldNames.AZIMUTH, source_type.Double) - _field_angle_step = QgsField(FieldNames.ANGLE_STEP, source_type.Double) - _field_observer_x = QgsField(FieldNames.OBSERVER_X, source_type.Double) - _field_observer_y = QgsField(FieldNames.OBSERVER_Y, source_type.Double) + + _field_azimuth = QgsField(FieldNames.AZIMUTH, COLUMN_TYPE.Double) + _field_angle_step = QgsField(FieldNames.ANGLE_STEP, COLUMN_TYPE.Double) + _field_observer_x = QgsField(FieldNames.OBSERVER_X, COLUMN_TYPE.Double) + _field_observer_y = QgsField(FieldNames.OBSERVER_Y, COLUMN_TYPE.Double) _base_fields = QgsFields() - _base_fields.append(QgsField(FieldNames.LOS_TYPE, source_type_string)) - _base_fields.append(QgsField(FieldNames.ID_OBSERVER, source_type.Int)) - _base_fields.append(QgsField(FieldNames.ID_TARGET, source_type.Int)) - _base_fields.append(QgsField(FieldNames.OBSERVER_OFFSET, source_type.Double)) + _base_fields.append(QgsField(FieldNames.LOS_TYPE, COLUMN_TYPE_STRING)) + _base_fields.append(QgsField(FieldNames.ID_OBSERVER, COLUMN_TYPE.Int)) + _base_fields.append(QgsField(FieldNames.ID_TARGET, COLUMN_TYPE.Int)) + _base_fields.append(QgsField(FieldNames.OBSERVER_OFFSET, COLUMN_TYPE.Double)) los_notarget_fields = QgsFields(_base_fields) los_notarget_fields.append(_field_azimuth) @@ -31,11 +25,11 @@ class Fields: los_local_fields = QgsFields(_base_fields) - los_local_fields.append(QgsField(FieldNames.TARGET_OFFSET, source_type.Double)) + los_local_fields.append(QgsField(FieldNames.TARGET_OFFSET, COLUMN_TYPE.Double)) los_global_fields = QgsFields(los_local_fields) - los_global_fields.append(QgsField(FieldNames.TARGET_X, source_type.Double)) - los_global_fields.append(QgsField(FieldNames.TARGET_Y, source_type.Double)) + los_global_fields.append(QgsField(FieldNames.TARGET_X, COLUMN_TYPE.Double)) + los_global_fields.append(QgsField(FieldNames.TARGET_Y, COLUMN_TYPE.Double)) los_plugin_layer_fields = QgsFields(los_global_fields) los_plugin_layer_fields.append(_field_azimuth) diff --git a/los_tools/gui/dialog_los_settings.py b/los_tools/gui/dialog_los_settings.py index bac4a9e..aa64173 100755 --- a/los_tools/gui/dialog_los_settings.py +++ b/los_tools/gui/dialog_los_settings.py @@ -11,9 +11,8 @@ QgsProject, QgsUnitTypes, QgsVectorLayer, - QgsWkbTypes, ) -from qgis.PyQt.QtCore import QMetaType, Qt, QVariant +from qgis.PyQt.QtCore import Qt from qgis.PyQt.QtWidgets import ( QCheckBox, QComboBox, @@ -30,16 +29,11 @@ QWidget, ) +from los_tools.utils import _column_type_class + from ..constants.field_names import FieldNames from .custom_classes import Distance, DistanceWidget -if Qgis.versionInt() >= 33800: - source_type = QMetaType.Type - source_type_string = source_type.QString -else: - source_type = QVariant.Type - source_type_string = source_type.String - class LoSSettings(QDialog): def __init__( @@ -270,12 +264,12 @@ def create_data_layer(self) -> QgsVectorLayer: size_field_name = FieldNames.TEMPLATE_SIZE.replace("?", unit_name) fields = QgsFields() - fields.append(QgsField(FieldNames.SIZE_ANGLE, QVariant.Double)) - fields.append(QgsField(distance_field_name, QVariant.Double)) - fields.append(QgsField(size_field_name, QVariant.Double)) + fields.append(QgsField(FieldNames.SIZE_ANGLE, _column_type_class().Double)) + fields.append(QgsField(distance_field_name, _column_type_class().Double)) + fields.append(QgsField(size_field_name, _column_type_class().Double)) layer = QgsMemoryProviderUtils.createMemoryLayer( - "Sampling Table", fields=fields, geometryType=QgsWkbTypes.NoGeometry + "Sampling Table", fields=fields, geometryType=Qgis.WkbType.NoGeometry ) angle = self.object_angle_size.value() diff --git a/los_tools/processing/analyse_los/tool_analyse_los.py b/los_tools/processing/analyse_los/tool_analyse_los.py index 0e1e1ce..1e0c685 100644 --- a/los_tools/processing/analyse_los/tool_analyse_los.py +++ b/los_tools/processing/analyse_los/tool_analyse_los.py @@ -17,13 +17,12 @@ QgsProcessingUtils, QgsVectorLayer, ) -from qgis.PyQt.QtCore import QVariant from los_tools.classes.classes_los import LoSGlobal, LoSLocal, LoSWithoutTarget from los_tools.constants.field_names import FieldNames from los_tools.constants.names_constants import NamesConstants from los_tools.processing.tools.util_functions import get_los_type -from los_tools.utils import get_doc_file +from los_tools.utils import COLUMN_TYPE, get_doc_file class AnalyseLosAlgorithm(QgsProcessingAlgorithm): @@ -98,28 +97,28 @@ def processAlgorithm(self, parameters, context: QgsProcessingContext, feedback: fields.append(QgsField(attribute.name(), attribute.type())) if los_type == NamesConstants.LOS_LOCAL: - fields.append(QgsField(FieldNames.VISIBLE, QVariant.Bool)) - fields.append(QgsField(FieldNames.VIEWING_ANGLE, QVariant.Double)) - fields.append(QgsField(FieldNames.ELEVATION_DIFF, QVariant.Double)) - fields.append(QgsField(FieldNames.ANGLE_DIFF_LH, QVariant.Double)) - fields.append(QgsField(FieldNames.ELEVATION_DIFF_LH, QVariant.Double)) - fields.append(QgsField(FieldNames.SLOPE_DIFFERENCE_LH, QVariant.Double)) - fields.append(QgsField(FieldNames.HORIZON_COUNT, QVariant.Int)) - fields.append(QgsField(FieldNames.DISTANCE_LH, QVariant.Double)) - # los_layer.addAttribute(QgsField(FieldNames.FUZZY_VISIBILITY, QVariant.Double)) + fields.append(QgsField(FieldNames.VISIBLE, COLUMN_TYPE.Bool)) + fields.append(QgsField(FieldNames.VIEWING_ANGLE, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.ELEVATION_DIFF, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.ANGLE_DIFF_LH, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.ELEVATION_DIFF_LH, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.SLOPE_DIFFERENCE_LH, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.HORIZON_COUNT, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.DISTANCE_LH, COLUMN_TYPE.Double)) + # los_layer.addAttribute(QgsField(FieldNames.FUZZY_VISIBILITY, COLUMN_TYPE.Double)) elif los_type == NamesConstants.LOS_GLOBAL: - fields.append(QgsField(FieldNames.VISIBLE, QVariant.Bool)) - fields.append(QgsField(FieldNames.ANGLE_DIFF_GH, QVariant.Double)) - fields.append(QgsField(FieldNames.ELEVATION_DIFF_GH, QVariant.Double)) - fields.append(QgsField(FieldNames.HORIZON_COUNT_BEHIND, QVariant.Int)) - fields.append(QgsField(FieldNames.DISTANCE_GH, QVariant.Double)) + fields.append(QgsField(FieldNames.VISIBLE, COLUMN_TYPE.Bool)) + fields.append(QgsField(FieldNames.ANGLE_DIFF_GH, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.ELEVATION_DIFF_GH, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.HORIZON_COUNT_BEHIND, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.DISTANCE_GH, COLUMN_TYPE.Double)) elif los_type == NamesConstants.LOS_NO_TARGET: - fields.append(QgsField(FieldNames.MAXIMAL_VERTICAL_ANGLE, QVariant.Double)) - fields.append(QgsField(FieldNames.DISTANCE_GH, QVariant.Double)) - fields.append(QgsField(FieldNames.DISTANCE_LH, QVariant.Double)) - fields.append(QgsField(FieldNames.VERTICAL_ANGLE_LH, QVariant.Double)) + fields.append(QgsField(FieldNames.MAXIMAL_VERTICAL_ANGLE, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.DISTANCE_GH, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.DISTANCE_LH, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.VERTICAL_ANGLE_LH, COLUMN_TYPE.Double)) sink, dest_id = self.parameterAsSink( parameters, diff --git a/los_tools/processing/analyse_los/tool_extract_los_visibility_parts.py b/los_tools/processing/analyse_los/tool_extract_los_visibility_parts.py index 6764bd5..754699f 100644 --- a/los_tools/processing/analyse_los/tool_extract_los_visibility_parts.py +++ b/los_tools/processing/analyse_los/tool_extract_los_visibility_parts.py @@ -20,14 +20,14 @@ QgsVectorLayer, QgsWkbTypes, ) -from qgis.PyQt.QtCore import Qt, QVariant +from qgis.PyQt.QtCore import Qt from los_tools.classes.classes_los import LoSGlobal, LoSLocal, LoSWithoutTarget from los_tools.constants.field_names import FieldNames from los_tools.constants.names_constants import NamesConstants from los_tools.constants.textlabels import TextLabels from los_tools.processing.tools.util_functions import get_los_type -from los_tools.utils import get_doc_file +from los_tools.utils import COLUMN_TYPE, get_doc_file class ExtractLoSVisibilityPartsAlgorithm(QgsProcessingAlgorithm): @@ -108,9 +108,9 @@ def processAlgorithm(self, parameters, context, feedback): los_type = get_los_type(los_layer, field_names) fields = QgsFields() - fields.append(QgsField(FieldNames.ID_OBSERVER, QVariant.Int)) - fields.append(QgsField(FieldNames.ID_TARGET, QVariant.Int)) - fields.append(QgsField(FieldNames.VISIBLE, QVariant.Bool)) + fields.append(QgsField(FieldNames.ID_OBSERVER, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.ID_TARGET, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.VISIBLE, COLUMN_TYPE.Bool)) sink, self.dest_id = self.parameterAsSink( parameters, diff --git a/los_tools/processing/analyse_los/tool_extract_los_visibility_polygons.py b/los_tools/processing/analyse_los/tool_extract_los_visibility_polygons.py index dc2db47..817d688 100644 --- a/los_tools/processing/analyse_los/tool_extract_los_visibility_polygons.py +++ b/los_tools/processing/analyse_los/tool_extract_los_visibility_polygons.py @@ -23,14 +23,14 @@ QgsVectorLayer, QgsWkbTypes, ) -from qgis.PyQt.QtCore import Qt, QVariant +from qgis.PyQt.QtCore import Qt from los_tools.classes.classes_los import LoSWithoutTarget from los_tools.constants.field_names import FieldNames from los_tools.constants.names_constants import NamesConstants from los_tools.constants.textlabels import TextLabels from los_tools.processing.tools.util_functions import get_los_type, line_to_polygon -from los_tools.utils import get_doc_file +from los_tools.utils import COLUMN_TYPE, get_doc_file class ExtractLoSVisibilityPolygonsAlgorithm(QgsProcessingAlgorithm): @@ -114,9 +114,9 @@ def processAlgorithm(self, parameters, context, feedback: QgsProcessingFeedback) los_type = get_los_type(los_layer, field_names) fields = QgsFields() - fields.append(QgsField(FieldNames.ID_OBSERVER, QVariant.Int)) - fields.append(QgsField(FieldNames.ID_TARGET, QVariant.Int)) - fields.append(QgsField(FieldNames.VISIBLE, QVariant.Bool)) + fields.append(QgsField(FieldNames.ID_OBSERVER, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.ID_TARGET, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.VISIBLE, COLUMN_TYPE.Bool)) sink, self.dest_id = self.parameterAsSink( parameters, diff --git a/los_tools/processing/analyse_los/tool_extract_points_los.py b/los_tools/processing/analyse_los/tool_extract_points_los.py index b627c72..b8cdfbb 100644 --- a/los_tools/processing/analyse_los/tool_extract_points_los.py +++ b/los_tools/processing/analyse_los/tool_extract_points_los.py @@ -18,14 +18,14 @@ QgsVectorLayer, QgsWkbTypes, ) -from qgis.PyQt.QtCore import Qt, QVariant +from qgis.PyQt.QtCore import Qt from los_tools.classes.classes_los import LoSGlobal, LoSLocal, LoSWithoutTarget from los_tools.constants.field_names import FieldNames from los_tools.constants.names_constants import NamesConstants from los_tools.constants.textlabels import TextLabels from los_tools.processing.tools.util_functions import get_los_type -from los_tools.utils import get_doc_file +from los_tools.utils import COLUMN_TYPE, get_doc_file class ExtractPointsLoSAlgorithm(QgsProcessingAlgorithm): @@ -123,17 +123,17 @@ def processAlgorithm(self, parameters, context, feedback): los_type = get_los_type(los_layer, field_names) fields = QgsFields() - fields.append(QgsField(FieldNames.ID_OBSERVER, QVariant.Int)) - fields.append(QgsField(FieldNames.ID_TARGET, QVariant.Int)) - fields.append(QgsField(FieldNames.VISIBLE, QVariant.Bool)) + fields.append(QgsField(FieldNames.ID_OBSERVER, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.ID_TARGET, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.VISIBLE, COLUMN_TYPE.Bool)) if extended_attributes: - fields.append(QgsField(FieldNames.ELEVATION_DIFF_LH, QVariant.Double)) - fields.append(QgsField(FieldNames.ANGLE_DIFF_LH, QVariant.Double)) + fields.append(QgsField(FieldNames.ELEVATION_DIFF_LH, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.ANGLE_DIFF_LH, COLUMN_TYPE.Double)) if los_type == NamesConstants.LOS_GLOBAL or los_type == NamesConstants.LOS_NO_TARGET: - fields.append(QgsField(FieldNames.ELEVATION_DIFF_GH, QVariant.Double)) - fields.append(QgsField(FieldNames.ANGLE_DIFF_GH, QVariant.Double)) + fields.append(QgsField(FieldNames.ELEVATION_DIFF_GH, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.ANGLE_DIFF_GH, COLUMN_TYPE.Double)) sink, self.dest_id = self.parameterAsSink( parameters, diff --git a/los_tools/processing/azimuths/tool_azimuth.py b/los_tools/processing/azimuths/tool_azimuth.py index 45aba59..7713032 100644 --- a/los_tools/processing/azimuths/tool_azimuth.py +++ b/los_tools/processing/azimuths/tool_azimuth.py @@ -11,10 +11,9 @@ QgsProcessingUtils, QgsWkbTypes, ) -from qgis.PyQt.QtCore import QVariant from los_tools.constants.field_names import FieldNames -from los_tools.utils import get_doc_file +from los_tools.utils import COLUMN_TYPE, get_doc_file class AzimuthPointPolygonAlgorithm(QgsProcessingAlgorithm): @@ -78,9 +77,9 @@ def processAlgorithm(self, parameters, context, feedback): object_field_id = self.parameterAsString(parameters, self.OBJECT_LAYER_FIELD_ID, context) fields = QgsFields() - fields.append(QgsField(FieldNames.ID_POINT, QVariant.Int)) - fields.append(QgsField(FieldNames.ID_OBJECT, QVariant.Int)) - fields.append(QgsField(FieldNames.AZIMUTH, QVariant.Double)) + fields.append(QgsField(FieldNames.ID_POINT, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.ID_OBJECT, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.AZIMUTH, COLUMN_TYPE.Double)) sink, dest_id = self.parameterAsSink( parameters, diff --git a/los_tools/processing/azimuths/tool_limit_angles_vector.py b/los_tools/processing/azimuths/tool_limit_angles_vector.py index 713c3dd..f4c45f7 100644 --- a/los_tools/processing/azimuths/tool_limit_angles_vector.py +++ b/los_tools/processing/azimuths/tool_limit_angles_vector.py @@ -15,12 +15,11 @@ QgsProject, QgsWkbTypes, ) -from qgis.PyQt.QtCore import QVariant from los_tools.constants.field_names import FieldNames from los_tools.constants.names_constants import NamesConstants from los_tools.processing.tools.util_functions import get_los_type -from los_tools.utils import get_doc_file +from los_tools.utils import COLUMN_TYPE, get_doc_file class LimitAnglesAlgorithm(QgsProcessingAlgorithm): @@ -97,10 +96,10 @@ def processAlgorithm(self, parameters, context, feedback): coord_transform = None fields = QgsFields() - fields.append(QgsField(FieldNames.ID_OBSERVER, QVariant.Int)) - fields.append(QgsField(FieldNames.ID_OBJECT, QVariant.Int)) - fields.append(QgsField(FieldNames.AZIMUTH_MIN, QVariant.Double)) - fields.append(QgsField(FieldNames.AZIMUTH_MAX, QVariant.Double)) + fields.append(QgsField(FieldNames.ID_OBSERVER, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.ID_OBJECT, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.AZIMUTH_MIN, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.AZIMUTH_MAX, COLUMN_TYPE.Double)) sink, dest_id = self.parameterAsSink( parameters, diff --git a/los_tools/processing/create_points/tool_points_around.py b/los_tools/processing/create_points/tool_points_around.py index ce228d0..8d37228 100644 --- a/los_tools/processing/create_points/tool_points_around.py +++ b/los_tools/processing/create_points/tool_points_around.py @@ -16,11 +16,10 @@ QgsProcessingUtils, QgsWkbTypes, ) -from qgis.PyQt.QtCore import QVariant from los_tools.constants.field_names import FieldNames from los_tools.processing.tools.util_functions import get_max_decimal_numbers, round_all_values -from los_tools.utils import get_doc_file +from los_tools.utils import COLUMN_TYPE, get_doc_file class CreatePointsAroundAlgorithm(QgsProcessingAlgorithm): @@ -116,9 +115,9 @@ def processAlgorithm(self, parameters, context, feedback): distance = self.parameterAsDouble(parameters, self.DISTANCE, context) fields = QgsFields() - fields.append(QgsField(FieldNames.ID_ORIGINAL_POINT, QVariant.Int)) - fields.append(QgsField(FieldNames.AZIMUTH, QVariant.Double)) - fields.append(QgsField(FieldNames.ANGLE_STEP_POINTS, QVariant.Double)) + fields.append(QgsField(FieldNames.ID_ORIGINAL_POINT, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.AZIMUTH, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.ANGLE_STEP_POINTS, COLUMN_TYPE.Double)) sink, dest_id = self.parameterAsSink( parameters, diff --git a/los_tools/processing/create_points/tool_points_by_azimuths.py b/los_tools/processing/create_points/tool_points_by_azimuths.py index f4299c3..c4fcc99 100644 --- a/los_tools/processing/create_points/tool_points_by_azimuths.py +++ b/los_tools/processing/create_points/tool_points_by_azimuths.py @@ -17,11 +17,10 @@ QgsProcessingUtils, QgsWkbTypes, ) -from qgis.PyQt.QtCore import QVariant from los_tools.constants.field_names import FieldNames from los_tools.processing.tools.util_functions import get_max_decimal_numbers, round_all_values -from los_tools.utils import get_doc_file +from los_tools.utils import COLUMN_TYPE, get_doc_file class CreatePointsInAzimuthsAlgorithm(QgsProcessingAlgorithm): @@ -136,10 +135,10 @@ def processAlgorithm(self, parameters, context, feedback): round_digits = get_max_decimal_numbers([angle_min, angle_max, angle_step]) fields = QgsFields() - fields.append(QgsField(FieldNames.ID_ORIGINAL_POINT, QVariant.Int)) - fields.append(QgsField(FieldNames.ID_POINT, QVariant.Int)) - fields.append(QgsField(FieldNames.AZIMUTH, QVariant.Double)) - fields.append(QgsField(FieldNames.ANGLE_STEP_POINTS, QVariant.Double)) + fields.append(QgsField(FieldNames.ID_ORIGINAL_POINT, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.ID_POINT, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.AZIMUTH, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.ANGLE_STEP_POINTS, COLUMN_TYPE.Double)) sink, dest_id = self.parameterAsSink( parameters, diff --git a/los_tools/processing/create_points/tool_points_in_direction.py b/los_tools/processing/create_points/tool_points_in_direction.py index 97483a0..d026cd0 100644 --- a/los_tools/processing/create_points/tool_points_in_direction.py +++ b/los_tools/processing/create_points/tool_points_in_direction.py @@ -16,11 +16,10 @@ QgsProcessingUtils, QgsWkbTypes, ) -from qgis.PyQt.QtCore import QVariant from los_tools.constants.field_names import FieldNames from los_tools.processing.tools.util_functions import get_max_decimal_numbers, round_all_values -from los_tools.utils import get_doc_file +from los_tools.utils import COLUMN_TYPE, get_doc_file class CreatePointsInDirectionAlgorithm(QgsProcessingAlgorithm): @@ -123,11 +122,11 @@ def processAlgorithm(self, parameters, context, feedback): distance = self.parameterAsDouble(parameters, self.DISTANCE, context) fields = QgsFields() - fields.append(QgsField(FieldNames.ID_ORIGINAL_POINT, QVariant.Int)) - fields.append(QgsField(FieldNames.ID_POINT, QVariant.Int)) - fields.append(QgsField(FieldNames.AZIMUTH, QVariant.Double)) - fields.append(QgsField(FieldNames.DIFF_TO_MAIN_AZIMUTH, QVariant.Double)) - fields.append(QgsField(FieldNames.ANGLE_STEP_POINTS, QVariant.Double)) + fields.append(QgsField(FieldNames.ID_ORIGINAL_POINT, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.ID_POINT, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.AZIMUTH, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.DIFF_TO_MAIN_AZIMUTH, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.ANGLE_STEP_POINTS, COLUMN_TYPE.Double)) sink, dest_id = self.parameterAsSink( parameters, diff --git a/los_tools/processing/horizons/tool_extract_horizon_lines.py b/los_tools/processing/horizons/tool_extract_horizon_lines.py index c1f4d8c..aa6b457 100644 --- a/los_tools/processing/horizons/tool_extract_horizon_lines.py +++ b/los_tools/processing/horizons/tool_extract_horizon_lines.py @@ -17,13 +17,12 @@ QgsVectorLayer, QgsWkbTypes, ) -from qgis.PyQt.QtCore import QVariant from los_tools.classes.classes_los import LoSWithoutTarget from los_tools.constants.field_names import FieldNames from los_tools.constants.names_constants import NamesConstants from los_tools.processing.tools.util_functions import get_los_type -from los_tools.utils import get_doc_file +from los_tools.utils import COLUMN_TYPE, COLUMN_TYPE_STRING, get_doc_file class ExtractHorizonLinesAlgorithm(QgsProcessingAlgorithm): @@ -103,10 +102,10 @@ def processAlgorithm(self, parameters, context, feedback: QgsProcessingFeedback) ref_coeff = self.parameterAsDouble(parameters, self.REFRACTION_COEFFICIENT, context) fields = QgsFields() - fields.append(QgsField(FieldNames.HORIZON_TYPE, QVariant.String)) - fields.append(QgsField(FieldNames.ID_OBSERVER, QVariant.Int)) - fields.append(QgsField(FieldNames.OBSERVER_X, QVariant.Double)) - fields.append(QgsField(FieldNames.OBSERVER_Y, QVariant.Double)) + fields.append(QgsField(FieldNames.HORIZON_TYPE, COLUMN_TYPE_STRING)) + fields.append(QgsField(FieldNames.ID_OBSERVER, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.OBSERVER_X, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.OBSERVER_Y, COLUMN_TYPE.Double)) sink, dest_id = self.parameterAsSink( parameters, diff --git a/los_tools/processing/horizons/tool_extract_horizons.py b/los_tools/processing/horizons/tool_extract_horizons.py index 3291790..d11c1b9 100644 --- a/los_tools/processing/horizons/tool_extract_horizons.py +++ b/los_tools/processing/horizons/tool_extract_horizons.py @@ -20,14 +20,13 @@ QgsSymbol, QgsWkbTypes, ) -from qgis.PyQt.QtCore import Qt, QVariant from los_tools.classes.classes_los import LoSGlobal, LoSLocal, LoSWithoutTarget from los_tools.constants.field_names import FieldNames from los_tools.constants.names_constants import NamesConstants from los_tools.constants.textlabels import TextLabels from los_tools.processing.tools.util_functions import get_los_type -from los_tools.utils import get_doc_file +from los_tools.utils import COLUMN_TYPE, COLUMN_TYPE_STRING, get_doc_file # TODO příznak horizontu na konci DSM @@ -149,12 +148,12 @@ def processAlgorithm(self, parameters, context, feedback): los_type = get_los_type(los_layer, field_names) fields = QgsFields() - fields.append(QgsField(FieldNames.HORIZON_TYPE, QVariant.String)) - fields.append(QgsField(FieldNames.ID_OBSERVER, QVariant.Int)) - fields.append(QgsField(FieldNames.ID_TARGET, QVariant.Int)) + fields.append(QgsField(FieldNames.HORIZON_TYPE, COLUMN_TYPE_STRING)) + fields.append(QgsField(FieldNames.ID_OBSERVER, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.ID_TARGET, COLUMN_TYPE.Int)) if los_type == NamesConstants.LOS_NO_TARGET: - fields.append(QgsField(FieldNames.AZIMUTH, QVariant.Double)) + fields.append(QgsField(FieldNames.AZIMUTH, COLUMN_TYPE.Double)) sink, self.dest_id = self.parameterAsSink( parameters, diff --git a/los_tools/processing/parameter_settings/tool_distances_for_sizes.py b/los_tools/processing/parameter_settings/tool_distances_for_sizes.py index 7e1cecc..fc5e7d8 100755 --- a/los_tools/processing/parameter_settings/tool_distances_for_sizes.py +++ b/los_tools/processing/parameter_settings/tool_distances_for_sizes.py @@ -14,10 +14,9 @@ QgsProcessingUtils, QgsWkbTypes, ) -from qgis.PyQt.QtCore import QVariant from los_tools.constants.field_names import FieldNames -from los_tools.utils import get_doc_file +from los_tools.utils import COLUMN_TYPE, get_doc_file class ObjectDistancesAlgorithm(QgsProcessingAlgorithm): @@ -65,9 +64,9 @@ def processAlgorithm(self, parameters, context, feedback: QgsProcessingFeedback) maximal_distance = self.parameterAsBoolean(parameters, self.MAXIMALDISTANCE, context) fields = QgsFields() - fields.append(QgsField(FieldNames.SIZE_ANGLE, QVariant.Double)) - fields.append(QgsField(FieldNames.DISTANCE, QVariant.Double)) - fields.append(QgsField(FieldNames.SIZE, QVariant.Double)) + fields.append(QgsField(FieldNames.SIZE_ANGLE, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.DISTANCE, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.SIZE, COLUMN_TYPE.Double)) sink, dest_id = self.parameterAsSink(parameters, self.OUTPUT_TABLE, context, fields, QgsWkbTypes.NoGeometry) diff --git a/los_tools/processing/parameter_settings/tool_sizes_at_distances.py b/los_tools/processing/parameter_settings/tool_sizes_at_distances.py index 3742abe..47b7167 100755 --- a/los_tools/processing/parameter_settings/tool_sizes_at_distances.py +++ b/los_tools/processing/parameter_settings/tool_sizes_at_distances.py @@ -14,10 +14,9 @@ QgsProcessingUtils, QgsWkbTypes, ) -from qgis.PyQt.QtCore import QVariant from los_tools.constants.field_names import FieldNames -from los_tools.utils import get_doc_file +from los_tools.utils import COLUMN_TYPE, get_doc_file class ObjectSizesAlgorithm(QgsProcessingAlgorithm): @@ -96,9 +95,9 @@ def processAlgorithm(self, parameters, context, feedback: QgsProcessingFeedback) default_sampling_size = self.parameterAsDouble(parameters, self.DEFAULT_SAMPLING_DISTANCE, context) fields = QgsFields() - fields.append(QgsField(FieldNames.SIZE_ANGLE, QVariant.Double)) - fields.append(QgsField(FieldNames.DISTANCE, QVariant.Double)) - fields.append(QgsField(FieldNames.SIZE, QVariant.Double)) + fields.append(QgsField(FieldNames.SIZE_ANGLE, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.DISTANCE, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.SIZE, COLUMN_TYPE.Double)) sink, dest_id = self.parameterAsSink(parameters, self.OUTPUT_TABLE, context, fields, QgsWkbTypes.NoGeometry) diff --git a/los_tools/processing/to_table/tool_export_horizon_lines.py b/los_tools/processing/to_table/tool_export_horizon_lines.py index 0133251..23e124e 100644 --- a/los_tools/processing/to_table/tool_export_horizon_lines.py +++ b/los_tools/processing/to_table/tool_export_horizon_lines.py @@ -16,10 +16,9 @@ QgsProcessingUtils, QgsWkbTypes, ) -from qgis.PyQt.QtCore import QVariant from los_tools.constants.field_names import FieldNames -from los_tools.utils import get_doc_file +from los_tools.utils import COLUMN_TYPE, COLUMN_TYPE_STRING, get_doc_file class ExportHorizonLinesAlgorithm(QgsProcessingAlgorithm): @@ -66,11 +65,11 @@ def processAlgorithm(self, parameters, context, feedback): feature_count = input_horizon_lines_layer.featureCount() fields = QgsFields() - fields.append(QgsField(FieldNames.ID_OBSERVER, QVariant.Int)) - fields.append(QgsField(FieldNames.HORIZON_TYPE, QVariant.String)) - fields.append(QgsField(FieldNames.ANGLE, QVariant.Double)) - fields.append(QgsField(FieldNames.VIEWING_ANGLE, QVariant.Double)) - fields.append(QgsField(FieldNames.CSV_HORIZON_DISTANCE, QVariant.Double)) + fields.append(QgsField(FieldNames.ID_OBSERVER, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.HORIZON_TYPE, COLUMN_TYPE_STRING)) + fields.append(QgsField(FieldNames.ANGLE, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.VIEWING_ANGLE, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.CSV_HORIZON_DISTANCE, COLUMN_TYPE.Double)) sink: QgsFeatureSink sink, path_sink = self.parameterAsSink( diff --git a/los_tools/processing/to_table/tool_export_los.py b/los_tools/processing/to_table/tool_export_los.py index 6e2069c..b025bba 100644 --- a/los_tools/processing/to_table/tool_export_los.py +++ b/los_tools/processing/to_table/tool_export_los.py @@ -13,13 +13,12 @@ QgsProcessingUtils, QgsWkbTypes, ) -from qgis.PyQt.QtCore import QVariant from los_tools.classes.classes_los import LoSGlobal, LoSLocal, LoSWithoutTarget from los_tools.constants.field_names import FieldNames from los_tools.constants.names_constants import NamesConstants from los_tools.processing.tools.util_functions import get_los_type -from los_tools.utils import get_doc_file +from los_tools.utils import COLUMN_TYPE, COLUMN_TYPE_STRING, get_doc_file class ExportLoSAlgorithm(QgsProcessingAlgorithm): @@ -83,24 +82,24 @@ def processAlgorithm(self, parameters, context, feedback): fields = QgsFields() - fields.append(QgsField(FieldNames.ID_LOS, QVariant.Int)) - fields.append(QgsField(FieldNames.ID_OBSERVER, QVariant.Int)) - fields.append(QgsField(FieldNames.OBSERVER_OFFSET, QVariant.Double)) - fields.append(QgsField(FieldNames.CSV_OBSERVER_DISTANCE, QVariant.Double)) - fields.append(QgsField(FieldNames.CSV_ELEVATION, QVariant.Double)) - fields.append(QgsField(FieldNames.CSV_VISIBLE, QVariant.Bool)) - fields.append(QgsField(FieldNames.CSV_HORIZON, QVariant.Bool)) + fields.append(QgsField(FieldNames.ID_LOS, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.ID_OBSERVER, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.OBSERVER_OFFSET, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.CSV_OBSERVER_DISTANCE, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.CSV_ELEVATION, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.CSV_VISIBLE, COLUMN_TYPE.Bool)) + fields.append(QgsField(FieldNames.CSV_HORIZON, COLUMN_TYPE.Bool)) if los_type == NamesConstants.LOS_LOCAL: - fields.append(QgsField(FieldNames.ID_TARGET, QVariant.Int)) - fields.append(QgsField(FieldNames.TARGET_OFFSET, QVariant.Double)) + fields.append(QgsField(FieldNames.ID_TARGET, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.TARGET_OFFSET, COLUMN_TYPE.Double)) elif los_type == NamesConstants.LOS_GLOBAL: - fields.append(QgsField(FieldNames.ID_TARGET, QVariant.Int)) - fields.append(QgsField(FieldNames.TARGET_OFFSET, QVariant.Double)) - fields.append(QgsField(FieldNames.TARGET_X, QVariant.Double)) - fields.append(QgsField(FieldNames.TARGET_Y, QVariant.Double)) - fields.append(QgsField(FieldNames.CSV_TARGET, QVariant.Bool)) + fields.append(QgsField(FieldNames.ID_TARGET, COLUMN_TYPE.Int)) + fields.append(QgsField(FieldNames.TARGET_OFFSET, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.TARGET_X, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.TARGET_Y, COLUMN_TYPE.Double)) + fields.append(QgsField(FieldNames.CSV_TARGET, COLUMN_TYPE.Bool)) # elif los_type == NamesConstants.LOS_NO_TARGET: # pass diff --git a/los_tools/utils.py b/los_tools/utils.py index cb17b78..539e57c 100644 --- a/los_tools/utils.py +++ b/los_tools/utils.py @@ -1,7 +1,11 @@ import configparser import json +import typing from pathlib import Path +from qgis.core import Qgis +from qgis.PyQt.QtCore import QMetaType, QVariant + def get_icon_path(icon_name: str) -> str: path = Path(__file__).parent / "icons" / icon_name @@ -32,3 +36,26 @@ def get_doc_file(file_path: str): return descriptions return "" + + +def _column_type_class(): + """Select clas for types based on version of QGIS.""" + if Qgis.versionInt() >= 33800: + source_type = QMetaType.Type + else: + source_type = QVariant.Type + return source_type + + +def _colum_type_string() -> typing.Union[QVariant.Type, QMetaType.Type]: + """Return string representation of column type based on version of QGIS.""" + source_type = _column_type_class() + if Qgis.versionInt() >= 33800: + source_type_string = source_type.QString + else: + source_type_string = source_type.String + return source_type_string + + +COLUMN_TYPE: type[typing.Union[QMetaType.Type, QVariant.Type]] = _column_type_class() +COLUMN_TYPE_STRING: type[typing.Union[QMetaType.Type, QVariant.Type]] = _colum_type_string()