178 changes: 57 additions & 121 deletions python/plugins/sextante/algs/ftools/Buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from sextante.core.QGisLayers import QGisLayers

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand All @@ -29,7 +30,7 @@

from sextante.core.SextanteLog import SextanteLog

def buffering(progress, writer, distance, field, useSelection, useField, layer, dissolve, segments):
def buffering(progress, writer, distance, field, useField, layer, dissolve, segments):
GEOS_EXCEPT = True
FEATURE_EXCEPT = True

Expand All @@ -44,133 +45,68 @@ def buffering(progress, writer, distance, field, useSelection, useField, layer,
outGeom = QgsGeometry()

current = 0

# there is selection in input layer
if useSelection:
total = 100.0 / float(layer.selectedFeatureCount())
selection = layer.selectedFeatures()

# with dissolve
if dissolve:
first = True
for inFeat in selection:
atMap = inFeat.attributeMap()
if useField:
value = atMap[field].doDouble()[0]
else:
value = distance

inGeom = QgsGeometry(inFeat.geometry())
try:
outGeom = inGeom.buffer(float(value), segments)
if first:
tempGeom = QgsGeometry(outGeom)
first = False
else:
try:
tempGeom = tempGeom.combine( outGeom )
except:
GEOS_EXCEPT = False
continue
except:
GEOS_EXCEPT = False
continue

current += 1
progress.setPercentage(int(current * total))
features = QGisLayers.features(layer)
total = 100.0 / float(len(features))

# with dissolve
if dissolve:
first = True
for inFeat in features:
atMap = inFeat.attributeMap()
if useField:
value = atMap[field].toDouble()[0]
else:
value = distance

inGeom = QgsGeometry(inFeat.geometry())
try:
outFeat.setGeometry(tempGeom)
writer.addFeature(outFeat)
except:
FEATURE_EXCEPT = False
# without dissolve
else:
for inFeat in selection:
atMap = inFeat.attributeMap()
if useField:
value = atMap[field].toDouble()[0]
outGeom = inGeom.buffer(float(value), segments)
if first:
tempGeom = QgsGeometry(outGeom)
first = False
else:
value = distance

inGeom = QgsGeometry(inFeat.geometry())
try:
outGeom = inGeom.buffer(float(value), segments)
try:
outFeat.setGeometry(outGeom)
outFeat.setAttributeMap(atMap)
writer.addFeature(outFeat)
tempGeom = tempGeom.combine(outGeom)
except:
FEATURE_EXCEPT = False
GEOS_EXCEPT = False
continue
except:
GEOS_EXCEPT = False
continue

current += 1
progress.setPercentage(int(current * total))
try:
outFeat.setGeometry(tempGeom)
writer.addFeature(outFeat)
except:
FEATURE_EXCEPT = False
# without dissolve
else:
for inFeat in features:
atMap = inFeat.attributeMap()
if useField:
value = atMap[field].toDouble()[0]
else:
value = distance

inGeom = QgsGeometry(inFeat.geometry())
try:
outGeom = inGeom.buffer(float(value), segments)
try:
outFeat.setGeometry(outGeom)
outFeat.setAttributeMap(atMap)
writer.addFeature(outFeat)
except:
GEOS_EXCEPT = False
FEATURE_EXCEPT = False
continue

current += 1
progress.setPercentage(int(current * total))
# there is no selection in input layer
else:
total = 100.0 / float(layer.featureCount())

# with dissolve
if dissolve:
first = True
while layer.nextFeature(inFeat):
atMap = inFeat.attributeMap()
if useField:
value = atMap[field].toDouble()[0]
else:
value = distance

inGeom = QgsGeometry(inFeat.geometry())
try:
outGeom = inGeom.buffer(float(value), segments)
if first:
tempGeom = QgsGeometry(outGeom)
first = False
else:
try:
tempGeom = tempGeom.combine(outGeom)
except:
GEOS_EXCEPT = False
continue
except:
GEOS_EXCEPT = False
continue

current += 1
progress.setPercentage(int(current * total))
try:
outFeat.setGeometry(tempGeom)
writer.addFeature(outFeat)
except:
FEATURE_EXCEPT = False
# without dissolve
else:
while layer.nextFeature(inFeat):
atMap = inFeat.attributeMap()
if useField:
value = atMap[field].toDouble()[0]
else:
value = distance

inGeom = QgsGeometry(inFeat.geometry())
try:
outGeom = inGeom.buffer(float(value), segments)
try:
outFeat.setGeometry(outGeom)
outFeat.setAttributeMap(atMap)
writer.addFeature(outFeat)
except:
FEATURE_EXCEPT = False
continue
except:
GEOS_EXCEPT = False
continue

current += 1
progress.setPercentage(int(current * total))

except:
GEOS_EXCEPT = False
continue

current += 1
progress.setPercentage(int(current * total))

del writer

if not GEOS_EXCEPT:
Expand Down
12 changes: 5 additions & 7 deletions python/plugins/sextante/algs/ftools/Centroids.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path

from PyQt4 import QtGui
from PyQt4.QtCore import *

Expand Down Expand Up @@ -62,14 +60,14 @@ def processAlgorithm(self, progress):
QGis.WKBPoint, layer.dataProvider().crs())

layer.select(layer.pendingAllAttributesList())

inFeat = QgsFeature()

outFeat = QgsFeature()

total = 100.0 / float(layer.featureCount())

features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
current = 0

while layer.nextFeature(inFeat):
for inFeat in features:
inGeom = inFeat.geometry()
attrMap = inFeat.attributeMap()

Expand Down
1 change: 0 additions & 1 deletion python/plugins/sextante/algs/ftools/Clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
__revision__ = '$Format:%H$'

from sextante.core.GeoAlgorithm import GeoAlgorithm
import os.path
from PyQt4 import QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
Expand Down
178 changes: 62 additions & 116 deletions python/plugins/sextante/algs/ftools/ConvexHull.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
__revision__ = '$Format:%H$'

from sextante.core.GeoAlgorithm import GeoAlgorithm
import os.path
from PyQt4 import QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
Expand All @@ -44,7 +43,6 @@ class ConvexHull(GeoAlgorithm):
INPUT = "INPUT"
OUTPUT = "OUTPUT"
FIELD = "FIELD"
USE_SELECTED = "USE_SELECTED"
METHOD = "METHOD"
METHODS = ["Create single minimum convex hull", "Create convex hulls based on field"]

Expand All @@ -53,8 +51,7 @@ class ConvexHull(GeoAlgorithm):
# return QtGui.QIcon(os.path.dirname(__file__) + "/icons/convex_hull.png")
#===========================================================================

