mkoenigb / ProcessX

Repository for QGIS ProcessX Plug-In
GNU General Public License v3.0
3 stars 3 forks source link

Unexpected type int error running Nearest Points to Path #3

Closed dm413 closed 1 year ago

dm413 commented 1 year ago

I am trying to use your Nearest Points to Path algorithm to convert points to a line. But I get an "unexpected type" error.

I select some points in a points layer, then run the tool. Turn on the selected points checkmark, set order-by to $X, and leave the rest of the settings as default. I have tried variations of this, including not changing any settings, and using all points in the layer, and get the same error.

The native point-to-path algorithm works fine with my data.

Am I doing something wrong, or is this a bug?

Full output is below. QGIS 3.30.1 on Windows 10.

QGIS version: 3.30.1-'s-Hertogenbosch
QGIS code revision: 9035a01e
Qt version: 5.15.3
Python version: 3.9.5
GDAL version: 3.6.3
GEOS version: 3.11.2-CAPI-1.17.2
PROJ version: Rel. 9.2.0, March 1st, 2023
PDAL version: 2.5.2 (git-version: 57c4e7)
Algorithm started at: 2023-04-16T10:22:52
Algorithm 'Nearest Points To Path' starting…
Input parameters:
{ 'ADD_PATH_DISTS' : False, 'ADD_PATH_FIDS' : False, 'ALLOW_SELF_CROSSING' : True, 'HANDLE_INVALID' : 1, 'MAX_DIST' : 0, 'MAX_POINTS' : 0, 'OUTPUT' : 'TEMPORARY_OUTPUT', 'SOURCE_CUSTOM_ID' : '', 'SOURCE_FILTER_EXPRESSION' : '', 'SOURCE_GROUPBY_EXPRESSION' : '', 'SOURCE_LYR' : QgsProcessingFeatureSourceDefinition('D:\\Home\\FOF\\Projects\\PronghornCorridor\\PronghornCorridorGIS\\DuffMesaGIS\\DuffMesa_DeffFlat_BottomWire\\DuffMesa_DeffFlat_BottomWire.shp', selectedFeaturesOnly=True, featureLimit=-1, geometryCheck=QgsFeatureRequest.GeometryAbortOnInvalid), 'SOURCE_LYR_ORDERBY' : '$X' }

Prepare processing...
Traceback (most recent call last):
File "C:\Users/<username>/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ProcessX\algorithms\vector_creation\NearestPointsToPath.py", line 117, in processAlgorithm
(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
TypeError: QgsProcessingAlgorithm.parameterAsSink(): argument 5 has unexpected type 'int'

Execution failed after 0.03 seconds

Loading resulting layers
Algorithm 'Nearest Points To Path' finished

Thanks,

mkoenigb commented 1 year ago

Thanks for reporting @dm413,

it is not really a bug, but a change in QGIS v3.30. The 5th argument of parameterAsSink now has to be a QgsWkbType: https://qgis.org/pyqgis/3.30/core/QgsProcessingAlgorithm.html#qgis.core.QgsProcessingAlgorithm.parameterAsSink. In earlier versions it could also be an integer.

I changed this line from

        (sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
                                               output_layer_fields, 2,
                                               source_layer.sourceCrs())

to

        (sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
                                               output_layer_fields, QgsWkbTypes.LineString, 
                                               source_layer.sourceCrs())

You can either do the same or re-download the algorithm or entire plugin from this master: https://github.com/mkoenigb/ProcessX/archive/refs/heads/main.zip. Alternatively you could also use an older version than 3.30, such as 3.16.

dm413 commented 1 year ago

This works. Thank you!