Skip to content

Commit

Permalink
Merge branch 'release/0.4.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
cnheider committed Mar 20, 2024
2 parents 1a43b49 + a34452d commit 6ae3b81
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
- --keep-runtime-typing

- repo: https://github.com/ambv/black
rev: 23.12.1
rev: 24.3.0
hooks:
- id: black
language_version: python3.10
Expand Down
2 changes: 1 addition & 1 deletion jord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion jord/networkx_utilities/construction.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
from typing import Mapping, Any

import shapely
Expand Down
1 change: 1 addition & 0 deletions jord/qgis_utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from .geometry_types import *
from .conversion import *

# from .styles import *
# from .categorisation import *
# from .styling import *
# from .plugin_version import *
Expand Down
31 changes: 23 additions & 8 deletions jord/qgis_utilities/helpers/groups.py
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions jord/qgis_utilities/styles.py
Original file line number Diff line number Diff line change
@@ -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())
1 change: 1 addition & 0 deletions jord/qlive_utilities/procedures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion jord/shapely_utilities/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
from typing import Iterable, List, Sequence, Tuple, Union

import numpy
from shapely import LinearRing
from shapely.geometry import (
LineString,
MultiLineString,
MultiPoint,
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
Expand Down
2 changes: 1 addition & 1 deletion jord/shapely_utilities/morphology.py
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down

0 comments on commit 6ae3b81

Please sign in to comment.