Skip to content

Commit

Permalink
Merge branch 'release/0.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
cnheider committed Jul 26, 2023
2 parents f932f39 + f7d53fd commit 095e795
Show file tree
Hide file tree
Showing 23 changed files with 430 additions and 72 deletions.
2 changes: 1 addition & 1 deletion jord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

__project__ = "Jord"
__author__ = "Christian Heider Nielsen"
__version__ = "0.1.0"
__version__ = "0.1.1"
__doc__ = r"""
.. module:: jord
:platform: Unix, Windows
Expand Down
4 changes: 4 additions & 0 deletions jord/geojson_utilities/geometry_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ class GeoJsonGeometryTypesEnum(Enum):
multi_polygon = MultiPolygon #

geometry_collection = GeometryCollection #


if __name__ == "__main__":
print(GeoJsonGeometryTypesEnum.geometry_collection.value.__name__)
1 change: 1 addition & 0 deletions jord/geopandas_utilities/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .geometry_filtering import *
from .importing import *
3 changes: 2 additions & 1 deletion jord/geopandas_utilities/geometry_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ def split_on_geom_type(
gdf3 = gdf[gdf.geometry.type=="MultiPolygon"]
"""
return {
t: data_frame[data_frame.geom_type == t.value] for t in ShapelyGeometryTypesEnum
t: data_frame[data_frame.geom_type == t.value.__name__]
for t in ShapelyGeometryTypesEnum
}
7 changes: 7 additions & 0 deletions jord/geopandas_utilities/importing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os

os.environ["USE_PYGEOS"] = "0"

import geopandas

__all__ = ["geopandas"]
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 .conversion import *
from .categorisation import *
from .styling import *
from .plugin_version import *
except ImportError as ix:
this_package_name = Path(__file__).parent.name
print(f"Make sure qgis module is available for {this_package_name}")
Expand Down
27 changes: 19 additions & 8 deletions jord/qgis_utilities/categorisation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import random
from itertools import cycle
from typing import Any, Iterable, Sized
from typing import Iterable, Sized, Callable, Generator

from PyQt5.Qt import QColor
from qgis.core import (
Expand All @@ -9,7 +9,7 @@
QgsRendererCategory,
QgsCategorizedSymbolRenderer,
)
from warg import TripleNumber
from warg import TripleNumber, QuadNumber, n_uint_mix_generator_builder

__all__ = ["categorise_layer"]

Expand All @@ -21,34 +21,45 @@ def random_rgb(mix: TripleNumber = (255, 255, 255)) -> TripleNumber:
return (red, green, blue)


def random_rgba(mix: TripleNumber = (1, 1, 1, 1)) -> TripleNumber:
def random_rgba(mix: QuadNumber = (1, 1, 1, 1)) -> QuadNumber:
red = random.randrange(0, mix[0])
green = random.randrange(0, mix[1])
blue = random.randrange(0, mix[2])
alpha = random.randrange(0, mix[3])
return (red, green, blue, alpha)


def random_color_generator() -> Any:
def random_color_generator() -> TripleNumber:
while 1:
yield random_rgb()


def random_color_alpha_generator() -> QuadNumber:
while 1:
yield random_rgba()


def categorise_layer(
layer: QgsVectorLayer,
field_name: str = "layer",
iterable: Iterable = random_color_generator,
iterable: Iterable = n_uint_mix_generator_builder(255, 255, 255, 255),
) -> None:
if isinstance(iterable, Sized):
iterable = cycle(iterable)
color_iter = iter(iterable())
if isinstance(iterable, Callable) and not isinstance(iterable, Generator):
iterable = iterable() # Compat
color_iter = iter(iterable)

render_categories = []
for cat in layer.uniqueValues(layer.fields().indexFromName(field_name)):
sym = QgsSymbol.defaultSymbol(layer.geometryType())
sym.setColor(QColor(*(next(color_iter)), 255))
col = next(color_iter)
if len(col) == 3:
col = (*col, 255)
sym.setColor(QColor(*col))
label = str(cat)
render_categories.append(
QgsRendererCategory(cat, symbol=sym, label=cat, render=True)
QgsRendererCategory(cat, symbol=sym, label=label, render=True)
)

layer.setRenderer(QgsCategorizedSymbolRenderer(field_name, render_categories))
Expand Down
11 changes: 11 additions & 0 deletions jord/qgis_utilities/plugin_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pyplugin_installer.installer_data import repositories, plugins