def processAlgorithm(self, progress):
useSelection = self.getParameterValue(ConvexHull.USE_SELECTED)
def processAlgorithm(self, progress):
useField = (self.getParameterValue(ConvexHull.METHOD) == 1)
field = self.getParameterValue(ConvexHull.FIELD)
vlayerA = QGisLayers.getObjectFromUri(self.getParameterValue(ConvexHull.INPUT))
Expand All @@ -64,7 +61,7 @@ def processAlgorithm(self, progress):
allAttrsA = vproviderA.attributeIndexes()
vproviderA.select(allAttrsA)
fields = { 0 : QgsField("ID", QVariant.Int),
1 : QgsField("Area", QVariant.Double),
1 : QgsField("Area", QVariant.Double),
2 : QgsField("Perim", QVariant.Double) }
writer = self.getOutputFromName(ConvexHull.OUTPUT).getVectorWriter(fields, QGis.WKBPolygon, vproviderA.crs())
inFeat = QgsFeature()
Expand All @@ -73,147 +70,96 @@ def processAlgorithm(self, progress):
outGeom = QgsGeometry()
nElement = 0
index = vproviderA.fieldNameIndex(field)
# there is selection in input layer
if useSelection:
nFeat = vlayerA.selectedFeatureCount()
selectionA = vlayerA.selectedFeatures()
if useField:
unique = ftools_utils.getUniqueValues( vproviderA, index )
nFeat = nFeat * len( unique )
for i in unique:
hull = []
first = True
outID = 0
for inFeat in selectionA:
atMap = inFeat.attributeMap()
idVar = atMap[ index ]
if idVar.toString().trimmed() == i.toString().trimmed():
if first:
outID = idVar
first = False
inGeom = QgsGeometry( inFeat.geometry() )
points = ftools_utils.extractPoints( inGeom )
hull.extend( points )
nElement += 1
progress.setPercentage(int(nElement/nFeat * 100))
if len( hull ) >= 3:
tmpGeom = QgsGeometry( outGeom.fromMultiPoint( hull ) )
try:
outGeom = tmpGeom.convexHull()
outFeat.setGeometry( outGeom )
(area, perim) = self.simpleMeasure( outGeom )
outFeat.addAttribute( 0, QVariant( outID ) )
outFeat.addAttribute( 1, QVariant( area ) )
outFeat.addAttribute( 2, QVariant( perim ) )
writer.addFeature( outFeat )
except:
GEOS_EXCEPT = False
continue
else:
hull = []
for inFeat in selectionA:
inGeom = QgsGeometry( inFeat.geometry() )
points = ftools_utils.extractPoints( inGeom )
hull.extend( points )
nElement += 1
progress.setPercentage(int(nElement/nFeat * 100))
tmpGeom = QgsGeometry( outGeom.fromMultiPoint( hull ) )
try:
outGeom = tmpGeom.convexHull()
outFeat.setGeometry( outGeom )
writer.addFeature( outFeat )
except:
GEOS_EXCEPT = False
# there is no selection in input layer
else:
rect = vlayerA.extent()
nFeat = vproviderA.featureCount()
if useField:
unique = ftools_utils.getUniqueValues( vproviderA, index )
nFeat = nFeat * len( unique )
for i in unique:
hull = []
first = True
outID = 0
vproviderA.select( allAttrsA )#, rect )
#vproviderA.rewind()
while vproviderA.nextFeature( inFeat ):
atMap = inFeat.attributeMap()
idVar = atMap[ index ]
if idVar.toString().trimmed() == i.toString().trimmed():
if first:
outID = idVar
first = False
inGeom = QgsGeometry( inFeat.geometry() )
points = ftools_utils.extractPoints( inGeom )
hull.extend( points )
nElement += 1
progress.setPercentage(int(nElement/nFeat * 100))
if len( hull ) >= 3:
tmpGeom = QgsGeometry( outGeom.fromMultiPoint( hull ) )
try:
outGeom = tmpGeom.convexHull()
outFeat.setGeometry( outGeom )
(area, perim) = self.simpleMeasure( outGeom )
outFeat.addAttribute( 0, QVariant( outID ) )
outFeat.addAttribute( 1, QVariant( area ) )
outFeat.addAttribute( 2, QVariant( perim ) )
writer.addFeature( outFeat )
except:
GEOS_EXCEPT = False
continue
else:

features = QGisLayers.features(vlayerA)
nFeat = len(features)

if useField:
unique = ftools_utils.getUniqueValues(vproviderA, index)
nFeat = nFeat * len(unique)
for i in unique:
hull = []
#vproviderA.rewind()
first = True
outID = 0
vproviderA.select(allAttrsA)
while vproviderA.nextFeature( inFeat ):
inGeom = QgsGeometry( inFeat.geometry() )
points = ftools_utils.extractPoints( inGeom )
hull.extend( points )
features = QGisLayers.features(vlayerA)
for inFeat in features:
atMap = inFeat.attributeMap()
idVar = atMap[ index ]
if idVar.toString().trimmed() == i.toString().trimmed():
if first:
outID = idVar
first = False
inGeom = QgsGeometry(inFeat.geometry())
points = ftools_utils.extractPoints(inGeom)
hull.extend(points)
nElement += 1
progress.setPercentage(int(nElement/nFeat * 100))
tmpGeom = QgsGeometry( outGeom.fromMultiPoint( hull ) )
try:
outGeom = tmpGeom.convexHull()
outFeat.setGeometry( outGeom )
writer.addFeature( outFeat )
except:
GEOS_EXCEPT = False
progress.setPercentage(int(nElement / nFeat * 100))
if len(hull) >= 3:
tmpGeom = QgsGeometry(outGeom.fromMultiPoint(hull))
try:
outGeom = tmpGeom.convexHull()
outFeat.setGeometry(outGeom)
(area, perim) = self.simpleMeasure(outGeom)
outFeat.addAttribute(0, QVariant(outID))
outFeat.addAttribute(1, QVariant(area))
outFeat.addAttribute(2, QVariant(perim))
writer.addFeature(outFeat)
except:
GEOS_EXCEPT = False
continue
else:
hull = []
vproviderA.select(allAttrsA)
features = QGisLayers.features(vlayerA)
for inFeat in features:
inGeom = QgsGeometry(inFeat.geometry())
points = ftools_utils.extractPoints(inGeom)
hull.extend(points)
nElement += 1
progress.setPercentage(int(nElement / nFeat * 100))
tmpGeom = QgsGeometry(outGeom.fromMultiPoint(hull))
try:
outGeom = tmpGeom.convexHull()
outFeat.setGeometry(outGeom)
writer.addFeature(outFeat)
except:
GEOS_EXCEPT = False

del writer

if not GEOS_EXCEPT:
SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Geometry exception while computing convex hull")
if not FEATURE_EXCEPT:
SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Feature exception while computing convex hull")

def simpleMeasure(self, inGeom ):
def simpleMeasure(self, inGeom):
measure = QgsDistanceArea()
attr1 = measure.measure(inGeom)
if inGeom.type() == QGis.Polygon:
attr2 = self.perimMeasure( inGeom, measure )
attr2 = self.perimMeasure(inGeom, measure)
else:
attr2 = attr1
return ( attr1, attr2 )
return (attr1, attr2)

def perimMeasure(self, inGeom, measure ):
def perimMeasure(self, inGeom, measure):
value = 0.00
if inGeom.isMultipart():
poly = inGeom.asMultiPolygon()
for k in poly:
for j in k:
value = value + measure.measureLine( j )
value = value + measure.measureLine(j)
else:
poly = inGeom.asPolygon()
for k in poly:
value = value + measure.measureLine( k )
value = value + measure.measureLine(k)
return value

def defineCharacteristics(self):
self.name = "Convex hull"
self.group = "Vector geometry tools"
self.addParameter(ParameterVector(ConvexHull.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
self.addParameter(ParameterTableField(ConvexHull.FIELD, "Field", ConvexHull.INPUT))
self.addParameter(ParameterSelection(ConvexHull.METHOD, "Method", ConvexHull.METHODS))
self.addParameter(ParameterBoolean(ConvexHull.USE_SELECTED, "Use selected features", False))
self.addParameter(ParameterSelection(ConvexHull.METHOD, "Method", ConvexHull.METHODS))
self.addOutput(OutputVector(ConvexHull.OUTPUT, "Convex hull"))
#=========================================================
28 changes: 10 additions & 18 deletions python/plugins/sextante/algs/ftools/Delaunay.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,17 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path
from sets import Set

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *

from sets import Set
from sextante.algs.ftools import voronoi
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from sextante.core.GeoAlgorithmExecutionException import \
GeoAlgorithmExecutionException
from sextante.core.QGisLayers import QGisLayers

from sextante.parameters.ParameterVector import ParameterVector
from sextante.outputs.OutputVector import OutputVector
from sextante.parameters.ParameterVector import ParameterVector

from sextante.algs.ftools import voronoi

class Delaunay(GeoAlgorithm):

Expand All @@ -59,8 +54,7 @@ def defineCharacteristics(self):
self.addOutput(OutputVector(self.OUTPUT, "Delaunay triangulation"))

def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
output = self.getOutputValue(self.OUTPUT)
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))

provider = layer.dataProvider()
provider.select()
Expand All @@ -75,17 +69,16 @@ def processAlgorithm(self, progress):

pts = []
ptDict = {}
ptNdx = -1
inFeat = QgsFeature()
ptNdx = -1
c = voronoi.Context()

while provider.nextFeature(inFeat):
features = QGisLayers.features(layer)
for inFeat in features:
geom = QgsGeometry(inFeat.geometry())
point = geom.asPoint()
x = point.x()
y = point.y()
pts.append((x, y))
ptNdx +=1
ptNdx += 1
ptDict[ptNdx] = inFeat.id()

