2012-10-04 19:33:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
GdalAlgorithmProvider.py
|
|
|
|
---------------------
|
|
|
|
Date : August 2012
|
|
|
|
Copyright : (C) 2012 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-04 19:33:47 +02:00
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-04 19:33:47 +02:00
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
import os
|
|
|
|
from PyQt4.QtCore import *
|
|
|
|
from PyQt4.QtGui import *
|
2013-09-12 21:28:27 +03:00
|
|
|
|
2013-08-12 20:44:27 +02:00
|
|
|
from processing.core.AlgorithmProvider import AlgorithmProvider
|
|
|
|
from processing.core.ProcessingLog import ProcessingLog
|
2013-09-12 21:28:27 +03:00
|
|
|
from processing.script.WrongScriptException import WrongScriptException
|
|
|
|
|
2013-08-12 20:44:27 +02:00
|
|
|
from processing.gdal.GdalAlgorithm import GdalAlgorithm
|
2013-09-12 21:28:27 +03:00
|
|
|
from processing.gdal.GdalUtils import GdalUtils
|
|
|
|
|
2013-08-12 20:44:27 +02:00
|
|
|
from processing.gdal.nearblack import nearblack
|
|
|
|
from processing.gdal.information import information
|
|
|
|
from processing.gdal.warp import warp
|
|
|
|
from processing.gdal.rgb2pct import rgb2pct
|
|
|
|
from processing.gdal.translate import translate
|
|
|
|
from processing.gdal.pct2rgb import pct2rgb
|
|
|
|
from processing.gdal.merge import merge
|
|
|
|
from processing.gdal.polygonize import polygonize
|
2013-09-12 21:28:27 +03:00
|
|
|
from processing.gdal.gdaladdo import gdaladdo
|
|
|
|
from processing.gdal.ClipByExtent import ClipByExtent
|
2013-09-14 14:02:47 +03:00
|
|
|
from processing.gdal.ClipByMask import ClipByMask
|
2013-09-14 14:35:14 +03:00
|
|
|
from processing.gdal.contour import contour
|
2013-09-14 18:24:39 +03:00
|
|
|
from processing.gdal.rasterize import rasterize
|
2013-09-15 17:47:27 +03:00
|
|
|
from processing.gdal.proximity import proximity
|
2013-09-15 20:20:35 +03:00
|
|
|
from processing.gdal.sieve import sieve
|
|
|
|
from processing.gdal.fillnodata import fillnodata
|
2013-09-26 21:03:10 +03:00
|
|
|
from processing.gdal.extractprojection import ExtractProjection
|
2013-09-30 16:14:56 +03:00
|
|
|
from processing.gdal.gdal2xyz import gdal2xyz
|
2013-10-13 13:46:38 +03:00
|
|
|
from processing.gdal.hillshade import hillshade
|
2013-09-12 21:28:27 +03:00
|
|
|
|
|
|
|
from processing.gdal.ogr2ogr import Ogr2Ogr
|
|
|
|
from processing.gdal.ogrinfo import OgrInfo
|
|
|
|
from processing.gdal.ogrsql import OgrSql
|
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2012-11-10 00:31:01 +01:00
|
|
|
class GdalOgrAlgorithmProvider(AlgorithmProvider):
|
2013-10-01 20:52:22 +03:00
|
|
|
"""This provider incorporates GDAL-based algorithms into the
|
|
|
|
Processing framework.
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
Algorithms have been implemented using two different mechanisms,
|
|
|
|
which should serve as an example of different ways of extending
|
2013-08-12 20:44:27 +02:00
|
|
|
the processing capabilities of QGIS:
|
2013-10-01 20:52:22 +03:00
|
|
|
1. when a python script exist for a given process, it has been
|
|
|
|
adapted as a Processing python script and loaded using the
|
|
|
|
ScriptAlgorithm class. This algorithms call GDAL using its
|
|
|
|
Python bindings.
|
|
|
|
2. Other algorithms are called directly using the command line
|
|
|
|
interface. These have been implemented individually extending
|
|
|
|
the GeoAlgorithm class.
|
|
|
|
"""
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
AlgorithmProvider.__init__(self)
|
|
|
|
self.createAlgsList()
|
|
|
|
|
|
|
|
def scriptsFolder(self):
|
2013-10-01 20:52:22 +03:00
|
|
|
"""The folder where script algorithms are stored.
|
|
|
|
"""
|
|
|
|
return os.path.dirname(__file__) + '/scripts'
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def getDescription(self):
|
2013-10-01 20:52:22 +03:00
|
|
|
return 'GDAL/OGR'
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def getName(self):
|
2013-10-01 20:52:22 +03:00
|
|
|
return 'gdalogr'
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def getIcon(self):
|
2013-10-01 20:52:22 +03:00
|
|
|
return QIcon(os.path.dirname(__file__) + '/icons/gdalicon.png')
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def _loadAlgorithms(self):
|
|
|
|
self.algs = self.preloadedAlgs
|
|
|
|
|
|
|
|
def createAlgsList(self):
|
2013-10-01 20:52:22 +03:00
|
|
|
# First we populate the list of algorithms with those created
|
|
|
|
# extending GeoAlgorithm directly (those that execute GDAL
|
|
|
|
# using the console)
|
2012-12-10 00:12:07 +01:00
|
|
|
self.preloadedAlgs = [nearblack(), information(), warp(), translate(),
|
2013-10-01 20:52:22 +03:00
|
|
|
rgb2pct(), pct2rgb(), merge(), polygonize(), gdaladdo(),
|
|
|
|
ClipByExtent(), ClipByMask(), contour(), rasterize(), proximity(),
|
|
|
|
sieve(), fillnodata(), ExtractProjection(), gdal2xyz(),
|
2013-10-13 13:46:38 +03:00
|
|
|
hillshade(),
|
2013-10-01 20:52:22 +03:00
|
|
|
# ----- OGR tools -----
|
|
|
|
OgrInfo(), Ogr2Ogr(), OgrSql(),
|
|
|
|
]
|
|
|
|
|
|
|
|
# And then we add those that are created as python scripts
|
2012-09-15 18:25:25 +03:00
|
|
|
folder = self.scriptsFolder()
|
2013-09-26 21:03:10 +03:00
|
|
|
if os.path.exists(folder):
|
|
|
|
for descriptionFile in os.listdir(folder):
|
2013-10-01 20:52:22 +03:00
|
|
|
if descriptionFile.endswith('py'):
|
2013-09-26 21:03:10 +03:00
|
|
|
try:
|
2013-10-01 20:52:22 +03:00
|
|
|
fullpath = os.path.join(self.scriptsFolder(),
|
|
|
|
descriptionFile)
|
2013-09-26 21:03:10 +03:00
|
|
|
alg = GdalAlgorithm(fullpath)
|
|
|
|
self.preloadedAlgs.append(alg)
|
2013-10-01 20:52:22 +03:00
|
|
|
except WrongScriptException, e:
|
|
|
|
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, e.msg)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def getSupportedOutputRasterLayerExtensions(self):
|
|
|
|
return GdalUtils.getSupportedRasterExtensions()
|