Skip to content

Commit

Permalink
fixed #6571, #6619 and problem with missing arrows in modeler
Browse files Browse the repository at this point in the history
added first draft of geoserver tools
nviz is back in grass tools
  • Loading branch information
volaya committed Nov 5, 2012
1 parent a4e4999 commit 983535f
Show file tree
Hide file tree
Showing 46 changed files with 4,203 additions and 278 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -45,4 +45,6 @@ qgis-test.ctest
i18n/*.qm
.project
.pydevproject
.idea
.idea
/python/plugins/sextante/resources_rc.py
/python/plugins/sextante/about/ui_aboutdialogbase.py
2 changes: 2 additions & 0 deletions python/plugins/sextante/core/Sextante.py
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from sextante.servertools.GeoServerToolsAlgorithmProvider import GeoServerToolsAlgorithmProvider


__author__ = 'Victor Olaya'
Expand Down Expand Up @@ -130,6 +131,7 @@ def initialize():
Sextante.addProvider(GrassAlgorithmProvider())
Sextante.addProvider(ScriptAlgorithmProvider())
Sextante.addProvider(TauDEMAlgorithmProvider())
Sextante.addProvider(GeoServerToolsAlgorithmProvider())
Sextante.modeler.initializeSettings();
#and initialize
SextanteLog.startLogging()
Expand Down
57 changes: 57 additions & 0 deletions python/plugins/sextante/database/DatabaseToolsAlgorithmProvider.py
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
DatabaseToolProvider.py
---------------------
Date : October 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__ = 'October 2012'
__copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from sextante.core.AlgorithmProvider import AlgorithmProvider
from PyQt4 import QtGui
import os

class DatabaseToolsAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
self.alglist = []#PostGISSQL(), ImportIntoPostGIS(), CreateTable()]

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)


def unload(self):
AlgorithmProvider.unload(self)


def getName(self):
return "database"

def getDescription(self):
return "Database tools"

def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/postgis.png")

def _loadAlgorithms(self):
self.algs = self.alglist

def supportsNonFileBasedOutput(self):
return True
Empty file.
6 changes: 6 additions & 0 deletions python/plugins/sextante/gdal/translate.py
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from sextante.parameters.ParameterString import ParameterString

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand All @@ -34,6 +35,7 @@ class translate(GeoAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"
EXTRA = "EXTRA"

def getIcon(self):
filepath = os.path.dirname(__file__) + "/icons/translate.png"
Expand All @@ -43,14 +45,18 @@ def defineCharacteristics(self):
self.name = "translate"
self.group = "Conversion"
self.addParameter(ParameterRaster(translate.INPUT, "Input layer", False))
self.addParameter(ParameterString(translate.EXTRA, "Additional creation parameters"))
self.addOutput(OutputRaster(translate.OUTPUT, "Output layer"))

def processAlgorithm(self, progress):
commands = ["gdal_translate"]
commands.append("-of")
out = self.getOutputValue(translate.OUTPUT)
extra = self.getOutputValue(translate.EXTRA)
commands.append(GdalUtils.getFormatShortNameFromFilename(out))
commands.append(extra)
commands.append(self.getParameterValue(translate.INPUT))
commands.append(out)


GdalUtils.runGdal(commands, progress)
7 changes: 2 additions & 5 deletions python/plugins/sextante/grass/GrassAlgorithmProvider.py
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from sextante.grass.nviz import nviz

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand All @@ -37,10 +38,6 @@ class GrassAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
#=======================================================================
# self.actions.append(DefineGrassRegionAction())
# self.actions.append(DefineGrassRegionFromLayerAction())
#=======================================================================
self.createAlgsList() #preloading algorithms to speed up

def initializeSettings(self):
Expand Down Expand Up @@ -76,7 +73,7 @@ def createAlgsList(self):
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not open GRASS algorithm: " + descriptionFile)
except Exception,e:
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not open GRASS algorithm: " + descriptionFile)
#self.preloadedAlgs.append(nviz())
self.preloadedAlgs.append(nviz())

def _loadAlgorithms(self):
self.algs = self.preloadedAlgs
Expand Down
1 change: 0 additions & 1 deletion python/plugins/sextante/gui/ParametersPanel.py
Expand Up @@ -54,7 +54,6 @@
from sextante.outputs.OutputRaster import OutputRaster
from sextante.outputs.OutputTable import OutputTable
from sextante.outputs.OutputVector import OutputVector
from sextante.outputs.OutputNumber import OutputNumber
from sextante.parameters.ParameterString import ParameterString

class ParametersPanel(QtGui.QWidget):
Expand Down
Binary file added python/plugins/sextante/images/geoserver.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions python/plugins/sextante/modeler/ModelerAlgorithm.py
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from sextante.outputs.OutputString import OutputString

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand Down Expand Up @@ -436,6 +437,8 @@ def getOutputType(self, i, outname):
return "output html"
elif isinstance(out, OutputNumber):
return "output number"
elif isinstance(out, OutputString):
return "output string"


def getAsPythonCode(self):
Expand Down
13 changes: 9 additions & 4 deletions python/plugins/sextante/modeler/ModelerArrowItem.py
Expand Up @@ -64,10 +64,14 @@ def endItem(self):
return self.myEndItem

def boundingRect(self):
extra = (self.pen().width() + 20) / 2.0
p1 = self.line().p1()
p2 = self.line().p2()
return QtCore.QRectF(p1, QtCore.QSizeF(p2.x() - p1.x(), p2.y() - p1.y())).normalized().adjusted(-extra, -extra, extra, extra)
#this is a quick fix to avoid arrows not being drawn
return QtCore.QRectF(0, 0, 4000,4000)
#=======================================================================
# extra = (self.pen().width() + 20) / 2.0
# p1 = self.line().p1()
# p2 = self.line().p2()
# return QtCore.QRectF(p1, QtCore.QSizeF(p2.x() - p1.x(), p2.y() - p1.y())).normalized().adjusted(-extra, -extra, extra, extra)
#=======================================================================

def shape(self):
path = super(ModelerArrowItem, self).shape()
Expand Down Expand Up @@ -123,3 +127,4 @@ def paint(self, painter, option, widget=None):

painter.drawLine(line)
painter.drawPolygon(self.arrowHead)

15 changes: 15 additions & 0 deletions python/plugins/sextante/modeler/ModelerParametersDialog.py
Expand Up @@ -17,6 +17,7 @@
***************************************************************************
"""
from sextante.parameters.ParameterCrs import ParameterCrs
from sextante.outputs.OutputString import OutputString

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand Down Expand Up @@ -317,6 +318,20 @@ def getStrings(self):
for param in params:
if isinstance(param, ParameterString):
strings.append(AlgorithmAndParameter(AlgorithmAndParameter.PARENT_MODEL_ALGORITHM, param.name, "", param.description))

if self.algIndex is None:
dependent = []
else:
dependent = self.model.getDependentAlgorithms(self.algIndex)
dependent.append(self.algIndex)

i=0
for alg in self.model.algs:
if i not in dependent:
for out in alg.outputs:
if isinstance(out, OutputString):
strings.append(AlgorithmAndParameter(i, out.name, alg.name, out.description))
i+=1
return strings

def getTableFields(self):
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/sextante/modeler/ModelerScene.py
Expand Up @@ -37,6 +37,7 @@ def __init__(self, parent=None):
super(ModelerScene, self).__init__(parent)
self.paramItems = []
self.algItems = []
self.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex);

def getParameterPositions(self):
pos = []
Expand Down Expand Up @@ -116,8 +117,7 @@ def paintModel(self, model):
for sourceItem in sourceItems:
arrow = ModelerArrowItem(sourceItem, self.algItems[iAlg])
self.addItem(arrow)
iAlg+=1

iAlg+=1

def mousePressEvent(self, mouseEvent):
if (mouseEvent.button() != QtCore.Qt.LeftButton):
Expand Down
4 changes: 1 addition & 3 deletions python/plugins/sextante/modeler/ModelerUtils.py
Expand Up @@ -24,7 +24,6 @@
__revision__ = '$Format:%H$'

import os
from sextante.core.SextanteUtils import SextanteUtils
from sextante.core.SextanteUtils import mkdir
from sextante.core.SextanteConfig import SextanteConfig

Expand All @@ -37,8 +36,7 @@ class ModelerUtils:
def modelsFolder():
folder = SextanteConfig.getSetting(ModelerUtils.MODELS_FOLDER)
if folder == None:
#folder = os.path.join(os.path.dirname(__file__), "models")
folder = SextanteUtils.userFolder() + os.sep + "models"

This comment has been minimized.

Copy link
@slarosa

slarosa Nov 5, 2012

Member

Hi Victor, you should revert this line in order to avoid permission error at least in unix system !

This comment has been minimized.

Copy link
@volaya

volaya Nov 5, 2012

Author Contributor

shouldn't the user have permission to use that folder? it is the folder where the plugin is installed, in the .qgis folder. That's where qgis can install new plugins...

This comment has been minimized.

Copy link
@slarosa

slarosa Nov 6, 2012

Member

Now that sextante is in core os.path.dirname(file) returns this error:

Traceback (most recent call last):
  File "/usr/local/share/qgis/python/qgis/utils.py", line 188, in startPlugin
    plugins[packageName] = package.classFactory(iface)
  File "/usr/local/share/qgis/python/plugins/sextante/__init__.py", line 46, in classFactory
    return SextantePlugin(iface)
  File "/usr/local/share/qgis/python/plugins/sextante/SextantePlugin.py", line 56, in __init__
    Sextante.initialize()
  File "/usr/local/share/qgis/python/plugins/sextante/core/Sextante.py", line 135, in initialize
    Sextante.modeler.initializeSettings();
  File "/usr/local/share/qgis/python/plugins/sextante/modeler/ModelerAlgorithmProvider.py", line 49, in initializeSettings
    SextanteConfig.addSetting(Setting(self.getDescription(), ModelerUtils.MODELS_FOLDER, "Models folder", ModelerUtils.modelsFolder()))
  File "/usr/local/share/qgis/python/plugins/sextante/modeler/ModelerUtils.py", line 41, in modelsFolder
    mkdir(folder)
  File "/usr/local/share/qgis/python/plugins/sextante/core/SextanteUtils.py", line 87, in mkdir
    os.mkdir(newdir)
OSError: [Errno 13] Permesso negato: '/usr/local/share/qgis/python/plugins/sextante/modeler/models'
folder = os.path.join(os.path.dirname(__file__), "models")
mkdir(folder)

return folder
Expand Down
75 changes: 75 additions & 0 deletions python/plugins/sextante/modeler/models/watersheds.model
@@ -0,0 +1,75 @@
NAME:Watersheds from DEM
GROUP:[Sample models]
PARAMETER:ParameterRaster|RASTERLAYER_DEM|DEM|False
458.0,50.0
PARAMETER:ParameterNumber|NUMBER_INITIATIONTHRESHOLD|Initiation Threshold|None|None|10000000.0
257.0,403.0
VALUE:HARDCODEDPARAMVALUE_INIT_VALUE_1===10000000
VALUE:HARDCODEDPARAMVALUE_SPLIT_3===0
VALUE:HARDCODEDPARAMVALUE_Method_0===0
VALUE:HARDCODEDPARAMVALUE_INIT_METHOD_1===2
VALUE:HARDCODEDPARAMVALUE_CALC_METHOD_4===0
VALUE:HARDCODEDPARAMVALUE_CLASS_ID_3===0
VALUE:HARDCODEDPARAMVALUE_STEP_0===1
VALUE:HARDCODEDPARAMVALUE_MINLEN_1===10
VALUE:HARDCODEDPARAMVALUE_DOLINEAR _0===True
VALUE:HARDCODEDPARAMVALUE_MINSIZE_2===0
VALUE:HARDCODEDPARAMVALUE_CLASS_ALL_3===1
VALUE:HARDCODEDPARAMVALUE_LINEARTHRS_0===500.0
VALUE:HARDCODEDPARAMVALUE_CONVERGENCE_0===1.0
VALUE:HARDCODEDPARAMVALUE_DIV_CELLS_1===10
ALGORITHM:saga:catchmentarea(parallel)
260.0,172.0
-1|RASTERLAYER_DEM
None
None
None
None
-1|HARDCODEDPARAMVALUE_STEP_0
-1|HARDCODEDPARAMVALUE_Method_0
-1|HARDCODEDPARAMVALUE_DOLINEAR _0
-1|HARDCODEDPARAMVALUE_LINEARTHRS_0
None
None
-1|HARDCODEDPARAMVALUE_CONVERGENCE_0
None
None
None
None
None
None
None
None
ALGORITHM:saga:channelnetwork
447.0,291.0
-1|RASTERLAYER_DEM
None
0|CAREA
-1|HARDCODEDPARAMVALUE_INIT_METHOD_1
-1|NUMBER_INITIATIONTHRESHOLD
None
-1|HARDCODEDPARAMVALUE_DIV_CELLS_1
None
-1|HARDCODEDPARAMVALUE_MINLEN_1
None
None
None
ALGORITHM:saga:watershedbasins
730.0,182.0
-1|RASTERLAYER_DEM
1|CHNLNTWRK
None
-1|HARDCODEDPARAMVALUE_MINSIZE_2
None
ALGORITHM:saga:vectorisinggridclasses
864.0,330.0
2|BASINS
-1|HARDCODEDPARAMVALUE_CLASS_ALL_3
-1|HARDCODEDPARAMVALUE_CLASS_ID_3
-1|HARDCODEDPARAMVALUE_SPLIT_3
None
ALGORITHM:ftools:export/addgeometrycolumns
655.0,442.0
3|POLYGONS
-1|HARDCODEDPARAMVALUE_CALC_METHOD_4
Watersheds
4 changes: 2 additions & 2 deletions python/plugins/sextante/outputs/OutputFactory.py
Expand Up @@ -16,7 +16,6 @@
* *
***************************************************************************
"""

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
Expand All @@ -29,12 +28,13 @@
from sextante.outputs.OutputVector import OutputVector
from sextante.outputs.OutputNumber import OutputNumber
from sextante.outputs.OutputFile import OutputFile
from sextante.outputs.OutputString import OutputString

class OutputFactory():

@staticmethod
def getFromString(s):
classes = [OutputRaster, OutputVector, OutputTable, OutputHTML, OutputNumber, OutputFile]
classes = [OutputRaster, OutputVector, OutputTable, OutputHTML, OutputNumber, OutputFile, OutputString]
for clazz in classes:
if s.startswith(clazz().outputTypeName()):
tokens = s[len(clazz().outputTypeName())+1:].split("|")
Expand Down

7 comments on commit 983535f

@slarosa
Copy link
Member

@slarosa slarosa commented on 983535f Nov 5, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Victor,
Sextante seems broken to this revision !
Can you take a look at it, please ?

@volaya
Copy link
Contributor Author

@volaya volaya commented on 983535f Nov 5, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@volaya
Copy link
Contributor Author

@volaya volaya commented on 983535f Nov 5, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dakcarto
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Victor,

Don't know if it is related to this commit, but now getting the following on Sextante load, at launch of QGIS:

Couldn't load plugin sextante due an error when calling its classFactory() method

Traceback (most recent call last):
  File "/Users/larrys/QGIS/github.com/build/output/python/qgis/utils.py", line 188, in startPlugin
    plugins[packageName] = package.classFactory(iface)
  File "/Users/larrys/QGIS/github.com/build/output/python/plugins/sextante/__init__.py", line 45, in classFactory
    from sextante.SextantePlugin import SextantePlugin
  File "/Users/larrys/QGIS/github.com/build/output/python/qgis/utils.py", line 384, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/Users/larrys/QGIS/github.com/build/output/python/plugins/sextante/SextantePlugin.py", line 34, in 
    from sextante.core.Sextante import Sextante
  File "/Users/larrys/QGIS/github.com/build/output/python/qgis/utils.py", line 384, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/Users/larrys/QGIS/github.com/build/output/python/plugins/sextante/core/Sextante.py", line 19, in 
    from sextante.servertools.GeoServerToolsAlgorithmProvider import GeoServerToolsAlgorithmProvider
  File "/Users/larrys/QGIS/github.com/build/output/python/qgis/utils.py", line 384, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
ImportError: No module named servertools.GeoServerToolsAlgorithmProvider

@slarosa
Copy link
Member

@slarosa slarosa commented on 983535f Nov 5, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't work here !

Traceback (most recent call last):
File "/usr/local/share/qgis/python/qgis/utils.py", line 188, in startPlugin
plugins[packageName] = package.classFactory(iface)
File "/usr/local/share/qgis/python/plugins/sextante/init.py", line 45, in classFactory
from sextante.SextantePlugin import SextantePlugin
File "/usr/local/share/qgis/python/qgis/utils.py", line 384, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/usr/local/share/qgis/python/plugins/sextante/SextantePlugin.py", line 34, in
from sextante.core.Sextante import Sextante
File "/usr/local/share/qgis/python/qgis/utils.py", line 384, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/usr/local/share/qgis/python/plugins/sextante/core/Sextante.py", line 19, in
from sextante.servertools.GeoServerToolsAlgorithmProvider import GeoServerToolsAlgorithmProvider
File "/usr/local/share/qgis/python/qgis/utils.py", line 384, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
ImportError: No module named servertools.GeoServerToolsAlgorithmProvider

@volaya
Copy link
Contributor Author

@volaya volaya commented on 983535f Nov 5, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think I fixed it. I forgot to add the folder to the cmakelists file, so it was not being built. Since I work with a 1.8 install and not with the git version, I could not see the problem (I have my own ant task to do the deploying). Now it should copy the new folder as well and everything should be fine :-)

Sorry for this

@slarosa
Copy link
Member

@slarosa slarosa commented on 983535f Nov 6, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...and to get it to work ;-) , add CMakeLists.txt in dir servertools:

FILE(GLOB PY_FILES *.py)

ADD_SUBDIRECTORY(geoserver)
ADD_SUBDIRECTORY(httplib2)

PLUGIN_INSTALL(sextante servertools ${PY_FILES})

in geoserver dir:

FILE(GLOB PY_FILES *.py)

PLUGIN_INSTALL(sextante servertools/geoserver ${PY_FILES})

and finally httplib2 dir:

FILE(GLOB PY_FILES *.py)

PLUGIN_INSTALL(sextante servertools/httplib2 ${PY_FILES})

this should solve the problem !

Thanks !

Please sign in to comment.