if len(pts) < 3:
Expand All @@ -107,7 +100,6 @@ def processAlgorithm(self, progress):
indicies.append(indicies[0])
polygon = []
step = 0

for index in indicies:
provider.featureAtId(ptDict[ids[index]], inFeat, True)
geom = QgsGeometry(inFeat.geometry())
Expand Down
55 changes: 17 additions & 38 deletions python/plugins/sextante/algs/ftools/DensifyGeometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
class DensifyGeometries(GeoAlgorithm):

INPUT = "INPUT"
VERTICES = "VERTICES"
USE_SELECTION = "USE_SELECTION"
VERTICES = "VERTICES"
OUTPUT = "OUTPUT"

#def getIcon(self):
Expand All @@ -52,15 +51,13 @@ def defineCharacteristics(self):
self.group = "Vector geometry tools"

self.addParameter(ParameterVector(self.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
self.addParameter(ParameterNumber(self.VERTICES, "Vertices to add", 1, 10000000, 1))
self.addParameter(ParameterBoolean(self.USE_SELECTION, "Use only selected features", False))
self.addParameter(ParameterNumber(self.VERTICES, "Vertices to add", 1, 10000000, 1))

self.addOutput(OutputVector(self.OUTPUT, "Simplified layer"))

def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
useSelection = self.getParameterValue(self.USE_SELECTION)
vertices =self.getParameterValue(self.VERTICES)
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
vertices = self.getParameterValue(self.VERTICES)

isPolygon = layer.geometryType() == QGis.Polygon

Expand All @@ -70,37 +67,19 @@ def processAlgorithm(self, progress):
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
layer.wkbType(), provider.crs())

features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
current = 0
if useSelection:
selection = layer.selectedFeatures()
total = 100.0 / float(len(selection))
for f in selection:
featGeometry = QgsGeometry(f.geometry())
attrMap = f.attributeMap()
newGeometry = self.densifyGeometry(featGeometry, int(vertices), isPolygon)

feature = QgsFeature()
feature.setGeometry(newGeometry)
feature.setAttributeMap(attrMap)
writer.addFeature(feature)

current += 1
progress.setPercentage(int(current * total))
else:
total = 100.0 / float(provider.featureCount())
f = QgsFeature()
while layer.nextFeature(f):
featGeometry = QgsGeometry(f.geometry())
attrMap = f.attributeMap()
newGeometry = self.densifyGeometry(featGeometry, int(vertices), isPolygon)

feature = QgsFeature()
feature.setGeometry(newGeometry)
feature.setAttributeMap(attrMap)
writer.addFeature(feature)

current += 1
progress.setPercentage(int(current * total))
for f in features:
featGeometry = QgsGeometry(f.geometry())
attrMap = f.attributeMap()
newGeometry = self.densifyGeometry(featGeometry, int(vertices), isPolygon)
feature = QgsFeature()
feature.setGeometry(newGeometry)
feature.setAttributeMap(attrMap)
writer.addFeature(feature)
current += 1
progress.setPercentage(int(current * total))

del writer

Expand Down Expand Up @@ -145,7 +124,7 @@ def densify(self, polyline, pointsNumber):
delta = multiplier * (j + 1)
x = p1.x() + delta * (p2.x() - p1.x())
y = p1.y() + delta * (p2.y() - p1.y())
output.append(QgsPoint( x, y ))
output.append(QgsPoint(x, y))
if j + 1 == pointsNumber:
break
output.append(polyline[len(polyline) - 1])
Expand Down
55 changes: 17 additions & 38 deletions python/plugins/sextante/algs/ftools/DensifyGeometriesInterval.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,28 @@

from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.QGisLayers import QGisLayers

from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterNumber import ParameterNumber
from sextante.parameters.ParameterBoolean import ParameterBoolean

from sextante.outputs.OutputVector import OutputVector

class DensifyGeometriesInterval(GeoAlgorithm):

INPUT = "INPUT"
INTERVAL = "INTERVAL"
USE_SELECTION = "USE_SELECTION"
OUTPUT = "OUTPUT"

def defineCharacteristics(self):
self.name = "Densify geometries given an interval"
self.group = "Vector geometry tools"

self.addParameter(ParameterVector(self.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
self.addParameter(ParameterNumber(self.INTERVAL, "Interval between Vertices to add", 1, 10000000, 1))
self.addParameter(ParameterBoolean(self.USE_SELECTION, "Use only selected features", False))
self.addParameter(ParameterNumber(self.INTERVAL, "Interval between Vertices to add", 1, 10000000, 1))

self.addOutput(OutputVector(self.OUTPUT, "Simplified layer"))

def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
useSelection = self.getParameterValue(self.USE_SELECTION)
interval =self.getParameterValue(self.INTERVAL)
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
interval = self.getParameterValue(self.INTERVAL)

isPolygon = layer.geometryType() == QGis.Polygon

Expand All @@ -70,37 +64,22 @@ def processAlgorithm(self, progress):
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
layer.wkbType(), provider.crs())


features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
current = 0
if useSelection:
selection = layer.selectedFeatures()
total = 100.0 / float(len(selection))
for f in selection:
featGeometry = QgsGeometry(f.geometry())
attrMap = f.attributeMap()
newGeometry = self.densifyGeometry(featGeometry, interval, isPolygon)

feature = QgsFeature()
feature.setGeometry(newGeometry)
feature.setAttributeMap(attrMap)
writer.addFeature(feature)

current += 1
progress.setPercentage(int(current * total))
else:
total = 100.0 / float(provider.featureCount())
f = QgsFeature()
while layer.nextFeature(f):
featGeometry = QgsGeometry(f.geometry())
attrMap = f.attributeMap()
newGeometry = self.densifyGeometry(featGeometry, interval, isPolygon)
for f in features:
featGeometry = QgsGeometry(f.geometry())
attrMap = f.attributeMap()
newGeometry = self.densifyGeometry(featGeometry, interval, isPolygon)

feature = QgsFeature()
feature.setGeometry(newGeometry)
feature.setAttributeMap(attrMap)
writer.addFeature(feature)
feature = QgsFeature()
feature.setGeometry(newGeometry)
feature.setAttributeMap(attrMap)
writer.addFeature(feature)

current += 1
progress.setPercentage(int(current * total))
current += 1
progress.setPercentage(int(current * total))

del writer

Expand Down Expand Up @@ -147,7 +126,7 @@ def densify(self, polyline, interval):
delta = multiplier * (j + 1)
x = p1.x() + delta * (p2.x() - p1.x())
y = p1.y() + delta * (p2.y() - p1.y())
output.append(QgsPoint( x, y ))
output.append(QgsPoint(x, y))
if j + 1 == pointsNumber:
break
output.append(polyline[len(polyline) - 1])
Expand Down
88 changes: 10 additions & 78 deletions python/plugins/sextante/algs/ftools/Difference.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@
* *
***************************************************************************
"""

__author__ = 'Victor Olaya'
__date__ = 'August 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.GeoAlgorithm import GeoAlgorithm
import os.path
from PyQt4 import QtGui

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
Expand All @@ -34,26 +31,25 @@
from sextante.outputs.OutputVector import OutputVector
from sextante.algs.ftools import ftools_utils
from sextante.core.SextanteLog import SextanteLog
from sextante.parameters.ParameterBoolean import ParameterBoolean
from sextante.core.SextanteConfig import SextanteConfig
from sextante.core.GeoAlgorithm import GeoAlgorithm


class Difference(GeoAlgorithm):

INPUT = "INPUT"
INPUT2 = "INPUT2"
OUTPUT = "OUTPUT"
USE_SELECTED = "USE_SELECTED"
USE_SELECTED2 = "USE_SELECTED2"

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

def processAlgorithm(self, progress):
useSelection = self.getParameterValue(Difference.USE_SELECTED)
useSelection2 = self.getParameterValue(Difference.USE_SELECTED2)
vlayerA = QGisLayers.getObjectFromUri(self.getParameterValue(Difference.INPUT))
vlayerB = QGisLayers.getObjectFromUri(self.getParameterValue(Difference.INPUT2))
useSelection = SextanteConfig.getSetting(SextanteConfig.USE_SELECTED)
GEOS_EXCEPT = True
FEATURE_EXCEPT = True
vproviderA = vlayerA.dataProvider()
Expand All @@ -79,10 +75,8 @@ def processAlgorithm(self, progress):
nElement = 0
# there is selection in input layer
if useSelection:
nFeat = vlayerA.selectedFeatureCount()
selectionA = vlayerA.selectedFeatures()
# we have selection in overlay layer
if useSelection2:
nFeat = vlayerA.selectedFeatureCount()
selectionA = vlayerA.selectedFeatures()
selectionB = vlayerB.selectedFeaturesIds()
for inFeatA in selectionA:
nElement += 1
Expand Down Expand Up @@ -112,71 +106,10 @@ def processAlgorithm(self, progress):
except:
FEATURE_EXCEPT = False
continue
# we have no selection in overlay layer
else:
for inFeatA in selectionA:
nElement += 1
progress.setPercentage(int(nElement/nFeat * 100))
add = True
geom = QgsGeometry( inFeatA.geometry() )
diff_geom = QgsGeometry( geom )
atMap = inFeatA.attributeMap()
intersects = index.intersects( geom.boundingBox() )
for id in intersects:
vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
tmpGeom = QgsGeometry( inFeatB.geometry() )
try:
if diff_geom.intersects( tmpGeom ):
diff_geom = QgsGeometry( diff_geom.difference( tmpGeom ) )
except:
GEOS_EXCEPT = False
add = False
break
if add:
try:
outFeat.setGeometry( diff_geom )
outFeat.setAttributeMap( atMap )
writer.addFeature( outFeat )
except:
FEATURE_EXCEPT = False
continue
# there is no selection in input layer
else:
nFeat = vproviderA.featureCount()
vproviderA.rewind()
# we have selection in overlay layer
if useSelection2:
selectionB = vlayerB.selectedFeaturesIds()
while vproviderA.nextFeature( inFeatA ):
nElement += 1
add = True
progress.setPercentage(int(nElement/nFeat * 100))
geom = QgsGeometry( inFeatA.geometry() )
diff_geom = QgsGeometry( geom )
atMap = inFeatA.attributeMap()
intersects = index.intersects( geom.boundingBox() )
for id in intersects:
# now check if id in selection
if id in selectionB:
vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
tmpGeom = QgsGeometry( inFeatB.geometry() )
try:
if diff_geom.intersects( tmpGeom ):
diff_geom = QgsGeometry( diff_geom.difference( tmpGeom ) )
except:
GEOS_EXCEPT = False
add = False
break
if add:
try:
outFeat.setGeometry( diff_geom )
outFeat.setAttributeMap( atMap )
writer.addFeature( outFeat )
except:
FEATURE_EXCEPT = False
continue
# we have no selection in overlay layer
else:
nFeat = vproviderA.featureCount()
vproviderA.rewind()
while vproviderA.nextFeature( inFeatA ):
nElement += 1
add = True
Expand All @@ -203,6 +136,7 @@ def processAlgorithm(self, progress):
except:
FEATURE_EXCEPT = False
continue

del writer
if not GEOS_EXCEPT:
SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Geometry exception while computing difference")
Expand All @@ -214,6 +148,4 @@ def defineCharacteristics(self):
self.group = "Vector overlay tools"
self.addParameter(ParameterVector(Difference.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
self.addParameter(ParameterVector(Difference.INPUT2, "Difference layer", ParameterVector.VECTOR_TYPE_ANY))
self.addParameter(ParameterBoolean(Difference.USE_SELECTED, "Use selected features (input)", False))
self.addParameter(ParameterBoolean(Difference.USE_SELECTED2, "Use selected features (difference)", False))
self.addOutput(OutputVector(Difference.OUTPUT, "Difference"))
15 changes: 6 additions & 9 deletions python/plugins/sextante/algs/ftools/ExportGeometryInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path

from PyQt4 import QtGui
from PyQt4.QtCore import *

Expand Down Expand Up @@ -108,19 +106,18 @@ def processAlgorithm(self, progress):
mapCRS = QGisLayers.iface.mapCanvas().mapRenderer().destinationCrs()
layCRS = layer.crs()
coordTransform = QgsCoordinateTransform(layCRS, mapCRS)

inFeat = QgsFeature()

outFeat = QgsFeature()
inGeom = QgsGeometry()

current = 0
total = 100.0 / float(provider.featureCount())

while layer.nextFeature(inFeat):
current = 0
features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
for inFeat in features:
inGeom = inFeat.geometry()

if method == 1:
inGeom.transform(coordTransform)
inGeom.transform(coordTransform)

(attr1, attr2) = self.simpleMeasure(inGeom, method, ellips, crs)

Expand Down
133 changes: 41 additions & 92 deletions python/plugins/sextante/algs/ftools/ExtentFromLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,18 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *

from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.QGisLayers import QGisLayers

from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterBoolean import ParameterBoolean

from sextante.outputs.OutputVector import OutputVector

class ExtentFromLayer(GeoAlgorithm):

INPUT_LAYER = "INPUT_LAYER"
USE_SELECTION = "USE_SELECTION"
BY_FEATURE = "BY_FEATURE"

OUTPUT = "OUTPUT"
Expand All @@ -56,18 +49,14 @@ def defineCharacteristics(self):
self.group = "Vector general tools"

self.addParameter(ParameterVector(self.INPUT_LAYER, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
self.addParameter(ParameterBoolean(self.USE_SELECTION, "Use selection", False))
self.addParameter(ParameterBoolean(self.BY_FEATURE, "Calculate extent for each feature separately", False))

self.addOutput(OutputVector(self.OUTPUT, "Output layer"))

def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT_LAYER))
useSelection = self.getParameterValue(self.USE_SELECTION)
byFeature = self.getParameterValue(self.BY_FEATURE)

output = self.getOutputValue(self.OUTPUT)

fields = {0 : QgsField("MINX", QVariant.Double),
1 : QgsField("MINY", QVariant.Double),
2 : QgsField("MAXX", QVariant.Double),
Expand All @@ -84,7 +73,7 @@ def processAlgorithm(self, progress):
QGis.WKBPolygon, layer.crs())

if byFeature:
self.featureExtent(layer, writer, useSelection, progress)
self.featureExtent(layer, writer, progress)
else:
self.layerExtent(layer, writer, progress)

Expand Down Expand Up @@ -126,87 +115,47 @@ def layerExtent(self, layer, writer, progress):
})
writer.addFeature(feat)

def featureExtent(self, layer, writer, useSelection, progress):
def featureExtent(self, layer, writer, progress):
current = 0

inFeat = QgsFeature()
outFeat = QgsFeature()

provider = layer.dataProvider()
provider.select()

if useSelection:
total = 100.0 / float(layer.selectedFeatureCount())
for inFeat in layer.selectedFeatures():
rect = inFeat.geometry().boundingBox()
minx = rect.xMinimum()
miny = rect.yMinimum()
maxx = rect.xMaximum()
maxy = rect.yMaximum()
height = rect.height()
width = rect.width()
cntx = minx + (width / 2.0)
cnty = miny + (height / 2.0)
area = width * height
perim = (2 * width) + (2 * height)
rect = [QgsPoint(minx, miny),
QgsPoint(minx, maxy),
QgsPoint(maxx, maxy),
QgsPoint(maxx, miny),
QgsPoint(minx, miny)
]
geometry = QgsGeometry().fromPolygon([rect])

outFeat.setGeometry(geometry)
outFeat.setAttributeMap({0 : QVariant(minx),
1 : QVariant(miny),
2 : QVariant(maxx),
3 : QVariant(maxy),
4 : QVariant(cntx),
5 : QVariant(cnty),
6 : QVariant(area),
7 : QVariant(perim),
8 : QVariant(height),
9 : QVariant(width)
})
writer.addFeature(outFeat)
current += 1
progress.setPercentage(int(current * total))
else:
total = 100.0 / float(provider.featureCount())
while provider.nextFeature(inFeat):
rect = inFeat.geometry().boundingBox()
minx = rect.xMinimum()
miny = rect.yMinimum()
maxx = rect.xMaximum()
maxy = rect.yMaximum()
height = rect.height()
width = rect.width()
cntx = minx + (width / 2.0)
cnty = miny + (height / 2.0)
area = width * height
perim = (2 * width) + (2 * height)
rect = [QgsPoint(minx, miny),
QgsPoint(minx, maxy),
QgsPoint(maxx, maxy),
QgsPoint(maxx, miny),
QgsPoint(minx, miny)
]

geometry = QgsGeometry().fromPolygon([rect])

outFeat.setGeometry(geometry)
outFeat.setAttributeMap({0 : QVariant(minx),
1 : QVariant(miny),
2 : QVariant(maxx),
3 : QVariant(maxy),
4 : QVariant(cntx),
5 : QVariant(cnty),
6 : QVariant(area),
7 : QVariant(perim),
8 : QVariant(height),
9 : QVariant(width)
})
writer.addFeature(outFeat)
current += 1
progress.setPercentage(int(current * total))
provider.select()
features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
for inFeat in features:
rect = inFeat.geometry().boundingBox()
minx = rect.xMinimum()
miny = rect.yMinimum()
maxx = rect.xMaximum()
maxy = rect.yMaximum()
height = rect.height()
width = rect.width()
cntx = minx + (width / 2.0)
cnty = miny + (height / 2.0)
area = width * height
perim = (2 * width) + (2 * height)
rect = [QgsPoint(minx, miny),
QgsPoint(minx, maxy),
QgsPoint(maxx, maxy),
QgsPoint(maxx, miny),
QgsPoint(minx, miny)
]

geometry = QgsGeometry().fromPolygon([rect])

outFeat.setGeometry(geometry)
outFeat.setAttributeMap({0 : QVariant(minx),
1 : QVariant(miny),
2 : QVariant(maxx),
3 : QVariant(maxy),
4 : QVariant(cntx),
5 : QVariant(cnty),
6 : QVariant(area),
7 : QVariant(perim),
8 : QVariant(height),
9 : QVariant(width)
})
writer.addFeature(outFeat)
current += 1
progress.setPercentage(int(current * total))
14 changes: 3 additions & 11 deletions python/plugins/sextante/algs/ftools/ExtractNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,13 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *

from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.QGisLayers import QGisLayers

from sextante.parameters.ParameterVector import ParameterVector

from sextante.outputs.OutputVector import OutputVector

from sextante.algs.ftools import FToolsUtils as utils

class ExtractNodes(GeoAlgorithm):
Expand Down Expand Up @@ -66,15 +59,14 @@ def processAlgorithm(self, progress):
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
QGis.WKBPoint, provider.crs())

inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
outGeom = QgsGeometry()

current = 0
total = 100.0 / float(provider.featureCount())

while layer.nextFeature(inFeat):
features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
for inFeat in features:
inGeom = inFeat.geometry()
atMap = inFeat.attributeMap()

Expand Down
28 changes: 12 additions & 16 deletions python/plugins/sextante/algs/ftools/FToolsUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from sextante.core.QGisLayers import QGisLayers

__author__ = 'Carson, Farmer, Victor Olaya'
__date__ = 'September 2012'
Expand All @@ -27,12 +28,13 @@

from qgis.core import *

def createSpatialIndex(provider):
ft = QgsFeature()
def createSpatialIndex(layer):
provider = layer.provider()
idx = QgsSpatialIndex()
provider.rewind()
provider.select()
while provider.nextFeature(ft):
features = QGisLayers.features(layer)
for ft in features:
idx.insertFeature(ft)
return idx

Expand Down Expand Up @@ -100,20 +102,14 @@ def extractPoints( geom ):

return points

def getUniqueValuesCount(layer, fieldIndex, useSelection):
def getUniqueValuesCount(layer, fieldIndex):
count = 0
values = []
layer.select([fieldIndex], QgsRectangle(), False)
if useSelection:
selection = layer.selectedFeatures()
for f in selection:
if f.attributeMap()[fieldIndex].toString() not in values:
values.append(f.attributeMap()[fieldIndex].toString())
count += 1
else:
feat = QgsFeature()
while layer.nextFeature(feat):
if feat.attributeMap()[fieldIndex].toString() not in values:
values.append(feat.attributeMap()[fieldIndex].toString())
count += 1

features = QGisLayers.features(layer)
for feat in features:
if feat.attributeMap()[fieldIndex].toString() not in values:
values.append(feat.attributeMap()[fieldIndex].toString())
count += 1
return count
8 changes: 1 addition & 7 deletions python/plugins/sextante/algs/ftools/FixedDistanceBuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *
Expand All @@ -46,7 +43,6 @@ class FixedDistanceBuffer(GeoAlgorithm):
INPUT = "INPUT"
OUTPUT = "OUTPUT"
FIELD = "FIELD"
USE_SELECTED = "USE_SELECTED"
DISTANCE = "DISTANCE"
SEGMENTS = "SEGMENTS"
DISSOLVE = "DISSOLVE"
Expand All @@ -59,9 +55,7 @@ class FixedDistanceBuffer(GeoAlgorithm):
def defineCharacteristics(self):
self.name = "Fixed distance buffer"
self.group = "Vector geometry tools"

self.addParameter(ParameterVector(self.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
self.addParameter(ParameterBoolean(self.USE_SELECTED, "Use selected features", False))
self.addParameter(ParameterNumber(self.DISTANCE, "Distance", 0.0, default=10.0))
self.addParameter(ParameterNumber(self.SEGMENTS, "Segments", 1, default=5))
self.addParameter(ParameterBoolean(self.DISSOLVE, "Dissolve result", False))
Expand All @@ -79,5 +73,5 @@ def processAlgorithm(self, progress):
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
QGis.WKBPolygon, provider.crs())

buff.buffering(progress, writer, distance, None, useSelection, False,
buff.buffering(progress, writer, distance, None, False,
layer, dissolve, segments)
89 changes: 9 additions & 80 deletions python/plugins/sextante/algs/ftools/Intersection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@
* *
***************************************************************************
"""

__author__ = 'Victor Olaya'
__date__ = 'August 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.GeoAlgorithm import GeoAlgorithm
import os.path
from PyQt4 import QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
Expand All @@ -35,24 +32,21 @@
from sextante.outputs.OutputVector import OutputVector
from sextante.algs.ftools import ftools_utils
from sextante.core.SextanteLog import SextanteLog
from sextante.parameters.ParameterBoolean import ParameterBoolean
from sextante.core.SextanteConfig import SextanteConfig

class Intersection(GeoAlgorithm):

INPUT = "INPUT"
INPUT2 = "INPUT2"
OUTPUT = "OUTPUT"
USE_SELECTED = "USE_SELECTED"
USE_SELECTED2 = "USE_SELECTED2"

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

def processAlgorithm(self, progress):
useSelection = self.getParameterValue(Intersection.USE_SELECTED)
useSelection2 = self.getParameterValue(Intersection.USE_SELECTED2)
useSelection = SextanteConfig.getSetting(SextanteConfig.USE_SELECTED)
vlayerA = QGisLayers.getObjectFromUri(self.getParameterValue(Intersection.INPUT))
vlayerB = QGisLayers.getObjectFromUri(self.getParameterValue(Intersection.INPUT2))
GEOS_EXCEPT = True
Expand Down Expand Up @@ -83,10 +77,8 @@ def processAlgorithm(self, progress):
nElement = 0
# there is selection in input layer
if useSelection:
nFeat = vlayerA.selectedFeatureCount()
selectionA = vlayerA.selectedFeatures()
# we have selection in overlay layer
if useSelection2:
nFeat = vlayerA.selectedFeatureCount()
selectionA = vlayerA.selectedFeatures()
selectionB = vlayerB.selectedFeaturesIds()
for inFeatA in selectionA:
nElement += 1
Expand Down Expand Up @@ -116,72 +108,10 @@ def processAlgorithm(self, progress):
except:
GEOS_EXCEPT = False
break
# we don't have selection in overlay layer
else:
for inFeatA in selectionA:
nElement += 1
progress.setPercentage(int(nElement/nFeat * 100))
geom = QgsGeometry( inFeatA.geometry() )
atMapA = inFeatA.attributeMap()
intersects = index.intersects( geom.boundingBox() )
for id in intersects:
vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
tmpGeom = QgsGeometry( inFeatB.geometry() )
try:
if geom.intersects( tmpGeom ):
atMapB = inFeatB.attributeMap()
int_geom = QgsGeometry( geom.intersection( tmpGeom ) )
if int_geom.wkbType() == 7:
int_com = geom.combine( tmpGeom )
int_sym = geom.symDifference( tmpGeom )
int_geom = QgsGeometry( int_com.difference( int_sym ) )
try:
outFeat.setGeometry( int_geom )
outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
writer.addFeature( outFeat )
except:
FEATURE_EXCEPT = False
continue
except:
GEOS_EXCEPT = False
break
# there is no selection in input layer

else:
nFeat = vproviderA.featureCount()
vproviderA.rewind()
# we have selection in overlay layer
if useSelection2:
selectionB = vlayerB.selectedFeaturesIds()
while vproviderA.nextFeature( inFeatA ):
nElement += 1
progress.setPercentage(int(nElement/nFeat * 100))
geom = QgsGeometry( inFeatA.geometry() )
atMapA = inFeatA.attributeMap()
intersects = index.intersects( geom.boundingBox() )
for id in intersects:
if id in selectionB:
vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
tmpGeom = QgsGeometry( inFeatB.geometry() )
try:
if geom.intersects( tmpGeom ):
atMapB = inFeatB.attributeMap()
int_geom = QgsGeometry( geom.intersection( tmpGeom ) )
if int_geom.wkbType() == 7:
int_com = geom.combine( tmpGeom )
int_sym = geom.symDifference( tmpGeom )
int_geom = QgsGeometry( int_com.difference( int_sym ) )
try:
outFeat.setGeometry( int_geom )
outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
writer.addFeature( outFeat )
except:
FEATURE_EXCEPT = False
continue
except:
GEOS_EXCEPT = False
break
# we have no selection in overlay layer
else:
nFeat = vproviderA.featureCount()
vproviderA.rewind()
while vproviderA.nextFeature( inFeatA ):
nElement += 1
progress.setPercentage(int(nElement/nFeat * 100))
Expand Down Expand Up @@ -209,17 +139,16 @@ def processAlgorithm(self, progress):
except:
GEOS_EXCEPT = False
break

del writer
if not GEOS_EXCEPT:
SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Geometry exception while computing intersection")
if not FEATURE_EXCEPT:
SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Feature exception while computing interesection")
SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Feature exception while computing intersection")

def defineCharacteristics(self):
self.name = "Intersection"
self.group = "Vector overlay tools"
self.addParameter(ParameterVector(Intersection.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
self.addParameter(ParameterVector(Intersection.INPUT2, "Intersect layer", ParameterVector.VECTOR_TYPE_ANY))
self.addParameter(ParameterBoolean(Intersection.USE_SELECTED, "Use selected features (input)", False))
self.addParameter(ParameterBoolean(Intersection.USE_SELECTED2, "Use selected features (intersect)", False))
self.addOutput(OutputVector(Intersection.OUTPUT, "Intersection"))
9 changes: 1 addition & 8 deletions python/plugins/sextante/algs/ftools/LinesIntersection.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,14 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *

from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.QGisLayers import QGisLayers

from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterTableField import ParameterTableField

from sextante.outputs.OutputVector import OutputVector

from sextante.algs.ftools import FToolsUtils as utils

class LinesIntersection(GeoAlgorithm):
Expand Down Expand Up @@ -85,7 +78,7 @@ def processAlgorithm(self, progress):
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fieldList,
QGis.WKBPoint, providerA.crs())

spatialIndex = utils.createSpatialIndex(providerB)
spatialIndex = utils.createSpatialIndex(layerB)

providerA.rewind()
layerA.select([idxA])
Expand Down
21 changes: 4 additions & 17 deletions python/plugins/sextante/algs/ftools/LinesToPolygons.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,12 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *

from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.QGisLayers import QGisLayers

from sextante.parameters.ParameterVector import ParameterVector

from sextante.outputs.OutputVector import OutputVector

class LinesToPolygons(GeoAlgorithm):

INPUT = "INPUT"
Expand All @@ -63,20 +55,15 @@ def processAlgorithm(self, progress):
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
QGis.WKBPolygon, provider.crs())

inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()

current = 0
total = 100.0 / float(provider.featureCount())

while layer.nextFeature(inFeat):
current = 0
features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
for inFeat in features:
outGeomList = []
multi = False

if inFeat.geometry().isMultipart():
outGeomList = inFeat.geometry().asMultiPolyline()
multi = True
else:
outGeomList.append(inFeat.geometry().asPolyline())

Expand Down
5 changes: 0 additions & 5 deletions python/plugins/sextante/algs/ftools/MeanCoords.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *
Expand Down Expand Up @@ -69,8 +66,6 @@ def processAlgorithm(self, progress):
weightField = self.getParameterValue(self.WEIGHT)
uniqueField = self.getParameterValue(self.UID)

output = self.getOutputValue(self.OUTPUT)

provider = layer.dataProvider()
weightIndex = layer.fieldNameIndex(weightField)
uniqueIndex = layer.fieldNameIndex(uniqueField)
Expand Down
13 changes: 4 additions & 9 deletions python/plugins/sextante/algs/ftools/MultipartToSingleparts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *
Expand Down Expand Up @@ -57,7 +54,6 @@ def defineCharacteristics(self):

def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
output = self.getOutputValue(self.OUTPUT)

provider = layer.dataProvider()
layer.select(layer.pendingAllAttributesList())
Expand All @@ -66,15 +62,14 @@ def processAlgorithm(self, progress):

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
geomType, provider.crs())

inFeat = QgsFeature()

outFeat = QgsFeature()
inGeom = QgsGeometry()

current = 0
total = 100.0 / float(provider.featureCount())

while layer.nextFeature(inFeat):
features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
for inFeat in features:
inGeom = inFeat.geometry()
atMap = inFeat.attributeMap()

Expand Down
21 changes: 6 additions & 15 deletions python/plugins/sextante/algs/ftools/NearestNeighbourAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,13 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path
import math

from PyQt4 import QtGui

from qgis.core import *

from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.QGisLayers import QGisLayers

from sextante.parameters.ParameterVector import ParameterVector

from sextante.outputs.OutputHTML import OutputHTML
from sextante.outputs.OutputNumber import OutputNumber

from sextante.algs.ftools import FToolsUtils as utils

class NearestNeighbourAnalysis(GeoAlgorithm):
Expand Down Expand Up @@ -77,22 +69,21 @@ def processAlgorithm(self, progress):
output = self.getOutputValue(self.OUTPUT)

provider = layer.dataProvider()
spatialIndex = utils.createSpatialIndex(provider)
spatialIndex = utils.createSpatialIndex(layer)
provider.rewind()
provider.select()

feat = QgsFeature()

neighbour = QgsFeature()
distance = QgsDistanceArea()

sumDist = 0.00
A = layer.extent()
A = float(A.width() * A.height())

current = 0
total = 100.0 / float(provider.featureCount())

while provider.nextFeature( feat ):
current = 0
features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
for feat in features:
neighbourID = spatialIndex.nearestNeighbor(feat.geometry().asPoint(), 2)[1]
provider.featureAtId(neighbourID, neighbour, True)
sumDist += distance.measureLine(neighbour.geometry().asPoint(), feat.geometry().asPoint())
Expand Down
4 changes: 0 additions & 4 deletions python/plugins/sextante/algs/ftools/PointDistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path
import csv
import math
import codecs
import cStringIO

from PyQt4 import QtGui
from qgis.core import *

from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.QGisLayers import QGisLayers

Expand Down
15 changes: 4 additions & 11 deletions python/plugins/sextante/algs/ftools/PointsInPolygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,16 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *

from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.QGisLayers import QGisLayers
from sextante.core.SextanteLog import SextanteLog

from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterString import ParameterString

from sextante.outputs.OutputVector import OutputVector

from sextante.algs.ftools import FToolsUtils as utils


Expand Down Expand Up @@ -68,8 +62,6 @@ def processAlgorithm(self, progress):
pointLayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.POINTS))
fieldName = self.getParameterValue(self.FIELD)

