3

I am using the code in "QGIS Python Programming Cookbook", testing the code to learn about programming in QGIS. But when I try to reproject a raster, I get the error: Error: Wrong number of parameters. When I type in processing.alghelp("gdalogr:warpreproject") it returns "Algorithm not found". Here is my code:

import processing
from processing.core.Processing import Processing
from qgis.core import *
from qgis.gui import *

Processing.initialize()
Processing.updateAlgsList()
#load a raster layer and set a COORDINATE SYSTEM
rasterLyr = QgsRasterLayer("G:\...\INPUT.ecw","MTN50")
print rasterLyr.isValid()
crs = QgsCoordinateReferenceSystem(25830, QgsCoordinateReferenceSystem.EpsgCrsId)
rasterLyr.setCrs(crs)

QgsMapLayerRegistry.instance().addMapLayers([rasterLyr])
#now, REPROJECT
processing.runalg("gdalogr:warpreproject", rasterLyr, "EPSG:25830", "EPSG:3722", None, 0, 0, 0, 0, 2, "\0, C:\..\output.ecw")

I am using QGIS Essen, 2.14. Is it a problem of using a code that isn't updated?

0
3

I noticed your comment on a previous post just now. You need use warpreproject, not warpproject.

import processing
processing.alghelp("gdalogr:warpreproject")

ALGORITHM: Warp (reproject)
    INPUT <ParameterRaster>
    SOURCE_SRS <ParameterCrs>
    DEST_SRS <ParameterCrs>
    NO_DATA <ParameterString>
    TR <ParameterNumber>
    METHOD <ParameterSelection>
    RTYPE <ParameterSelection>
    COMPRESS <ParameterSelection>
    JPEGCOMPRESSION <ParameterNumber>
    ZLEVEL <ParameterNumber>
    PREDICTOR <ParameterNumber>
    TILED <ParameterBoolean>
    BIGTIFF <ParameterSelection>
    TFW <ParameterBoolean>
    EXTRA <ParameterString>
    OUTPUT <OutputRaster>

Note that it requires 16 parameters compared to your 10 :)

Tested this on QGIS 2.14.1-Essen with Processing version 2.12.2

5
  • I have made that correction, it runs - after execfile(..) it returns true because the isValid() - but keep saying "Algorithm not found", nevertheless, I open my toolbox and Reproject is available... I keep it activated in my plugin manager. According to the number of parameters, it doesn't complain now about number of them
    – user64823
    Apr 18 '16 at 15:11
  • @user64823 - Are you running your code inside QGIS (i.e. the Python console)? And are you getting an output?
    – Joseph
    Apr 18 '16 at 15:15
  • I have written that code in the Text Editor of QGIS, sorry I forgot to tell so. Then, I run it and output is: True, Error: Algorithm not found Layer is loaded to the interface.
    – user64823
    Apr 18 '16 at 15:17
  • Sorry so much, I have correct one parameter and it works (I have to input all the parameters correctly) because it now, exists. Thank you...
    – user64823
    Apr 18 '16 at 15:24
  • I have already : processing.runalg("gdalogr:warpreproject", rasterLyr, "EPSG:25830", "EPSG:3722", -9999, 0, 0, 0, 0, 10, 0, 0, False, 0, False, "Yes", "C:\...\MYREPROJECT.ecw") And it returns :Wrong parameter value: 0 ; I follow all the types of parameters....
    – user64823
    Apr 18 '16 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.