0

I want to use the "clip raster by extent" tool of PyQGIS.

The doc Clip qgis doc says that there are five parameters :

processing.runalg('gdalogr:cliprasterbyextent', input, no_data, projwin, extra, output)

But when I run it, it answers : ALGORITHM: Clip raster by extent

INPUT <ParameterRaster>
NO_DATA <ParameterString>
PROJWIN <ParameterExtent>
RTYPE <ParameterSelection>
COMPRESS <ParameterSelection>
JPEGCOMPRESSION <ParameterNumber>
ZLEVEL <ParameterNumber>
PREDICTOR <ParameterNumber>
TILED <ParameterBoolean>
BIGTIFF <ParameterSelection>
TFW <ParameterBoolean>
EXTRA <ParameterString>
OUTPUT <OutputRaster>

RTYPE(Output raster type)

0 - Byte
1 - Int16
2 - UInt16
3 - UInt32
4 - Int32
5 - Float32
6 - Float64

COMPRESS(GeoTIFF options. Compression type:)

0 - NONE
1 - JPEG
2 - LZW
3 - PACKBITS
4 - DEFLATE

BIGTIFF(Control whether the created file is a BigTIFF or a classic TIFF)

0 - 
1 - YES
2 - NO
3 - IF_NEEDED
4 - IF_SAFER

So 14 parameters, even so the doc is for 2.18 version and I have 2.18.9 version.

My questions is : How can I know how to fill this field that are not in the doc ? There are some help for rtype, compress and bigtif but not for the others.

I didn't name my topic with Clip tool name as that is not the only tool that make that. Last time,for create grids, I finally followed the advises of python console, but this time I would like to understand more generally how to solve the problem.

J.Delannoy
  • 505
  • 2
  • 18
  • As per the new user [tour] a Question should ask only one question. Asking multiple questions makes this too broad. – Midavalo Jul 03 '17 at 14:17

2 Answers2

3

I can't specifically speak to why there is a difference between between the documentations's number of parameters vs the tool. I have found in general that GDAL, OGR and GRASS tools tend to require a lot more parameters than QGIS algorithms.

In general, I've found the best way to handle the parameter selection for these tools is to open up the processing toolbox, search for the tool of interest (in this case, clip raster by extent) and open it, then expand "Advanced Parameters" (marked in red): enter image description here

Once expanded, it should look like this: enter image description here

In this case, if you look at the list of prameters you provided up top (INPUT, NO_DATA, PROJWIN, etc), it lines up precisely with the list of parameters and options in the tool window. Using this, you can follow through the list and see what is set as default, and get a bit more of an explanation as to what each parameter corresponds to.

Most likely, there are only 5 parameters listed in the docs, as that is the number of non-advanced parameters in the tool, even though the tool requires all parameters to run properly.

EastWest
  • 253
  • 2
  • 14
  • Thank you for your answer :) I checked the advanced parameters in the processing toolbox as you said, but there are only 3 non-advanced parameters and 1 advanced parameters. So unfortunately it does not solve my problem. – J.Delannoy Jul 03 '17 at 12:20
  • @J.Delannoy I have edited my answer with images to show how to view advanced parameters – EastWest Jul 03 '17 at 13:15
  • Thank you for the picture, that is stupid : I though that the advanced parameters were displayed. Then my problem is solved :) – J.Delannoy Jul 03 '17 at 13:16
3

The problem is that the official QGIS Documentation is not always at the most recent up-to-date status because there are a lot of things that continuously change in it and the efforts offered by the volunteers are not always enough for covering the whole job to do (you may consider offering your time for helping the community here).

Having said that, the best way for knowing the syntax of a specific algorithm from the Processing Toolbox is using the alghelp() method. For your case:

import processing
processing.alghelp('gdalogr:cliprasterbyextent')

It will print all the parameters need for correctly run the tool (they must be inserted in the same order as they are listed):

ALGORITHM: Clip raster by extent
    INPUT <ParameterRaster>
    NO_DATA <ParameterString>
    PROJWIN <ParameterExtent>
    RTYPE <ParameterSelection>
    COMPRESS <ParameterSelection>
    JPEGCOMPRESSION <ParameterNumber>
    ZLEVEL <ParameterNumber>
    PREDICTOR <ParameterNumber>
    TILED <ParameterBoolean>
    BIGTIFF <ParameterSelection>
    TFW <ParameterBoolean>
    EXTRA <ParameterString>
    OUTPUT <OutputRaster>


RTYPE(Output raster type)
    0 - Byte
    1 - Int16
    2 - UInt16
    3 - UInt32
    4 - Int32
    5 - Float32
    6 - Float64
COMPRESS(GeoTIFF options. Compression type:)
    0 - NONE
    1 - JPEG
    2 - LZW
    3 - PACKBITS
    4 - DEFLATE
BIGTIFF(Control whether the created file is a BigTIFF or a classic TIFF)
    0 - 
    1 - YES
    2 - NO
    3 - IF_NEEDED
    4 - IF_SAFER

An example of execution for the algorithm is the following (the extent was randomly chosen by me):

input = iface.activeLayer() # load the raster as you want
processing.runalg('gdalogr:cliprasterbyextent', input, '', '318274.544903,318395.855583,4993449.28398,4993527.77913', 5, 4, 75, 6, 1, False, 0, False, '', output)
mgri
  • 16,159
  • 6
  • 47
  • 80
  • Thank you for your answer. I didn't aim to criticize the work done by the community, I know that it's huge and wonderful. I just didn't realized that the tool was from Gdal and the doc from the community, so I didn't understand the difference of number of parameters. Thanks for the tips of alghelp that is what I was searching for. However I hoped that it would give me more information about parameters because as you can see in my post I already had this information. I didn't know how to fill the other parameters. But now I know thanks to your example. – J.Delannoy Jul 03 '17 at 12:51
  • @J.Delannoy Which are the specific parameters on which you would like to have more information? – mgri Jul 03 '17 at 12:57
  • For the PREDICTOR, the TILED and the TFW please. For JPEGCOMPRESSION and BigTif I suppose that it depends on which precision you want and how much place you have, but I have to admit that I don't really know how to choose. But I can search more information on the internet. The ZLEVEL, I guess it's 0 if I have no information about it. – J.Delannoy Jul 03 '17 at 13:04
  • @J.Delannoy I didn't notice you asked 4 different questions in the same question, while you are allowed to ask only one question per question My answer solved your first two problems, so I think the best would be editing your original question by removing the last two question, then accepting the answer you found the most useful and finally ask a new separate question looking for an answer to the last two questions. – mgri Jul 03 '17 at 13:12