output = self.getOutputValue(self.OUTPUT)

polyProvider = polyLayer.dataProvider()
pointProvider = pointLayer.dataProvider()
if polyProvider.crs() != pointProvider.crs():
Expand All @@ -81,7 +73,7 @@ def processAlgorithm(self, progress):
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fieldList,
polyProvider.geometryType(), polyProvider.crs())

spatialIndex = utils.createSpatialIndex(pointProvider)
spatialIndex = utils.createSpatialIndex(pointLayer)

pointProvider.rewind()
pointProvider.select()
Expand All @@ -95,10 +87,11 @@ def processAlgorithm(self, progress):
geom = QgsGeometry()

current = 0
total = 100.0 / float(polyProvider.featureCount())
hasIntersections = False

while polyLayer.nextFeature(ftPoly):
features = QGisLayers.features(polyLayer)
total = 100.0 / float(len(features))
for ftPoly in features:
geom = ftPoly.geometry()
atMap = ftPoly.attributeMap()

Expand Down
10 changes: 4 additions & 6 deletions python/plugins/sextante/algs/ftools/PointsInPolygonUnique.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ def processAlgorithm(self, progress):
fieldName = self.getParameterValue(self.FIELD)
classFieldName = self.getParameterValue(self.CLASSFIELD)

output = self.getOutputValue(self.OUTPUT)

