3

When calling GdalUtils.version(), the returned information is

"2010100"

While I can identify GDAL2, I´m unsure about the next version steps. It could be 2.1.1 or 2.0.1 or 2.1.1.

Currently, the newest GDAL is 2.1.2 so I assume that it means 2.1.1. Can somebody verify that?

Also, the output of GdalUtils.version() should be updated to return proper version information.

Here is the complete Python script (macOS):

import os
import sys
from qgis.core import *
from osgeo import ogr
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.gui import *
QgsApplication.setPrefixPath(r'/Applications/QGIS.app/Contents', True)
app = QgsApplication([], True)
QgsApplication.initQgis()
sys.path.append(r'/Applications/QGIS.app/Contents/Resources/python/plugins')
from processing.core.Processing import Processing
Processing.initialize()
import processing

from processing.algs.gdal.GdalUtils import GdalUtils
GdalUtils.version()
pat-s
  • 291
  • 1
  • 17

2 Answers2

5

I suppose that the version comes directly from GDAL. See the source code https://trac.osgeo.org/gdal/browser/trunk/gdal/gcore/gdal_version.h. Probably GDAL and QGIS developers would appreciate if you could show a place where to improve the documentation.

The code looks like this:

/* GDAL_COMPUTE_VERSION macro introduced in GDAL 1.10 */
/* Must be used ONLY to compare with version numbers for GDAL >= 1.10 */
#ifndef GDAL_COMPUTE_VERSION
#define GDAL_COMPUTE_VERSION(maj,min,rev) ((maj)*1000000+(min)*10000+(rev)*100)
#endif

With this formula your version is 2.1.1.

user30184
  • 65,331
  • 4
  • 65
  • 118
  • Thanks! Well, my suggesting would be to place proper points between maj , min and rev so that GdalUtils.version() returns 2.1.1 instead of 2010100. I´ll open a ticket. – pat-s Jan 22 '17 at 18:18
  • Isn't that code for computers and not for humans? For computers it is easy to find that 2010100<2010200 but not as easy to compare strings 2.1.1 and 2.1.2, or 2.1.11. – user30184 Jan 22 '17 at 18:25
  • Maybe the output is needed in this format in other functions. Then I´ll just do a local modification. I´ll see what the QGIS team thinks. – pat-s Jan 22 '17 at 20:49
2

According to your path ( /Applications/QGIS.app/Contents/Resources/python/plugins) you work on Mac OS X. If you use a version of KyngChaos, GDAL is installed in /Library/Frameworks/GDAL.framework and you don't need QGIS to return the proper GDAL version information.

If you have followed the procedure outlined in the ReadMe.rtf file (GDAL_Framework-2.1.2-1.dmg)

You can type in the Terminal.app

gdalinfo --version

Or in the Python shell

from osgeo import gdal
print gdal.__version__

Because you can perfectly use the GDAL library without QGIS

gene
  • 54,868
  • 3
  • 110
  • 187
  • My system-wide GDAL is installed using homebrew. Regardless, I try to access QGIS GDAL platform independent using the processing module from QGIS. So I need to use the GdalUtils way. – pat-s Jan 22 '17 at 20:47