Skip to content
Permalink
Browse files

Merge branch 'sextante_user_dir'

  • Loading branch information
alexbruy committed Nov 12, 2012
2 parents e11ee59 + 4496c74 commit 69361d9216e418dfdda207a2cd249bec12ad934b

This file was deleted.

@@ -27,16 +27,21 @@
import time
import sys

from PyQt4.QtCore import *

from qgis.core import *

class SextanteUtils:

NUM_EXPORTED = 1

@staticmethod
def userFolder():
userfolder = os.path.expanduser("~") + os.sep + "sextante"
mkdir(userfolder)
userDir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/sextante"
if not QDir(userDir).exists():
QDir().mkpath(userDir)

return userfolder
return unicode(userDir)

@staticmethod
def isWindows():
@@ -48,10 +53,11 @@ def isMac():

@staticmethod
def tempFolder():
tempfolder = os.path.expanduser("~") + os.sep + "sextante" + os.sep + "tempdata"
mkdir(tempfolder)
tempDir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/sextante/tempdata"
if not QDir(tempDir).exists():
QDir().mkpath(tempDir)

return tempfolder
return unicode(tempDir)

@staticmethod
def setTempOutput(out, alg):
@@ -85,5 +91,3 @@ def mkdir(newdir):
mkdir(head)
if tail:
os.mkdir(newdir)


@@ -44,7 +44,7 @@ def __init__(self, fileName, encoding, fields, geometryType, crs, options=None):
self.isMemory = False
self.memLayer = None
self.writer = None

if encoding is None:
settings = QSettings()
encoding = settings.value("/SextanteQGIS/encoding", "System").toString()
@@ -68,7 +68,7 @@ def __init__(self, fileName, encoding, fields, geometryType, crs, options=None):
extension = extension[:extension.find(" ")]
OGRCodes[extension] = value

extension = self.fileName[self.fileName.find(".") + 1:]
extension = self.fileName[self.fileName.rfind(".") + 1:]
self.writer = QgsVectorFileWriter(self.fileName, encoding, fields, geometryType, crs, OGRCodes[extension])

def addFeature(self, feature):
@@ -36,7 +36,6 @@ 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"
mkdir(folder)

@@ -49,12 +48,6 @@ def getAlgorithm(name):
return provider[name]
return None


@staticmethod
def getAlgorithms():
return ModelerUtils.allAlgs





@@ -55,28 +55,25 @@ def unload(self):
def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/script.png")

def scriptsFolder(self):
return ScriptUtils.scriptsFolder()

def getName(self):
return "script"

def getDescription(self):
return "Scripts"

def _loadAlgorithms(self):
folder = self.scriptsFolder()
def _loadAlgorithms(self):
folder = ScriptUtils.scriptsFolder()
self.loadFromFolder(folder)
folder = os.path.join(os.path.dirname(__file__), "scripts")
self.loadFromFolder(folder)

def loadFromFolder(self, folder):
if not os.path.exists(folder):
return
for descriptionFile in os.listdir(folder):
if descriptionFile.endswith("py"):
try:
fullpath = os.path.join(ScriptUtils.scriptsFolder(), descriptionFile)
fullpath = os.path.join(folder, descriptionFile)
alg = ScriptAlgorithm(fullpath)
if alg.name.strip() != "":
self.algs.append(alg)
@@ -37,11 +37,7 @@ class ScriptUtils:
def scriptsFolder():
folder = SextanteConfig.getSetting(ScriptUtils.SCRIPTS_FOLDER)
if folder == None:
#folder = os.path.join(os.path.dirname(__file__), "scripts")
folder = SextanteUtils.userFolder() + os.sep + "scripts"
mkdir(folder)

return folder



@@ -1,3 +1,4 @@
##[Example scripts]=group
##input=vector
##cellsize=number 1000.0
##grid=output vector
@@ -1,5 +1,6 @@
#Definition of inputs and outputs
#==================================
##[Example scripts]=group
##input=vector
##class_field=field input
##value_field=field input
@@ -44,18 +45,18 @@
if clazz not in classes:
classes[clazz] = []
if value not in classes[clazz]:
classes[clazz].append(value)
classes[clazz].append(value)

# Create output vector layer with additional attribute
while provider.nextFeature(inFeat):
print int((500 * nElement)/nFeat)
nElement += 1
nElement += 1
inGeom = inFeat.geometry()
outFeat.setGeometry( inGeom )
atMap = inFeat.attributeMap()
clazz = atMap[class_field_index].toString()
outFeat.setAttributeMap( atMap )
outFeat.addAttribute( len(provider.fields()), QVariant(len(classes[clazz])))
writer.addFeature( outFeat )
del writer

del writer

0 comments on commit 69361d9

Please sign in to comment.
You can’t perform that action at this time.