polyProvider = polyLayer.dataProvider()
pointProvider = pointLayer.dataProvider()
if polyProvider.crs() != pointProvider.crs():
Expand All @@ -85,24 +83,24 @@ def processAlgorithm(self, progress):
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fieldList,
polyProvider.geometryType(), polyProvider.crs())

spatialIndex = utils.createSpatialIndex(pointProvider)
spatialIndex = utils.createSpatialIndex(pointLayer)

pointProvider.rewind()
pointProvider.select()

allAttrs = polyLayer.pendingAllAttributesList()
polyLayer.select(allAttrs)

ftPoly = QgsFeature()
ftPoint = QgsFeature()
outFeat = QgsFeature()
geom = QgsGeometry()

current = 0
total = float(polyProvider.featureCount())
hasIntersections = False

while polyLayer.nextFeature(ftPoly):
features = QGisLayers.features(polyLayer)
total = 100.0 / float(len(features))
for ftPoly in features:
geom = ftPoly.geometry()
atMap = ftPoly.attributeMap()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,24 @@ def processAlgorithm(self, progress):
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fieldList,
polyProvider.geometryType(), polyProvider.crs())

spatialIndex = utils.createSpatialIndex(pointProvider)
spatialIndex = utils.createSpatialIndex(pointLayer)