__all__ = ["plugin_status"]


def plugin_status(plugin_key) -> str:
return plugins.all()[plugin_key]["status"]


# utils.reloadPlugin()
5 changes: 3 additions & 2 deletions jord/qgis_utilities/styling.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ def style_layer_from_mapping(
cat_color = default_color
cat_opacity = default_opacity
cat_width = default_width
label = str(cat)

if cat in style_mapping.keys():
style = style_mapping[cat]
style = style_mapping[label]
if "color" in style:
cat_color = (
int(n) for n in style["color"]
Expand All @@ -56,7 +57,7 @@ def style_layer_from_mapping(
print(f"width ignored, symbol is of type: {type(symbol)}")

render_categories.append(
QgsRendererCategory(cat, symbol=symbol, label=cat, render=True)
QgsRendererCategory(cat, symbol=symbol, label=label, render=True)
)

layer.setRenderer(QgsCategorizedSymbolRenderer(field_name, render_categories))
Expand Down
1 change: 1 addition & 0 deletions jord/qlive_utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
from .serialisation import *
from .uri_utilities import *
from .client import *
from .clients import *
10 changes: 8 additions & 2 deletions jord/qlive_utilities/client.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
from typing import Any
from enum import Enum
from typing import Any, Callable

import zmq
from warg import AlsoDecorator


__all__ = ["QliveClient"]

import inspect


class QliveClient(AlsoDecorator):
"""
Client for sending data to qgis instance
"""

def __init__(self, addr: str = "tcp://localhost:5555"):
self.context = zmq.Context()
self.socket = self.context.socket(zmq.REQ)
Expand Down
2 changes: 2 additions & 0 deletions jord/qlive_utilities/clients/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .auto import *
from .interfaced import *
97 changes: 97 additions & 0 deletions jord/qlive_utilities/clients/auto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from functools import partial
from typing import Callable
import inspect
from enum import Enum
from jord.qlive_utilities import (
QliveClient,
QliveRPCMethodEnum,
QliveRPCMethodMap,
build_package,
)


__all__ = ["AutoQliveClient"]


class DisSatisfactionEnum(Enum):
none = "none"
args = "args"
kws = "kws"
argskws = "argskws"


def partial_satisfied(partial_fn: Callable) -> bool:
signature = inspect.signature(partial_fn.func)
try:
signature.bind(*partial_fn.args, **partial_fn.keywords)
return True
except TypeError:
return False


class AutoQliveClient(QliveClient):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

for method in QliveRPCMethodEnum:
actual_callable = QliveRPCMethodMap[method]

if False:
partial_build_package = partial(build_package, method)
if False and partial_satisfied(
partial_build_package
): # TODO: RESOLVE PARTIAL APPLICATION SATISFACTION.

def a():
self.send(partial_build_package())

rpc_method = a
elif True:

def a(*args):
self.send(partial_build_package(*args))

rpc_method = a
elif False:

def a(**kwargs):
self.send(partial_build_package(**kwargs))

rpc_method = a
elif False:

def a(*args, **kwargs):
self.send(partial_build_package(*args, **kwargs))

rpc_method = a
else:
raise NotImplementedError
elif False:
rpc_method = lambda *args: self.send(
partial(build_package, method)(*args)
)
elif False:
rpc_method = lambda *args: self.send(build_package(method, *args))
else:

def wrapped(method_, *args_) -> Callable:
return self.send(build_package(method_, *args_))

rpc_method = partial(wrapped, method)

rpc_method.__doc__ = actual_callable.__doc__
setattr(self, method.value, rpc_method)


if __name__ == "__main__":
# QliveClient().clear_all()
# QliveClient().remove_layers()
# print(QliveClient().clear_all.__doc__)
# print(QliveClient().__dict__)
def uahdsuh():
with AutoQliveClient() as qlive:
qlive.add_wkts({"a": "POINT (-66.86 10.48)"})

# QliveClient().add_dataframe(None)

uahdsuh()
11 changes: 11 additions & 0 deletions jord/qlive_utilities/clients/interfaced.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from enum import Enum

from jord.qlive_utilities.client import QliveClient


__all__ = ["InterfacedQliveClient"]


class InterfacedQliveClient(QliveClient):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Loading

0 comments on commit 095e795

Please sign in to comment.