QGIS/python/plugins/processing/gdal/GdalOgrAlgorithmProvider.py

116 lines
4.8 KiB
Python
Raw Normal View History

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'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
2012-09-15 18:25:25 +03:00
import os
from PyQt4.QtCore import *
from PyQt4.QtGui import *
2013-08-12 20:44:27 +02:00
from processing.core.AlgorithmProvider import AlgorithmProvider
from processing.core.ProcessingLog import ProcessingLog
from processing.script.WrongScriptException import WrongScriptException
2013-08-12 20:44:27 +02:00
from processing.gdal.GdalAlgorithm import GdalAlgorithm
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
from processing.gdal.gdaladdo import gdaladdo
from processing.gdal.ClipByExtent import ClipByExtent
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
class GdalOgrAlgorithmProvider(AlgorithmProvider):
2012-09-15 18:25:25 +03:00
2013-08-12 20:44:27 +02: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:
2012-09-15 18:25:25 +03:00
1)when a python script exist for a given process, it has been adapted
2013-08-12 20:44:27 +02:00
as a processing python script and loaded using the ScriptAlgorithm class.
2012-09-15 18:25:25 +03:00
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'''
def __init__(self):
AlgorithmProvider.__init__(self)
self.createAlgsList()
def scriptsFolder(self):
'''The folder where script algorithms are stored'''
return os.path.dirname(__file__) + "/scripts"
def getDescription(self):
return "GDAL/OGR"
2012-09-15 18:25:25 +03:00
def getName(self):
return "gdalogr"
2012-09-15 18:25:25 +03:00
def getIcon(self):
return QIcon(os.path.dirname(__file__) + "/icons/gdalicon.png")
def _loadAlgorithms(self):
2013-08-12 20:44:27 +02:00
'''This is called each time there is a change in the set of algorithms,
2012-09-15 18:25:25 +03:00
for instance, when the users adds a new model or script. Since this provider
cannot be extended by the user, we create the list in advance and then just
assign it to self.algs'''
self.algs = self.preloadedAlgs
def createAlgsList(self):
#First we populate the list of algorithms with those created extending
2012-09-15 18:25:25 +03:00
#GeoAlgorithm directly (those that execute GDAL using the console)
2012-12-10 00:12:07 +01:00
self.preloadedAlgs = [nearblack(), information(), warp(), translate(),
rgb2pct(), pct2rgb(), merge(), polygonize(),
gdaladdo(), ClipByExtent(),
OgrInfo(), Ogr2Ogr(), OgrSql()]
2012-09-15 18:25:25 +03:00
#And then we add those that are created as python scripts
folder = self.scriptsFolder()
for descriptionFile in os.listdir(folder):
if descriptionFile.endswith("py"):
try:
fullpath = os.path.join(self.scriptsFolder(), descriptionFile)
alg = GdalAlgorithm(fullpath)
self.preloadedAlgs.append(alg)
except WrongScriptException,e:
2013-08-12 20:44:27 +02:00
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,e.msg)
2012-09-15 18:25:25 +03:00
def getSupportedOutputRasterLayerExtensions(self):
return GdalUtils.getSupportedRasterExtensions()
2012-12-10 00:12:07 +01:00
#===========================================================================
# def getSupportedOutputVectorLayerExtensions(self):
# return ["shp", "sqlite"]
#===========================================================================