pointProvider.rewind()
pointProvider.select()

allAttrs = polyLayer.pendingAllAttributesList()
polyLayer.select(allAttrs)

ftPoly = QgsFeature()
ftPoint = QgsFeature()
outFeat = QgsFeature()
geom = QgsGeometry()

current = 0
total = 100.0 / float(polyProvider.featureCount())
hasIntersections = False

while polyLayer.nextFeature(ftPoly):
features = QGisLayers.features(polyLayer)
total = 100.0 / float(len(features))
for ftPoly in features:
geom = ftPoly.geometry()
atMap = ftPoly.attributeMap()

Expand Down
16 changes: 5 additions & 11 deletions python/plugins/sextante/algs/ftools/PolygonsToLines.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *
Expand Down Expand Up @@ -57,7 +55,6 @@ def defineCharacteristics(self):

def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
output = self.getOutputValue(self.OUTPUT)

provider = layer.dataProvider()
layer.select(layer.pendingAllAttributesList())
Expand All @@ -71,19 +68,16 @@ def processAlgorithm(self, progress):
outGeom = QgsGeometry()

current = 0
total = 100.0 / float(provider.featureCount())

while layer.nextFeature(inFeat):
multi = False
features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
for inFeat in features:
inGeom = inFeat.geometry()
if inGeom.isMultipart():
multi = True
atMap = inFeat.attributeMap()
lineList = self.extractAsLine(inGeom)
outFeat.setAttributeMap(atMap)
for h in lineList:
outFeat.setGeometry(outGeom.fromPolyline(h))
writer.addFeature(outFeat)
outFeat.setGeometry(outGeom.fromPolyline(h))
writer.addFeature(outFeat)

current += 1
progress.setPercentage(int(current * total))
Expand Down
9 changes: 4 additions & 5 deletions python/plugins/sextante/algs/ftools/RandomSelection.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path
import random

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *
Expand Down Expand Up @@ -63,7 +61,7 @@ def defineCharacteristics(self):

self.addParameter(ParameterVector(self.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
self.addParameter(ParameterSelection(self.METHOD, "Method", self.METHODS, 0))
self.addParameter(ParameterNumber(self.NUMBER, "Number/persentage of selected features", 1, None, 10))
self.addParameter(ParameterNumber(self.NUMBER, "Number/percentage of selected features", 0, None, 10))
self.addOutput(OutputVector(self.OUTPUT, "Selection", True))

def processAlgorithm(self, progress):
Expand All @@ -77,13 +75,14 @@ def processAlgorithm(self, progress):

if method == 0:
if value > featureCount:
raise GeoAlgorithmExecutionException("Selected number is greater that feature count. Choose lesser value and try again.")
raise GeoAlgorithmExecutionException("Selected number is greater than feature count. Choose a lower value and try again.")
else:
if value > 100:
raise GeoAlgorithmExecutionException("Persentage can't be greater than 100. Set corrent value and try again.")
raise GeoAlgorithmExecutionException("Persentage can't be greater than 100. Set a different value and try again.")
value = int(round((value / 100.0000), 4) * featureCount)

selran = random.sample(xrange(0, featureCount), value)

layer.setSelectedFeatures(selran)
self.setOutputValue(self.OUTPUT, filename)

Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path
import random

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *
Expand Down Expand Up @@ -78,7 +76,6 @@ def processAlgorithm(self, progress):
method = self.getParameterValue(self.METHOD)

layer.removeSelection(True)
provider = layer.dataProvider()
index = layer.fieldNameIndex(field)
layer.select([index])

Expand Down
19 changes: 5 additions & 14 deletions python/plugins/sextante/algs/ftools/ReprojectLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,14 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *

from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.QGisLayers import QGisLayers
from sextante.core.SextanteLog import SextanteLog

from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterCrs import ParameterCrs

from sextante.outputs.OutputVector import OutputVector

class ReprojectLayer(GeoAlgorithm):
Expand Down Expand Up @@ -64,22 +58,19 @@ def processAlgorithm(self, progress):
crsId = self.getParameterValue(self.TARGET_CRS)
targetCrs = QgsCoordinateReferenceSystem(int(crsId))

output = self.getOutputValue(self.OUTPUT)

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
layer.wkbType(), targetCrs)

layer.select(layer.pendingAllAttributesList())

current = 0
total = 100.0 / float(layer.featureCount())

layerCrs = layer.crs()
crsTransform = QgsCoordinateTransform(layerCrs, targetCrs)

f = QgsFeature()

outFeat = QgsFeature()
while layer.nextFeature(f):
current = 0
features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
for f in features:
geom = f.geometry()
geom.transform(crsTransform)
outFeat.setGeometry(geom)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/algs/ftools/SelectByLocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def processAlgorithm(self, progress):
inputProvider = inputLayer.dataProvider()
selectProvider = selectLayer.dataProvider()

index = utils.createSpatialIndex(inputProvider)
index = utils.createSpatialIndex(inputLayer)

inputProvider.select()
selectProvider.select()
Expand Down
11 changes: 5 additions & 6 deletions python/plugins/sextante/algs/ftools/SinglePartsToMultiparts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *
Expand Down Expand Up @@ -81,15 +78,17 @@ def processAlgorithm(self, progress):
unique = layer.uniqueValues(index)

current = 0
total = 100.0 / float(provider.featureCount() * len(unique))
features = QGisLayers.features(layer)
total = 100.0 / float(len(features) * len(unique))

if not len(unique) == layer.featureCount():
for i in unique:
provider.rewind()
#provider.rewind()
multi_feature= []
first = True
layer.select(allAttrs)
while layer.nextFeature(inFeat):
features = QGisLayers.features(layer)
for inFeat in features:
atMap = inFeat.attributeMap()
idVar = atMap[index]
if idVar.toString().trimmed() == i.toString().trimmed():
Expand Down
12 changes: 5 additions & 7 deletions python/plugins/sextante/algs/ftools/SumLines.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ def processAlgorithm(self, progress):
lengthFieldName = self.getParameterValue(self.LEN_FIELD)
countFieldName = self.getParameterValue(self.COUNT_FIELD)

output = self.getOutputValue(self.OUTPUT)

polyProvider = polyLayer.dataProvider()
lineProvider = lineLayer.dataProvider()
if polyProvider.crs() != lineProvider.crs():
Expand All @@ -84,7 +82,7 @@ def processAlgorithm(self, progress):
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fieldList,
polyProvider.geometryType(), polyProvider.crs())

