From 0a943cf2af201447dc4febc0666fb3cd34eae262 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Mar 2024 21:38:08 +0000 Subject: [PATCH 1/4] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - https://github.com/ambv/black → https://github.com/psf/black - [github.com/psf/black: 22.3.0 → 24.3.0](https://github.com/psf/black/compare/22.3.0...24.3.0) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bf2c495..337cf15 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,8 +1,8 @@ fail_fast: true #exclude: '^exclude' repos: - - repo: https://github.com/ambv/black - rev: 22.3.0 + - repo: https://github.com/psf/black + rev: 24.3.0 hooks: - id: black language_version: python3.8 From 87ac0535ca380be3ccbc2a69d1d6750668e0943a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Mar 2024 21:38:31 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- jord/qgis_utilities/numpy_utilities/conversion.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jord/qgis_utilities/numpy_utilities/conversion.py b/jord/qgis_utilities/numpy_utilities/conversion.py index 710c50b..d87d6ca 100644 --- a/jord/qgis_utilities/numpy_utilities/conversion.py +++ b/jord/qgis_utilities/numpy_utilities/conversion.py @@ -5,7 +5,7 @@ __all__ = ["get_qimage_from_numpy"] -def get_qimage_from_numpy(img, debug=False)->QtGui.QImage: +def get_qimage_from_numpy(img, debug=False) -> QtGui.QImage: # if isinstance(img, Image): # img = img.data # if isinstance(img, numpy.ndarray): @@ -24,7 +24,7 @@ def get_qimage_from_numpy(img, debug=False)->QtGui.QImage: return QtGui.QImage(img, width, height, bytes_per_line, QtGui.QImage.Format_RGB888) -def transform_coordinates(coordinates, fromCRS, toCRS)->list: +def transform_coordinates(coordinates, fromCRS, toCRS) -> list: """ function to transform a set of coordinates from one CRS to another""" @@ -49,7 +49,7 @@ def transform_coordinates(coordinates, fromCRS, toCRS)->list: ] # transform the QgsPoint objects back to a list of coordinates -def get_coordinates_of_layer_extent(layer)->list: +def get_coordinates_of_layer_extent(layer) -> list: """ function to get coordinates of a layer extent From f10cad02a1c02f484c334a023d2ea53d2f74809d Mon Sep 17 00:00:00 2001 From: Christian Heider Nielsen Date: Wed, 20 Mar 2024 12:51:19 +0100 Subject: [PATCH 3/4] bump --- jord/__init__.py | 2 +- jord/qgis_utilities/__init__.py | 1 + jord/qgis_utilities/helpers/groups.py | 31 ++++++++++++++++++++------- jord/qgis_utilities/styles.py | 28 ++++++++++++++++++++++++ jord/qlive_utilities/procedures.py | 1 + jord/shapely_utilities/lines.py | 2 +- jord/shapely_utilities/morphology.py | 2 +- 7 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 jord/qgis_utilities/styles.py diff --git a/jord/__init__.py b/jord/__init__.py index eecf74d..2d4ceea 100755 --- a/jord/__init__.py +++ b/jord/__init__.py @@ -16,7 +16,7 @@ __project__ = "Jord" __author__ = "Christian Heider Lindbjerg" -__version__ = "0.4.7" +__version__ = "0.4.8" __doc__ = r""" .. module:: jord :platform: Unix, Windows diff --git a/jord/qgis_utilities/__init__.py b/jord/qgis_utilities/__init__.py index a57be17..716fc3d 100755 --- a/jord/qgis_utilities/__init__.py +++ b/jord/qgis_utilities/__init__.py @@ -24,6 +24,7 @@ from .geometry_types import * from .conversion import * + # from .styles import * # from .categorisation import * # from .styling import * # from .plugin_version import * diff --git a/jord/qgis_utilities/helpers/groups.py b/jord/qgis_utilities/helpers/groups.py index 21bb320..800a9fc 100644 --- a/jord/qgis_utilities/helpers/groups.py +++ b/jord/qgis_utilities/helpers/groups.py @@ -1,15 +1,30 @@ +from typing import Optional, Any + from qgis.core import QgsLayerTreeGroup __all__ = ["duplicate_groups"] -def duplicate_groups(group_root, appendix: str = " (Copy)") -> QgsLayerTreeGroup: - parent = group_root.parent - new_group = parent.addGroup(f"{group_root.name()}{appendix}") - for child in group_root.children(): - if isinstance(child, QgsLayerTreeGroup): - duplicate_groups(child, appendix="") # Only top level +def duplicate_groups( + group_to_duplicate, *, group_parent: Optional[Any] = None, appendix: str = " (Copy)" +) -> QgsLayerTreeGroup: + assert ( + group_to_duplicate is not None + ), f"{group_to_duplicate=} is required to create a duplicate group" + + if group_parent is None: + group_parent = group_to_duplicate.parent() + + if group_parent is None: + raise ValueError(f"Group parent was not found for {group_to_duplicate}") + + new_group_parent = group_parent.addGroup(f"{group_to_duplicate.name()}{appendix}") + for original_group_child in group_to_duplicate.children(): + if isinstance(original_group_child, QgsLayerTreeGroup): + new_child_group = duplicate_groups( + original_group_child, group_parent=new_group_parent, appendix="" + ) # Only top level else: - new_group.addChildNode(child.clone()) + new_group_parent.addChildNode(original_group_child.clone()) - return new_group + return new_group_parent diff --git a/jord/qgis_utilities/styles.py b/jord/qgis_utilities/styles.py new file mode 100644 index 0000000..05e1c3a --- /dev/null +++ b/jord/qgis_utilities/styles.py @@ -0,0 +1,28 @@ +from pathlib import Path + +__all__ = ["add_xml_style"] + + +def add_xml_style(iface, path: Path = "styles/my_directional_lines.xml") -> None: + from qgis.core import QgsStyle + + if not isinstance(path, Path): + path = Path(path) + + qstyles = QgsStyle.defaultStyle() + qstyles.importXml(str(path)) + # qstyles.addFavorite(QgsStyle.StyleEntity.SymbolEntity, 'Snake') + + before = qstyles.symbolNames() + qstyles.importXml("mycompanystyles.xml") + after = qstyles.symbolNames() + mystyles = list(set(after) - set(before)) + for s in mystyles: + qstyles.addFavorite(QgsStyle.StyleEntity.SymbolEntity, s) + + layer = iface.activeLayer() + qstyles = QgsStyle.defaultStyle() + style = qstyles.symbol("Snake") + layer.renderer().setSymbol(style) + layer.triggerRepaint() + iface.layerTreeView().refreshLayerSymbology(layer.id()) diff --git a/jord/qlive_utilities/procedures.py b/jord/qlive_utilities/procedures.py index 73b78e2..2cb51c7 100755 --- a/jord/qlive_utilities/procedures.py +++ b/jord/qlive_utilities/procedures.py @@ -276,6 +276,7 @@ def add_shapely_layer( # assert geoms[0] == #TODO: SAME TYPE if isinstance(geoms, shapely.geometry.base.BaseGeometry): geoms = [geoms] + return add_wkt_layer( qgis_instance_handle, [geom.wkt for geom in geoms], *args, **kwargs ) diff --git a/jord/shapely_utilities/lines.py b/jord/shapely_utilities/lines.py index 13ba21e..bfc4340 100755 --- a/jord/shapely_utilities/lines.py +++ b/jord/shapely_utilities/lines.py @@ -42,7 +42,6 @@ from typing import Iterable, List, Sequence, Tuple, Union import numpy -from shapely import LinearRing from shapely.geometry import ( LineString, MultiLineString, @@ -50,6 +49,7 @@ Point, box, ) +from shapely.geometry import LinearRing from shapely.geometry.base import BaseGeometry from shapely.ops import linemerge as shapely_linemerge from sorcery import assigned_names diff --git a/jord/shapely_utilities/morphology.py b/jord/shapely_utilities/morphology.py index 76e765e..f2dbd94 100755 --- a/jord/shapely_utilities/morphology.py +++ b/jord/shapely_utilities/morphology.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import shapely -from shapely import LinearRing +from shapely.geometry import LinearRing from shapely.geometry.base import BaseGeometry __all__ = ["closing", "opening", "erode", "erosion", "dilate", "dilation", "close"] From a34452df690fa17f39a8fe6d16a98c0c46f4ff1d Mon Sep 17 00:00:00 2001 From: Christian Heider Nielsen Date: Wed, 20 Mar 2024 12:54:09 +0100 Subject: [PATCH 4/4] fix --- jord/networkx_utilities/construction.py | 1 - 1 file changed, 1 deletion(-) mode change 100755 => 100644 jord/networkx_utilities/construction.py diff --git a/jord/networkx_utilities/construction.py b/jord/networkx_utilities/construction.py old mode 100755 new mode 100644 index b3df4fd..538bc06 --- a/jord/networkx_utilities/construction.py +++ b/jord/networkx_utilities/construction.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 from typing import Mapping, Any import shapely