3

Is there any possibility to call tools found in the QGIS processing toolbox from the command line, other than using python?

It is my understanding that if you use any GDAL tools, the QGIS gui is just creaing and sending off the shell command for you. Is there any possibility to vice versa start QGIS tools directly to the command line?

As an example one could use the Raster Analysis -> Zonal statistics tool.

A similar question was answered with an ogr command. With this question I want to address this issue in general.

I am looking for a solution which will also work on Linux, since I seek for ways of using the power of QGIS on a cluster. OSgeo4W is therefore not an option.

  • Are you already familiar with the OSGeo4W Shell (typically installed with QGIS I think)? If not, I'd start by looking at that. Hope that helps. – jbchurchill Jan 23 at 15:36
  • I work from Linux so there is no need for the 4W. Do you have anything particular in mind? – loki Jan 23 at 15:50
  • Sorry - I'm just spit-balling. I see a long list of commands when I open that shell. -={ OSGeo4W Shell Commands }=- assistant ogrinfo avcexport ogrlineref avcimport ogrtindex bmp2tiff osgeo4w-setup cs2cs pal2rgb curl pixeltool designer ppm2tiff dllupdate proj example1 psql example2 pylupdate4 fax2ps – jbchurchill Jan 23 at 16:08
3

If you run a QGIS Processing tool from the toolbox, you can then open the Processing History dialog from the Processing menu. Clicking any item in the history will show you an equivalent Python command in the lower half of this dialog.

You can then copy this command and paste into a Python script, which can be called directly from the terminal/bash shell.

There is some standard PyQGIS setup calls you need to make at the start of your script in order to initialise QGIS. This is described in detail in this answer: Using QGIS3 Processing algorithms from standalone PyQGIS scripts (outside of GUI)

1

As people wrote, OSGEO4W shell is the way to go, there is on the path a lot of geoprocessing tools, if not all, that is used internally inside QGIS.

One must that you should really take a look is gdalwarp, it may be used to a big variety of raster operations like reproject, change format extensions, pixel value, and the list goes on and on.

see reference to gdalwarp here

For vector layers another must is ogr2ogr it does simply everything for vector layers.

see reference to ogr2ogr here

A advice, you must pay attention to syntax for input output, it is in this order for gdalwarp, and the inverse (output input) for ogr2ogr.

  • Thank you for your ideas. Unfortunately i am looking for a way to use it on a linux machine. Furthermore, I want to use the specific QGIS tools as for example zonal statistics (as described in the Q). gdal and ogr as well as OTB are no problem. Tried to clarify my Q – loki Jan 23 at 16:54
  • well loki, maybe you could try to mix tools to get your desired result, in my point of view mostly geoprocessing tools are based in small simple tools that form the building blocks to the most advanced analysis. – ckc Jan 24 at 18:57
  • I absolutely agree with you in most cases. However when it comes to more complex tasks, you might introduce more errors when splitting things up. Furthermore I experienced that the fastest way to process data is by finding the best tool from a variety of programs. This is why I asked the Q in the first place. – loki Jan 25 at 5:52

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.