Skip to content

Commit

Permalink
.. make factory
Browse files Browse the repository at this point in the history
  • Loading branch information
cnheider committed Sep 15, 2024
1 parent 29e941e commit 2934053
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 10 deletions.
2 changes: 1 addition & 1 deletion jord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

__project__ = "Jord"
__author__ = "Christian Heider Lindbjerg"
__version__ = "0.7.6"
__version__ = "0.7.7"
__doc__ = r"""
.. module:: jord
:platform: Unix, Windows
Expand Down
3 changes: 3 additions & 0 deletions jord/qgis_utilities/conversion/gcp_transformer_factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from pathlib import Path

# noinspection PyUnresolvedReferences
from qgis.analysis import QgsGcpGeometryTransformer, QgsGcpTransformerInterface

# noinspection PyUnresolvedReferences
from qgis.core import QgsPointXY

__all__ = ["get_gcp_transformer_from_file"]
Expand Down
18 changes: 17 additions & 1 deletion jord/qgis_utilities/conversion/parsing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/env python3
from typing import Collection
from typing import Any, Collection

__all__ = [
"sanitise_wkb",
"sanitise_wkt",
"explode_geometry_collection",
"wkb_geom_constructor",
]


def sanitise_wkb() -> str: ...
Expand All @@ -9,3 +16,12 @@ def sanitise_wkt() -> str: ...


def explode_geometry_collection() -> Collection[str]: ...


def wkb_geom_constructor(wkb: bytes) -> Any:
# noinspection PyUnresolvedReferences
from qgis.core import QgsGeometry

geom = QgsGeometry()
geom.fromWkb(wkb)
return geom
3 changes: 2 additions & 1 deletion jord/qgis_utilities/conversion/read_gcp_read.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import csv
from pathlib import Path
from typing import Generator, Tuple

__all__ = ["read_gcp_file"]


def read_gcp_file(
gcp_points_file_path, filter_comments: bool = True
gcp_points_file_path: Path, filter_comments: bool = True
) -> Tuple[Generator, Generator]:
with open(gcp_points_file_path, encoding="utf8", errors="ignore") as fp:
if filter_comments:
Expand Down
2 changes: 2 additions & 0 deletions jord/qgis_utilities/conversion/read_wld_file.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from PyQt5.QtGui import QTransform

__all__ = ["read_wld_file"]


def read_wld_file(geom, wld_file_path):
assert wld_file_path is not None
Expand Down
14 changes: 9 additions & 5 deletions jord/qgis_utilities/layer_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ def add_qgis_single_feature_layer(
:param visible:
:param categorise_by_attribute:
:param group:
:param columns: Field=name:type(length,precision) Defines an attribute of the layer. Multiple field parameters can be added to the data provider definition. Type is one of “integer”, “double”, “string”.
:param columns: Field=name:type(length,precision) Defines an attribute of the layer. Multiple field
parameters can be added to the data provider definition. Type is one of “integer”, “double”, “string”.
:param index: index=yes Specifies that the layer will be constructed with a spatial index
:param qgis_instance_handle:
:param geom:
:type geom: QgsGeometry
:param name:
:type name: Optional[str]
:param crs: Crs=definition Defines the coordinate reference system to use for the layer. Definition is any string accepted by QgsCoordinateReferenceSystem.createFromString()
:param crs: Crs=definition Defines the coordinate reference system to use for the layer. Definition is any
string accepted by QgsCoordinateReferenceSystem.createFromString()
:return: None
:rtype: None
"""
Expand Down Expand Up @@ -170,7 +172,6 @@ def add_qgis_single_feature_layer(
return_collection.append(sub_layer)

if group:

qgis_project.addMapLayer(sub_layer, False)
group.insertLayer(0, sub_layer)
else:
Expand Down Expand Up @@ -309,7 +310,8 @@ def add_qgis_multi_feature_layer(
"""
fields == column definition name, type, length/size
Multiple field parameters can be added to the data provider definition. type is one of “integer”, “double”, “string”.
Multiple field parameters can be added to the data provider definition. type is one of “integer”,
“double”, “string”.
An example url is “Point?crs=epsg:4326&field=id:integer&field=name:string(20)&index=yes”
Expand Down Expand Up @@ -392,6 +394,7 @@ def add_qgis_multi_feature_layer(
geoms = [geoms]

for geom in geoms:
# geom:QgsGeometry
geom_json = json.loads(geom.asJson())

if geom_json is None:
Expand Down Expand Up @@ -476,7 +479,8 @@ def add_qgis_multi_feature_layer(

layer = QgsVectorLayer(uri, layer_name, "memory")
layer_data_provider = layer.dataProvider()
# pr.addAttributes([QgsField("name", QVariant.String),QgsField("age", QVariant.Int),QgsField("size", QVariant.Double)])
# pr.addAttributes([QgsField("name", QVariant.String),QgsField("age", QVariant.Int),QgsField("size",
# QVariant.Double)])

(res, out_feats) = layer_data_provider.addFeatures(
features
Expand Down
7 changes: 5 additions & 2 deletions jord/qlive_utilities/procedures.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
from warg import Number, ensure_existence, passes_kws_to

from jord import PROJECT_APP_PATH
from jord.qgis_utilities import (
wkb_geom_constructor,
)
from jord.qgis_utilities.layer_creation import (
add_qgis_multi_feature_layer,
add_qgis_single_feature_layer,
Expand Down Expand Up @@ -69,7 +72,7 @@ def add_wkb(qgis_instance_handle: Any, wkb: bytes, *args, **kwargs) -> List:
from qgis.core import QgsGeometry

return add_qgis_single_feature_layer(
qgis_instance_handle, QgsGeometry().fromWkb(wkb), *args, **kwargs
qgis_instance_handle, wkb_geom_constructor(wkb), *args, **kwargs
)


Expand Down Expand Up @@ -104,7 +107,7 @@ def add_wkb_layer(

return add_qgis_multi_feature_layer(
qgis_instance_handle,
[QgsGeometry().fromWkb(wkb) for wkb in wkbs],
[wkb_geom_constructor(wkb) for wkb in wkbs],
*args,
**kwargs,
)
Expand Down

0 comments on commit 2934053

Please sign in to comment.