Friday 22 December 2017

python - GDAL version in QGIS


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()

Answer



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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...