Skip to content

Commit

Permalink
Fixed some minor bugs in sextante algs
Browse files Browse the repository at this point in the history
Removed SAGA Split algorithms
  • Loading branch information
volaya committed Nov 28, 2012
1 parent 0893db7 commit 6d71876
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 52 deletions.
6 changes: 3 additions & 3 deletions python/plugins/sextante/__init__.py
Expand Up @@ -17,7 +17,7 @@
***************************************************************************
"""

from sextante.core.Sextante import runalg, alghelp, alglist, algoptions, load, loadFromAlg, extent, getObjectFromName, getObjectFromUri
from sextante.core.Sextante import runalg, runandload, alghelp, alglist, algoptions, load, loadFromAlg, extent, getObjectFromName, getObjectFromUri

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand All @@ -32,7 +32,7 @@ def description():
return "SEXTANTE Geoprocessing Platform for QGIS"

def version():
return "1.0.8"
return "1.0.9"

def icon():
return "images/toolbox.png"
Expand All @@ -41,7 +41,7 @@ def category():
return "Analysis"

def qgisMinimumVersion():
return "1.0"
return "1.8"

def classFactory(iface):
from sextante.SextantePlugin import SextantePlugin
Expand Down
16 changes: 8 additions & 8 deletions python/plugins/sextante/algs/AddTableField.py
Expand Up @@ -73,13 +73,13 @@ def processAlgorithm(self, progress):
nFeat = vprovider.featureCount()
nElement = 0
while vprovider.nextFeature(inFeat):
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
inGeom = inFeat.geometry()
outFeat.setGeometry( inGeom )
atMap = inFeat.attributeMap()
outFeat.setAttributeMap( atMap )
outFeat.addAttribute( len(vprovider.fields()), QVariant() )
writer.addFeature( outFeat )
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
inGeom = inFeat.geometry()
outFeat.setGeometry( inGeom )
atMap = inFeat.attributeMap()
outFeat.setAttributeMap( atMap )
outFeat.addAttribute( len(vprovider.fields()), QVariant() )
writer.addFeature( outFeat )
del writer

11 changes: 3 additions & 8 deletions python/plugins/sextante/algs/FieldPyculator.py
Expand Up @@ -67,8 +67,6 @@ def processAlgorithm(self, progress):
code = self.getParameterValue(self.FORMULA)
globalExpression = self.getParameterValue(self.GLOBAL)
useSelected = self.getParameterValue(self.USE_SELECTED)
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputFromName(self.OUTPUT_LAYER)
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT_LAYER))
vprovider = layer.dataProvider()
Expand All @@ -77,9 +75,7 @@ def processAlgorithm(self, progress):
fields = vprovider.fields()
fields[len(fields)] = QgsField(fieldname, QVariant.Double)
writer = output.getVectorWriter(fields, vprovider.geometryType(), vprovider.crs() )
outFeat = QgsFeature()
nFeatures = vprovider.featureCount()
nElement = 0
outFeat = QgsFeature()
new_ns = {}

#run global code
Expand Down Expand Up @@ -115,13 +111,12 @@ def processAlgorithm(self, progress):
"Field code block can't be executed! %s \n %s"
(unicode(sys.exc_info()[0].__name__), unicode(sys.exc_info()[1])))


QtGui.QMessageBox.critical(None, "", str(vprovider))
#run

nElement = 1
features = layer.selectedFeatures()
nFeatures = len(features)
if not useSelected or nFeatures == 0:
nFeatures = vprovider.featureCount()
feat = QgsFeature()
if need_attrs:
attr_ind = vprovider.attributeIndexes()
Expand Down
4 changes: 4 additions & 0 deletions python/plugins/sextante/core/Sextante.py
Expand Up @@ -376,6 +376,10 @@ def alghelp(name):
def runalg(algOrName, *args):
alg = Sextante.runAlgorithm(algOrName, None, *args)
return alg.getOutputValuesAsDictionary()

def runandload(name, *args):
Sextante.runAlgorithm(name, SextantePostprocessing.handleAlgorithmResults, *args)


def extent(layers):
first = True
Expand Down
5 changes: 4 additions & 1 deletion python/plugins/sextante/core/SextanteVectorWriter.py
Expand Up @@ -54,7 +54,7 @@ def __init__(self, fileName, encoding, fields, geometryType, crs, options=None):

uri = self.TYPE_MAP[geometryType]
if crs.isValid():
uri += "?crs=" + crs.authid()
uri += "?crs=" + crs.authid()
self.memLayer = QgsVectorLayer(uri, self.fileName, "memory")
self.writer = self.memLayer.dataProvider()
self.writer.addAttributes(fields.values())
Expand All @@ -69,6 +69,9 @@ def __init__(self, fileName, encoding, fields, geometryType, crs, options=None):
OGRCodes[extension] = value

extension = self.fileName[self.fileName.rfind(".") + 1:]
if extension not in OGRCodes:
extension = "shp"
self.filename = self.filename + "shp"
self.writer = QgsVectorFileWriter(self.fileName, encoding, fields, geometryType, crs, OGRCodes[extension])

def addFeature(self, feature):
Expand Down
10 changes: 5 additions & 5 deletions python/plugins/sextante/gui/BatchProcessingDialog.py
Expand Up @@ -16,11 +16,6 @@
* *
***************************************************************************
"""
from sextante.gui.CrsSelectionPanel import CrsSelectionPanel
from sextante.outputs.OutputNumber import OutputNumber
from sextante.outputs.OutputString import OutputString
from sextante.core.SextanteUtils import SextanteUtils

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
Expand All @@ -35,6 +30,10 @@
from sextante.parameters.ParameterVector import ParameterVector
from sextante.gui.BatchInputSelectionPanel import BatchInputSelectionPanel
from sextante.gui.AlgorithmExecutionDialog import AlgorithmExecutionDialog
from sextante.gui.CrsSelectionPanel import CrsSelectionPanel
from sextante.outputs.OutputNumber import OutputNumber
from sextante.outputs.OutputString import OutputString
from sextante.core.SextanteUtils import SextanteUtils

