2012-10-05 23:28:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
AlgorithmProvider.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. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
2016-09-21 18:24:26 +02:00
|
|
|
from builtins import object
|
2012-10-05 23:28:47 +02:00
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-05 23:28: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-05 23:28:47 +02:00
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
import os
|
2016-04-22 10:38:48 +02:00
|
|
|
from qgis.PyQt.QtGui import QIcon
|
|
|
|
from qgis.PyQt.QtCore import QCoreApplication
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
from qgis.core import QgsVectorFileWriter
|
2013-10-01 20:52:22 +03:00
|
|
|
from processing.core.ProcessingConfig import Setting, ProcessingConfig
|
2016-04-29 12:00:43 +03:00
|
|
|
from processing.tools import dataobjects
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2015-07-09 14:41:00 +02:00
|
|
|
class AlgorithmProvider(object):
|
2015-08-22 14:29:41 +02:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
"""This is the base class for algorithms providers.
|
|
|
|
|
|
|
|
An algorithm provider is a set of related algorithms, typically
|
|
|
|
from the same external application or related to a common area
|
|
|
|
of analysis.
|
|
|
|
"""
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def __init__(self):
|
2013-10-01 20:52:22 +03:00
|
|
|
# Indicates if the provider should be active by default.
|
|
|
|
# For provider relying on an external software, this should be
|
|
|
|
# False, so the user should activate them manually and install
|
|
|
|
# the required software in advance.
|
2012-09-15 18:25:25 +03:00
|
|
|
self.activate = True
|
|
|
|
self.actions = []
|
|
|
|
self.contextMenuActions = []
|
|
|
|
|
|
|
|
def loadAlgorithms(self):
|
|
|
|
self.algs = []
|
2016-01-08 08:27:22 +01:00
|
|
|
self._loadAlgorithms()
|
|
|
|
for alg in self.algs:
|
|
|
|
alg.provider = self
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
# Methods to be overridden.
|
2012-09-15 18:25:25 +03:00
|
|
|
def _loadAlgorithms(self):
|
2013-10-01 20:52:22 +03:00
|
|
|
"""Algorithm loading should take place here, filling self.algs,
|
|
|
|
which is a list of elements of class GeoAlgorithm. Use that
|
|
|
|
class to create your own algorithms.
|
|
|
|
"""
|
2012-09-15 18:25:25 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
def initializeSettings(self):
|
2013-10-01 20:52:22 +03:00
|
|
|
"""This is the place where you should add config parameters
|
|
|
|
using the ProcessingConfig class.
|
|
|
|
|
|
|
|
This method is called when a provider is added to the
|
|
|
|
Processing framework. By default it just adds a setting to
|
|
|
|
activate or deactivate algorithms from the provider.
|
|
|
|
"""
|
2013-08-12 20:44:27 +02:00
|
|
|
ProcessingConfig.settingIcons[self.getDescription()] = self.getIcon()
|
2013-10-01 20:52:22 +03:00
|
|
|
name = 'ACTIVATE_' + self.getName().upper().replace(' ', '_')
|
|
|
|
ProcessingConfig.addSetting(Setting(self.getDescription(), name,
|
2016-01-08 12:52:19 +01:00
|
|
|
self.tr('Activate'), self.activate))
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def unload(self):
|
2013-10-01 20:52:22 +03:00
|
|
|
"""Do here anything that you want to be done when the provider
|
|
|
|
is removed from the list of available ones.
|
|
|
|
|
|
|
|
This method is called when you remove the provider from
|
|
|
|
Processing. Removal of config setting should be done here.
|
|
|
|
"""
|
|
|
|
name = 'ACTIVATE_' + self.getName().upper().replace(' ', '_')
|
2013-08-12 20:44:27 +02:00
|
|
|
ProcessingConfig.removeSetting(name)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def getName(self):
|
2013-10-01 20:52:22 +03:00
|
|
|
"""Returns the name to use to create the command-line name.
|
|
|
|
Should be a short descriptive name of the provider.
|
|
|
|
"""
|
|
|
|
return 'processing'
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def getDescription(self):
|
2013-10-01 20:52:22 +03:00
|
|
|
"""Returns the full name of the provider.
|
|
|
|
"""
|
2014-10-03 14:44:01 +03:00
|
|
|
return self.tr('Generic algorithm provider')
|
2013-03-31 21:18:27 +02:00
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
def getIcon(self):
|
2016-03-14 20:26:58 +01:00
|
|
|
return QIcon(os.path.dirname(__file__) + '/../images/alg.png')
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def getSupportedOutputRasterLayerExtensions(self):
|
2013-10-01 20:52:22 +03:00
|
|
|
return ['tif']
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def getSupportedOutputVectorLayerExtensions(self):
|
2016-04-29 12:00:43 +03:00
|
|
|
return dataobjects.getSupportedOutputVectorLayerExtensions()
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def getSupportedOutputTableExtensions(self):
|
2013-10-01 20:52:22 +03:00
|
|
|
return ['csv']
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def supportsNonFileBasedOutput(self):
|
2012-09-27 08:53:23 +03:00
|
|
|
return False
|
2014-10-03 14:44:01 +03:00
|
|
|
|
2016-01-08 08:27:22 +01:00
|
|
|
def canBeActivated(self):
|
|
|
|
return True
|
|
|
|
|
2014-10-03 14:44:01 +03:00
|
|
|
def tr(self, string, context=''):
|
|
|
|
if context == '':
|
2015-01-14 20:57:56 +02:00
|
|
|
context = self.__class__.__name__
|
2016-03-14 20:26:58 +01:00
|
|
|
return QCoreApplication.translate(context, string)
|