Skip to content
Permalink
Browse files
added explode and multi to single part algorithms
added lastools for linux
added FUSION filterdata algorihtm
changed r installation method

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@171 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf committed May 8, 2012
1 parent 3107d16 commit c80371a727dafd008a76a747fe7b1798563b24ea
@@ -5,7 +5,7 @@ def name():
def description():
return "SEXTANTE Geoprocessing platform for QGIS"
def version():
return "Version 1.0.4"
return "Version 1.0.5"
def icon():
return "icon.png"
def qgisMinimumVersion():
@@ -0,0 +1,72 @@
from sextante.core.GeoAlgorithm import GeoAlgorithm
import os.path
from PyQt4 import QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from sextante.parameters.ParameterVector import ParameterVector
from sextante.core.QGisLayers import QGisLayers
from sextante.outputs.OutputVector import OutputVector

class Explode(GeoAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"

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

def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
output = self.getOutputValue(self.OUTPUT)
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
fields = vprovider.fields()
writer = QgsVectorFileWriter( output, systemEncoding,
fields, QGis.WKBLineString, vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
nFeat = vprovider.featureCount()
nElement = 0
while vprovider.nextFeature( inFeat ):
nElement += 1
progress.setPercentage((nElement*100)/nFeat)
inGeom = inFeat.geometry()
atMap = inFeat.attributeMap()
segments = self.extractAsSingleSegments( inGeom )
outFeat.setAttributeMap( atMap )
for segment in segments:
outFeat.setGeometry(segment)
writer.addFeature(outFeat)
del writer


def extractAsSingleSegments( self, geom ):
segments = []
if geom.isMultipart():
multi = geom.asMultiPolyline()
for polyline in multi:
segments.extend( self.getPolylineAsSingleSegments(polyline))
else:
segments.extend( self.getPolylineAsSingleSegments(geom.asPolyline()))
return segments

def getPolylineAsSingleSegments(self, polyline):
segments = []
for i in range(len(polyline)-1):
ptA = polyline[i]
ptB = polyline[i+1]
segment = QgsGeometry.fromPolyline([ptA, ptB])
segments.append(segment)
return segments

def defineCharacteristics(self):
self.name = "Explode lines"
self.group = "Algorithms for vector layers"
self.addParameter(ParameterVector(self.INPUT, "Input layer",ParameterVector.VECTOR_TYPE_LINE))
self.addOutput(OutputVector(self.OUTPUT, "Output layer"))

@@ -5,7 +5,6 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sextante.parameters.ParameterString import ParameterString
from sextante.parameters.ParameterSelection import ParameterSelection
from sextante.core.QGisLayers import QGisLayers
import os
from PyQt4 import QtGui
@@ -4,12 +4,13 @@
import os
from sextante.algs.FieldsCalculator import FieldsCalculator
from sextante.algs.SaveSelectedFeatures import SaveSelectedFeatures
from sextante.algs.Explode import Explode

class SextanteAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
self.alglist = [AddTableField(), FieldsCalculator(), SaveSelectedFeatures()]
self.alglist = [AddTableField(), FieldsCalculator(), SaveSelectedFeatures(), Explode()]

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
@@ -86,8 +86,8 @@ def initialize():
Sextante.addProvider(FToolsAlgorithmProvider())
Sextante.addProvider(ModelerOnlyAlgorithmProvider())
Sextante.addProvider(GdalAlgorithmProvider())
Sextante.addProvider(LasToolsAlgorithmProvider())
if SextanteUtils.isWindows():
Sextante.addProvider(LasToolsAlgorithmProvider())
Sextante.addProvider(FusionAlgorithmProvider())
Sextante.addProvider(OTBAlgorithmProvider())
Sextante.addProvider(RAlgorithmProvider())
@@ -29,6 +29,7 @@
from sextante.ftools.RandomSelection import RandomSelection
from sextante.ftools.SelectByLocation import SelectByLocation
from sextante.ftools.RandomSelectionWithinSubsets import RandomSelectionWithinSubsets
from sextante.ftools.MultipartToSingleparts import MultipartTosingleparts

class FToolsAlgorithmProvider(AlgorithmProvider):

@@ -41,7 +42,8 @@ def __init__(self):
NearestNeighbourAnalysis(), MeanCoords(), LinesIntersection(),
ConvexHull(), FixedDistanceBuffer(), VariableDistanceBuffer(),
Dissolve(), Difference(), Intersection(), Union(), Clip(), ExtentFromLayer(),
RandomSelection(), RandomSelectionWithinSubsets(), SelectByLocation()]
RandomSelection(), RandomSelectionWithinSubsets(), SelectByLocation(),
MultipartTosingleparts()]

def getDescription(self):
return "fTools (Vector analysis)"
@@ -0,0 +1,99 @@
from sextante.core.GeoAlgorithm import GeoAlgorithm
import os.path
from PyQt4 import QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from sextante.parameters.ParameterVector import ParameterVector
from sextante.core.QGisLayers import QGisLayers
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from sextante.outputs.OutputVector import OutputVector

class MultipartTosingleparts(GeoAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"

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

def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
output = self.getOutputValue(self.OUTPUT)
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
fields = vprovider.fields()
geomType = self.multiToSingleGeom(vprovider.geometryType())
writer = QgsVectorFileWriter( output, systemEncoding,
fields, geomType, vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
nFeat = vprovider.featureCount()
nElement = 0
while vprovider.nextFeature( inFeat ):
nElement += 1
progress.setPercentage((nElement*100)/nFeat)
inGeom = inFeat.geometry()
atMap = inFeat.attributeMap()
featList = self.extractAsSingle( inGeom )
outFeat.setAttributeMap( atMap )
for i in featList:
outFeat.setGeometry( i )
writer.addFeature( outFeat )
del writer


def multiToSingleGeom(self, wkbType):
try:
if wkbType in (QGis.WKBPoint, QGis.WKBMultiPoint,
QGis.WKBPoint25D, QGis.WKBMultiPoint25D):
return QGis.WKBPoint
elif wkbType in (QGis.WKBLineString, QGis.WKBMultiLineString,
QGis.WKBMultiLineString25D, QGis.WKBLineString25D):
return QGis.WKBLineString
elif wkbType in (QGis.WKBPolygon, QGis.WKBMultiPolygon,
QGis.WKBMultiPolygon25D, QGis.WKBPolygon25D):
return QGis.WKBPolygon
else:
return QGis.WKBUnknown
except Exception, err:
raise GeoAlgorithmExecutionException(str(err))


def extractAsSingle( self, geom ):
multi_geom = QgsGeometry()
temp_geom = []
if geom.type() == 0:
if geom.isMultipart():
multi_geom = geom.asMultiPoint()
for i in multi_geom:
temp_geom.append( QgsGeometry().fromPoint ( i ) )
else:
temp_geom.append( geom )
elif geom.type() == 1:
if geom.isMultipart():
multi_geom = geom.asMultiPolyline()
for i in multi_geom:
temp_geom.append( QgsGeometry().fromPolyline( i ) )
else:
temp_geom.append( geom )
elif geom.type() == 2:
if geom.isMultipart():
multi_geom = geom.asMultiPolygon()
for i in multi_geom:
temp_geom.append( QgsGeometry().fromPolygon( i ) )
else:
temp_geom.append( geom )
return temp_geom


def defineCharacteristics(self):
self.name = "Multipart to singleparts"
self.group = "Geometry tools"
self.addParameter(ParameterVector(self.INPUT, "Input layer"))
self.addOutput(OutputVector(self.OUTPUT, "Output layer"))

@@ -86,7 +86,7 @@ def singleToMultiGeom(self, wkbType):
print str(err)

def defineCharacteristics(self):
self.name = "Singleparts to multi parts"
self.name = "Singleparts to multipart"
self.group = "Geometry tools"
self.addParameter(ParameterVector(SinglePartsToMultiparts.INPUT, "Input layer"))
self.addParameter(ParameterTableField(SinglePartsToMultiparts.FIELD,
@@ -1,6 +1,5 @@
import os
from sextante.parameters.ParameterFile import ParameterFile
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.fusion.FusionUtils import FusionUtils
from PyQt4 import QtGui
import subprocess
@@ -27,7 +26,7 @@ def defineCharacteristics(self):
self.addAdvancedModifiers()

def processAlgorithm(self, progress):
commands = [os.path.join(FusionUtils.FusionPath(), "ClipData.exe")]
commands = [os.path.join(FusionUtils.FusionPath(), "FilterData.exe")]
commands.append("/verbose")
self.addAdvancedModifiersToCommand(commands)
commands.append("/shape:" + str(self.getParameterValue(self.SHAPE)))
@@ -37,7 +36,7 @@ def processAlgorithm(self, progress):
else:
FusionUtils.createFileList(files)
commands.append(FusionUtils.tempFileListFilepath())
outFile = self.getOutputValue(self.OUTPUT)
outFile = self.getOutputValue(self.OUTPUT) + ".lda"
commands.append(outFile)
extent = str(self.getParameterValue(self.EXTENT)).split(",")
commands.append(extent[0])
@@ -0,0 +1,5 @@
'''
Created on 07/05/2012
@author: Volaya
'''
@@ -0,0 +1,48 @@
import os
from sextante.parameters.ParameterFile import ParameterFile
from sextante.fusion.FusionUtils import FusionUtils
from PyQt4 import QtGui
import subprocess
from sextante.outputs.OutputFile import OutputFile
from sextante.fusion.FusionAlgorithm import FusionAlgorithm
from sextante.parameters.ParameterNumber import ParameterNumber

class FilterData(FusionAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"
VALUE = "VALUE"
SHAPE = "SHAPE"
WINDOWSIZE = "WINDOWSIZE"


def defineCharacteristics(self):
self.name = "Filter Data outliers"
self.group = "Points"
self.addParameter(ParameterFile(self.INPUT, "Input las layer"))
self.addParameter(ParameterNumber(self.VALUE, "Standard Deviation multiplier"))
self.addParameter(ParameterNumber(self.VALUE, "Window size", None, None, 10))
self.addOutput(OutputFile(self.OUTPUT, "Output filtered las file"))
self.addAdvancedModifiers()

def processAlgorithm(self, progress):
commands = [os.path.join(FusionUtils.FusionPath(), "FilterData.exe")]
commands.append("/verbose")
self.addAdvancedModifiersToCommand(commands)
commands.append("outlier")
commands.append(self.getParameterValue(self.VALUE))
commands.append(self.getParameterValue(self.WINDOWSIZE))
outFile = self.getOutputValue(self.OUTPUT) + ".lda"
commands.append(outFile)
files = self.getParameterValue(self.INPUT).split(";")
if len(files) == 1:
commands.append(self.getParameterValue(self.INPUT))
else:
FusionUtils.createFileList(files)
commands.append(FusionUtils.tempFileListFilepath())
FusionUtils.runFusion(commands, progress)
commands = [os.path.join(FusionUtils.FusionPath(), "LDA2LAS.exe")]
commands.append(outFile)
commands.append(self.getOutputValue(self.OUTPUT))
p = subprocess.Popen(commands, shell=True)
p.wait()
@@ -10,14 +10,15 @@
from sextante.fusion.CanopyModel import CanopyModel
from sextante.fusion.ClipData import ClipData
from sextante.fusion.Cover import Cover
from sextante.fusion.FilterData import FilterData


class FusionAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
self.actions.append(OpenViewerAction())
self.algsList = [CloudMetrics(), CanopyMaxima(), CanopyModel(), ClipData(), Cover()]
self.algsList = [CloudMetrics(), CanopyMaxima(), CanopyModel(), ClipData(), Cover(), FilterData()]

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
@@ -55,9 +55,9 @@ def createAlgsList(self):
self.preloadedAlgs.append(alg)
else:
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not open GRASS algorithm: " + descriptionFile)
except Exception,e:
except Exception:
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not open GRASS algorithm: " + descriptionFile)
self.preloadedAlgs.append(nviz())
#self.preloadedAlgs.append(nviz())
#self.createDescriptionFiles()

def _loadAlgorithms(self):
@@ -1,10 +1,9 @@
v.surf.idw
v.surf.idw
Vector (v.*)
ParameterVector|input|input|-1|False
ParameterVector|input|input|0|False
ParameterNumber|npoints|npoints|None|None|12
ParameterNumber|power|power|None|None|2.0
ParameterNumber|layer|layer|None|None|1
ParameterTableField|column|column|input
ParameterBoolean|-n|-n|True
OutputRaster|output|output
@@ -16,14 +16,18 @@
from sextante.lastools.lassplit import lassplit
from sextante.lastools.lasclassify import lasclassify
from sextante.lastools.lasclip import lasclip
from sextante.core.SextanteUtils import SextanteUtils


class LasToolsAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
self.algsList = [las2shp(), lasboundary(), las2dem(), las2iso(), lasgrid(), lasground(),
if SextanteUtils.isWindows():
self.algsList = [las2shp(), lasboundary(), las2dem(), las2iso(), lasgrid(), lasground(),
lasinfo(), lasheight(), lasprecision(), lassplit(), lasclassify(), lasclip()]
else:
self.algsList = [lasinfo(), lasprecision()]

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
@@ -20,7 +20,8 @@ def LasToolsPath():
def runLasTools(commands, progress):
loglines = []
loglines.append("LasTools execution console output")
proc = subprocess.Popen(commands, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT, universal_newlines=False).stdout
commandline = " ".join(commands)
proc = subprocess.Popen(commandline, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT, universal_newlines=False).stdout
for line in iter(proc.readline, ""):
loglines.append(line)
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
Loading

0 comments on commit c80371a

Please sign in to comment.