from sextante.parameters.ParameterExtent import ParameterExtent
from sextante.parameters.ParameterNumber import ParameterNumber
Expand All @@ -58,6 +57,7 @@
class BatchProcessingDialog(AlgorithmExecutionDialog):
def __init__(self, alg):
self.algs = None
self.showAdvanced = False
self.table = QtGui.QTableWidget(None)
AlgorithmExecutionDialog.__init__(self, alg, self.table)
self.setWindowModality(1)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/gui/HistoryDialog.py
Expand Up @@ -98,7 +98,7 @@ def executeAlgorithm(self):
item = self.tree.currentItem()
if isinstance(item, TreeLogEntryItem):
if item.isAlg:
script = "from sextante.core.Sextante import Sextante\n"
script = "import sextante\n"
script+=item.entry.text.replace("runalg(","runandload(")
exec(script)

Expand Down
4 changes: 2 additions & 2 deletions python/plugins/sextante/metadata.txt
Expand Up @@ -2,8 +2,8 @@
name=SEXTANTE
description=SEXTANTE Geoprocessing Platform for QGIS
category=Analysis
version=1.0.8
qgisMinimumVersion=1.0
version=1.0.9
qgisMinimumVersion=1.8

author=Victor Olaya
email=volayaf@gmail.com
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/sextante/mmqgisx/mmqgisx_library.py
Expand Up @@ -1598,7 +1598,7 @@ def mmqgisx_grid(qgis, savename, hspacing, vspacing, width, height, originx, ori
if (hspacing <= 0) or (vspacing <= 0):
return "Invalid grid spacing: " + unicode(hspacing) + " / " + unicode(vspacing)

if (width <= hspacing) or (width < vspacing):
if (width < hspacing) or (height < vspacing):
return "Invalid width / height: " + unicode(width) + " / " + unicode(height)

fields = {
Expand Down Expand Up @@ -1681,9 +1681,9 @@ def mmqgisx_grid(qgis, savename, hspacing, vspacing, width, height, originx, ori
feature.addAttribute(1, QVariant(y + (vspacing / 2.0)))
outfile.addFeature(feature)
linecount = linecount + 1
y = y + hspacing;
y = y + vspacing;

x = x + vspacing
x = x + hspacing

elif gridtype == "Diamond (polygon)":
x = originx
Expand Down
6 changes: 6 additions & 0 deletions python/plugins/sextante/parameters/ParameterFile.py
Expand Up @@ -39,6 +39,12 @@ def serialize(self):
return self.__module__.split(".")[-1] + "|" + self.name + "|" + self.description +\
"|" + str(self.isFolder)

def setValue(self, obj):
self.value = str(obj)
if self.value.strip() == "":
return False
return True

def deserialize(self, s):
tokens = s.split("|")
return ParameterFile(tokens[0], tokens[1], tokens[2] == str(True))
Expand Down
8 changes: 0 additions & 8 deletions python/plugins/sextante/saga/description/SplitShapesLayer.txt

This file was deleted.

This file was deleted.

This file was deleted.

Expand Up @@ -36,8 +36,7 @@

#Iterate over input layer to count unique values in each class
while provider.nextFeature(inFeat):
#Printing a number to the console to indicate progress
print int((50 * nElement)/nFeat)
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
atMap = inFeat.attributeMap()
clazz = atMap[class_field_index].toString()
Expand Down
@@ -0,0 +1,50 @@
#Definition of inputs and outputs
#==================================
##[Example scripts]=group
##input=vector
##class_field=field input
##output=output file

#Algorithm body
#==================================
from sextante.core.QGisLayers import QGisLayers
from qgis.core import *
from PyQt4.QtCore import *
from sextante.core.SextanteVectorWriter import SextanteVectorWriter

# "input" contains the location of the selected layer.
# We get the actual object,
layer = QGisLayers.getObjectFromUri(input)
provider = layer.dataProvider()
allAttrs = provider.attributeIndexes()
provider.select( allAttrs )
fields = provider.fields()
writers = {}

# Fields are defined by their names, but QGIS needs the index for the attributes map
class_field_index = provider.fieldNameIndex(class_field)

inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
nFeat = provider.featureCount()
nElement = 0
writers = {}

while provider.nextFeature(inFeat):
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
atMap = inFeat.attributeMap()
clazz = atMap[class_field_index].toString()
if clazz not in writers:
outputFile = output + "_" + str(len(writers)) + ".shp"
writers[clazz] = SextanteVectorWriter(outputFile, None, fields, provider.geometryType(), provider.crs() )
inGeom = inFeat.geometry()
outFeat.setGeometry(inGeom)
outFeat.setAttributeMap(atMap)
writers[clazz].addFeature(outFeat)



for writer in writers.values():
del writer

0 comments on commit 6d71876

Please sign in to comment.