Gooong / LeastCostPath

The Least Cost Path Plugin for QGIS
https://plugins.qgis.org/plugins/leastcostpath/
GNU General Public License v3.0
24 stars 12 forks source link

LeastCostPath does not run with QgsVectorLayer #3

Closed nagyrobir closed 5 years ago

nagyrobir commented 5 years ago

Hei! I am trying to run the LeastCostPath via a Python script.

vlayer = QgsVectorLayer("D:\\tst\\start.shp", "start", "ogr")
vlayer2 = QgsVectorLayer("D:\\tst\\end.shp", "end", "ogr")
test=processing.run("Cost distance analysis:Least Cost Path", { 'BOOLEAN_OUTPUT_LINEAR_REFERENCE' : False, 'INPUT_COST_RASTER' : 'D:/tst/cost.tif', 'INPUT_END_LAYER' : vlayer2, 'INPUT_RASTER_BAND' : 1, 'INPUT_START_LAYER' : vlayer, 'OUTPUT' : 'memory:' })

When i try to run the script i get the following error:

Traceback (most recent call last):
  File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\code.py", line 91, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "C:/PROGRA~1/QGIS3~1.2/apps/qgis/./python/plugins\processing\tools\general.py", line 96, in run
    return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)
  File "C:/PROGRA~1/QGIS3~1.2/apps/qgis/./python/plugins\processing\core\Processing.py", line 189, in runAlgorithm
    raise QgsProcessingException(msg)
_core.QgsProcessingException: There were errors executing the algorithm.

Am i passing the parameters incorrectly or the function cannot handle QgsVectorLayer as an input? Thank you.

nagyrobir commented 5 years ago

I apologize. I actually forgot to set the layer CRS. Everything works like a charm! Thank you for this great program!