forked from cnheider/jord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
57 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters