3

I want fingertip access to the GDAL/OGR tools, particularly ogrinfo, from the main QGIS screen.

I currently run ogrinfo.exe in a DOS shell but this seems clumsy.

Installing the GDAL Tools plugin only accesses the raster tools. (The User Guide confirms this.)

But in my Windows QGIS folder there is a file:

 C:\Program Files\QGIS283\apps\qgis-ltr\python\plugins\processing\algs\gdal\ogrinfo.py

Does this perhaps somehow let me run ogrinfo from the Python console?

6

Assuming you downloaded and installed QGIS through the OSGeo4W Network Installer you will have access to the QGIS Processing Framework. Among other algorithm providers this will provide you access to the GDAL/OGR Provider which includes (under OGR miscellaneous) the Information tool (which is ogrinfo). The results will be output to a temporary HTML file.

If you do want to access it from the Python console you can run the algorithm from there as well, for example:

>>> lyr = iface.activeLayer()
>>> import processing
>>> processing.runalg('gdalogr:information', lyr, None)
{'OUTPUT': u'/var/folders/pd/ydjvghhj0xx7jr0_0bzz85n80000gn/T/processing/6feb7dc9a3894ed5a5276a3d48f94180/OUTPUT.html'}

Note that you still have to open the HTML file yourself, so it may be easier to just use the processing GUI. Or you could try:

>>> import os
>>> os.startfile(processing.runalg('gdalogr:information', lyr, None)["OUTPUT"])
  • 1
    This was a preposterously useful answer, pointing me to the 'Processing Framework' chapter of the User Guide which greatly rewards careful study, and culminating in the coding of my first Python script from your example code. The os.startfile (...) method does indeed fire the browser! For anyone interested: gdalogr:information always calls ogrinfo with the -so (summary output) option. On the precept that too much information is better than too little, a cheap and dirty little fix is to edit ogrinfo.py and comment the line arguments.append('-so'). – Bad Loser Oct 4 '15 at 22:46
  • @BadLoser Happy to help! If you're looking at Processing it's worth taking a look at the Graphical Modeler as well - it can be a lot easier than writing scripts if you only need to string together the Processing algorithms. – om_henners Oct 5 '15 at 13:34
0

Update. The ogrinfo.exe -so option is now handled by ogrinfo.py, the python wrapper!

Example: Analysis of shape file with suppression of the summary only option

Start a QGIS project and open the Shape file of interest as a new vector layer.

Using Plugins/Python Console, create and run the following python script:

ipLayer = iface.activeLayer()
opHTML = 'C:\Users\DAZ\Desktop\shapeHTML.html'
import processing
import os
os.startfile(processing.runalg('gdalogr:information', ipLayer, 0, opHTML)["OUTPUT"])

Your browser gets fired and the full analysis becomes immediately visible. The -so option is controlled by the third parameter 0=full 1=summary

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.