spatialIndex = utils.createSpatialIndex(lineProvider)
spatialIndex = utils.createSpatialIndex(lineLayer)

lineProvider.rewind()
lineProvider.select()
Expand All @@ -100,10 +98,10 @@ def processAlgorithm(self, progress):
distArea = QgsDistanceArea()

current = 0
total = 100.0 / float(polyProvider.featureCount())
hasIntersections = False

while polyLayer.nextFeature(ftPoly):
features = QGisLayers.features(polyLayer)
total = 100.0 / float(len(features))
hasIntersections = False
for ftPoly in features:
inGeom = QgsGeometry(ftPoly.geometry())
atMap = ftPoly.attributeMap()
count = 0
Expand Down
4 changes: 1 addition & 3 deletions python/plugins/sextante/algs/ftools/Union.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

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 *
Expand All @@ -35,6 +32,7 @@
from sextante.outputs.OutputVector import OutputVector
from sextante.algs.ftools import ftools_utils
from sextante.core.SextanteLog import SextanteLog
from sextante.core.GeoAlgorithm import GeoAlgorithm

class Union(GeoAlgorithm):

Expand Down
5 changes: 0 additions & 5 deletions python/plugins/sextante/algs/ftools/UniqueValues.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,12 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path
import codecs

from PyQt4 import QtGui

from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.QGisLayers import QGisLayers

from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterTableField import ParameterTableField

from sextante.outputs.OutputHTML import OutputHTML
from sextante.outputs.OutputNumber import OutputNumber

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *

from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.QGisLayers import QGisLayers

from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterBoolean import ParameterBoolean
from sextante.parameters.ParameterNumber import ParameterNumber
Expand All @@ -47,7 +43,6 @@ class VariableDistanceBuffer(GeoAlgorithm):
INPUT = "INPUT"
OUTPUT = "OUTPUT"
FIELD = "FIELD"
USE_SELECTED = "USE_SELECTED"
SEGMENTS = "SEGMENTS"
DISSOLVE = "DISSOLVE"

Expand All @@ -61,7 +56,6 @@ def defineCharacteristics(self):
self.group = "Vector geometry tools"

self.addParameter(ParameterVector(self.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
self.addParameter(ParameterBoolean(self.USE_SELECTED, "Use selected features", False))
self.addParameter(ParameterTableField(self.FIELD, "Distance field",self.INPUT ))
self.addParameter(ParameterNumber(self.SEGMENTS, "Segments", 1, default=5))
self.addParameter(ParameterBoolean(self.DISSOLVE, "Dissolve result", False))
Expand All @@ -70,7 +64,6 @@ def defineCharacteristics(self):

def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
useSelection = self.getParameterValue(self.USE_SELECTED)
dissolve = self.getParameterValue(self.DISSOLVE)
field = self.getParameterValue(self.FIELD)
segments = int(self.getParameterValue(self.SEGMENTS))
Expand All @@ -79,5 +72,5 @@ def processAlgorithm(self, progress):
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
QGis.WKBPolygon, provider.crs())

buff.buffering(progress, writer, 0, field, useSelection, True,
buff.buffering(progress, writer, 0, field, True,
layer, dissolve, segments)
5 changes: 2 additions & 3 deletions python/plugins/sextante/algs/ftools/VoronoiPolygons.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path
from sets import Set

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *
Expand Down Expand Up @@ -77,7 +75,8 @@ def processAlgorithm(self, progress):
ptDict = {}
ptNdx = -1

while layer.nextFeature(inFeat):
features = QGisLayers.features(layer)
for inFeat in features:
geom = QgsGeometry(inFeat.geometry())
point = geom.asPoint()
x = point.x()-extent.xMinimum()
Expand Down
59 changes: 26 additions & 33 deletions python/plugins/sextante/algs/ftools/ftools_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from sextante.core.QGisLayers import QGisLayers

__author__ = 'Carson Farmer, Victor Olaya'
__date__ = 'August 2012'
Expand Down Expand Up @@ -329,42 +330,34 @@ def getFieldType(vlayer, fieldName):
return field.typeName()

# return the number of unique values in field
def getUniqueValuesCount( vlayer, fieldIndex, useSelection ):
vprovider = vlayer.dataProvider()
def getUniqueValuesCount( layer, fieldIndex):
vprovider = layer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
count = 0
values = []
if useSelection:
selection = vlayer.selectedFeatures()
for f in selection:
if f.attributeMap()[ fieldIndex ].toString() not in values:
values.append( f.attributeMap()[ fieldIndex ].toString() )
count += 1
else:
feat = QgsFeature()
while vprovider.nextFeature( feat ):
if feat.attributeMap()[ fieldIndex ].toString() not in values:
values.append( feat.attributeMap()[ fieldIndex ].toString() )
count += 1
values = []
features = QGisLayers.features(layer)
for feat in features:
if feat.attributeMap()[ fieldIndex ].toString() not in values:
values.append( feat.attributeMap()[ fieldIndex ].toString() )
count += 1
return count

def getShapesByGeometryType( baseDir, inShapes, geomType ):
outShapes = QStringList()
for fileName in inShapes:
layerPath = QFileInfo( baseDir + "/" + fileName ).absoluteFilePath()
vLayer = QgsVectorLayer( layerPath, QFileInfo( layerPath ).baseName(), "ogr" )
if not vLayer.isValid():
continue
layerGeometry = vLayer.geometryType()
if layerGeometry == QGis.Polygon and geomType == 0:
outShapes << fileName
elif layerGeometry == QGis.Line and geomType == 1:
outShapes << fileName
elif layerGeometry == QGis.Point and geomType == 2:
outShapes << fileName

if outShapes.count() == 0:
return None

return outShapes
outShapes = QStringList()
for fileName in inShapes:
layerPath = QFileInfo( baseDir + "/" + fileName ).absoluteFilePath()
vLayer = QgsVectorLayer( layerPath, QFileInfo( layerPath ).baseName(), "ogr" )
if not vLayer.isValid():
continue
layerGeometry = vLayer.geometryType()
if layerGeometry == QGis.Polygon and geomType == 0:
outShapes << fileName
elif layerGeometry == QGis.Line and geomType == 1:
outShapes << fileName
elif layerGeometry == QGis.Point and geomType == 2:
outShapes << fileName

if outShapes.count() == 0:
return None
return outShapes
2 changes: 1 addition & 1 deletion python/plugins/sextante/algs/ftools/voronoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ def computeDelaunayTriangulation(points):
"""
siteList = SiteList(points)
context = Context()
context.triangulate = true
context.triangulate = True
voronoi(siteList,context)
return context.triangles

Expand Down
1 change: 1 addition & 0 deletions python/plugins/sextante/core/QGisLayers.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class Features():
def __init__(self, layer):
self.layer = layer
self.selection = False;
self.layer.dataProvider().rewind()
if SextanteConfig.getSetting(SextanteConfig.USE_SELECTED):
self.selected = layer.selectedFeatures()
if len(self.selected) > 0:
Expand Down