Skip to content
Permalink
Browse files
Fixed some minor bugs in sextante algs
Removed SAGA Split algorithms
  • Loading branch information
volaya committed Nov 28, 2012
1 parent 0893db7 commit 6d71876626e6f92caa7a6741813da9abebb017b6
@@ -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'
@@ -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"
@@ -41,7 +41,7 @@ def category():
return "Analysis"

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

def classFactory(iface):
from sextante.SextantePlugin import SextantePlugin
@@ -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

@@ -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()
@@ -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
@@ -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()
@@ -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
@@ -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())
@@ -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):
@@ -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'
@@ -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
@@ -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)
@@ -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)

@@ -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
@@ -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 = {
@@ -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
@@ -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))

This file was deleted.

This file was deleted.

This file was deleted.

@@ -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()
@@ -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.