Skip to content

Commit

Permalink
Accept lines with Z/M (#166)
Browse files Browse the repository at this point in the history
layers with Z and/or M values previously were throwing exceptions

This is fixed by deriving the base (flat) layer type before comparison.
Also comparing against `QgsWkbTypes` instead of integers.

Co-authored-by: Jakob Schnell <Jakob.Schnell@heigit.org>
Co-authored-by: Amandus Butzer <amandus.butzer@heigit.org>
  • Loading branch information
3 people authored Jan 20, 2022
1 parent 224a349 commit c8f38a9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ RELEASING:
12. Upload the package to https://plugins.qgis.org/plugins/ORStools/ (Manage > Add Version)
13. Create new release in GitHub with tag version and release title of `vX.X.X`
-->
## [Unreleased]

## Fixed
- error for layers with z/m values ([#166](https://github.com/GIScience/orstools-qgis-plugin/pull/166))

## [1.5.1] - 2022-01-11

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions ORStools/proc/directions_lines_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ def _get_sorted_lines(layer, field_name):
line = None
field_value = feat[field_name] if field_name else None

if layer.wkbType() == QgsWkbTypes.MultiLineString:
if QgsWkbTypes.flatType(layer.wkbType()) == QgsWkbTypes.MultiLineString:
# TODO: only takes the first polyline geometry from the multiline geometry currently
# Loop over all polyline geometries
line = [x_former.transform(QgsPointXY(point)) for point in feat.geometry().asMultiPolyline()[0]]

elif layer.wkbType() == QgsWkbTypes.LineString:
elif QgsWkbTypes.flatType(layer.wkbType()) == QgsWkbTypes.LineString:
line = [x_former.transform(QgsPointXY(point)) for point in feat.geometry().asPolyline()]

yield line, field_value
4 changes: 2 additions & 2 deletions ORStools/proc/directions_points_layer_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ def sort(f): return f.id()
from_values = list()
x_former = transform.transformToWGS(source.sourceCrs())

if source.wkbType() == QgsWkbTypes.Point:
if QgsWkbTypes.flatType(source.wkbType()) == QgsWkbTypes.Point:
points = list()
for feat in sorted(source.getFeatures(), key=sort):
points.append(x_former.transform(QgsPointXY(feat.geometry().asPoint())))
input_points.append(points)
from_values.append(None)
elif source.wkbType() == QgsWkbTypes.MultiPoint:
elif QgsWkbTypes.flatType(source.wkbType()) == QgsWkbTypes.MultiPoint:
# loop through multipoint features
for feat in sorted(source.getFeatures(), key=sort):
points = list()
Expand Down
2 changes: 1 addition & 1 deletion ORStools/proc/isochrones_layer_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def processAlgorithm(self, parameters, context, feedback):

# Make the actual requests
requests = []
if source.wkbType() == 4:
if QgsWkbTypes.flatType(source.wkbType()) == QgsWkbTypes.MultiPoint:
raise QgsProcessingException(
"TypeError: Multipoint Layers are not accepted. Please convert to single geometry layer.")

Expand Down
4 changes: 2 additions & 2 deletions ORStools/proc/matrix_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
QgsProcessingException,
QgsProcessingParameterField,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterEnum,
)

from PyQt5.QtCore import QVariant
Expand Down Expand Up @@ -110,7 +109,8 @@ def processAlgorithm(self, parameters, context, feedback):
destination_field = destination.fields().field(destination_field_name) if destination_field_name else None

# Abort when MultiPoint type
if (source.wkbType() or destination.wkbType()) == 4:
if (QgsWkbTypes.flatType(source.wkbType()) or QgsWkbTypes.flatType(destination.wkbType()))\
== QgsWkbTypes.MultiPoint:
raise QgsProcessingException(
"TypeError: Multipoint Layers are not accepted. Please convert to single geometry layer.")

Expand Down

0 comments on commit c8f38a9

Please sign in to comment.