Skip to content
Permalink
Browse files

housekeeping: remove obsolete code, completely switch to new vector API

  • Loading branch information
alexbruy committed Mar 21, 2013
1 parent 6df3540 commit 9afe76d4d63e57abfbf8b42d2333fde548d78de3
Showing with 235 additions and 259 deletions.
  1. +5 −1 python/plugins/sextante/algs/ftools/BasicStatisticsNumbers.py
  2. +5 −3 python/plugins/sextante/algs/ftools/BasicStatisticsStrings.py
  3. +6 −7 python/plugins/sextante/algs/ftools/Buffer.py
  4. +1 −3 python/plugins/sextante/algs/ftools/Centroids.py
  5. +1 −9 python/plugins/sextante/algs/ftools/ConvexHull.py
  6. +15 −9 python/plugins/sextante/algs/ftools/Delaunay.py
  7. +3 −7 python/plugins/sextante/algs/ftools/DensifyGeometries.py
  8. +4 −6 python/plugins/sextante/algs/ftools/DensifyGeometriesInterval.py
  9. +22 −17 python/plugins/sextante/algs/ftools/ExportGeometryInfo.py
  10. +27 −24 python/plugins/sextante/algs/ftools/ExtentFromLayer.py
  11. +7 −8 python/plugins/sextante/algs/ftools/ExtractNodes.py
  12. +14 −13 python/plugins/sextante/algs/ftools/FToolsUtils.py
  13. +1 −2 python/plugins/sextante/algs/ftools/FixedDistanceBuffer.py
  14. +10 −12 python/plugins/sextante/algs/ftools/LinesIntersection.py
  15. +9 −9 python/plugins/sextante/algs/ftools/LinesToPolygons.py
  16. +2 −4 python/plugins/sextante/algs/ftools/MeanCoords.py
  17. +12 −15 python/plugins/sextante/algs/ftools/MultipartToSingleparts.py
  18. +2 −2 python/plugins/sextante/algs/ftools/NearestNeighbourAnalysis.py
  19. +15 −9 python/plugins/sextante/algs/ftools/PointDistance.py
  20. +11 −12 python/plugins/sextante/algs/ftools/PointsInPolygon.py
  21. +9 −16 python/plugins/sextante/algs/ftools/PointsInPolygonUnique.py
  22. +10 −18 python/plugins/sextante/algs/ftools/PointsInPolygonWeighted.py
  23. +5 −6 python/plugins/sextante/algs/ftools/PolygonsToLines.py
  24. +2 −2 python/plugins/sextante/algs/ftools/RandomSelection.py
  25. +5 −4 python/plugins/sextante/algs/ftools/RandomSelectionWithinSubsets.py
  26. +1 −1 python/plugins/sextante/algs/ftools/ReprojectLayer.py
  27. +10 −12 python/plugins/sextante/algs/ftools/SelectByLocation.py
  28. +3 −6 python/plugins/sextante/algs/ftools/SimplifyGeometries.py
  29. +2 −7 python/plugins/sextante/algs/ftools/SinglePartsToMultiparts.py
  30. +9 −12 python/plugins/sextante/algs/ftools/SumLines.py
  31. +3 −0 python/plugins/sextante/algs/ftools/UniqueValues.py
  32. +1 −1 python/plugins/sextante/algs/ftools/VariableDistanceBuffer.py
  33. +3 −2 python/plugins/sextante/algs/ftools/VoronoiPolygons.py
@@ -24,12 +24,17 @@
__revision__ = '$Format:%H$'

import math

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.OutputHTML import OutputHTML
from sextante.outputs.OutputNumber import OutputNumber

@@ -86,7 +91,6 @@ def processAlgorithm(self, progress):
outputFile = self.getOutputValue(self.OUTPUT_HTML_FILE)

index = layer.fieldNameIndex(fieldName)
#layer.select([index], QgsRectangle(), False)

cvValue = 0
minValue = 0
@@ -23,8 +23,8 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import codecs

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *
@@ -84,7 +84,6 @@ def processAlgorithm(self, progress):
outputFile = self.getOutputValue(self.OUTPUT_HTML_FILE)

index = layer.fieldNameIndex(fieldName)
layer.select([index], QgsRectangle(), False)

sumValue = 0
minValue = 0
@@ -150,7 +149,10 @@ def processAlgorithm(self, progress):
self.setOutputValue(self.UNIQUE, uniqueValues)

def createHTML(self, outputFile, algData):
f = open(outputFile, "w")
f = codecs.open(outputFile, "w", encoding="utf-8")
f.write('<html><head>')
f.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>')
for s in algData:
f.write("<p>" + str(s) + "</p>")
f.write("</body></html>")
f.close()
@@ -34,8 +34,6 @@ def buffering(progress, writer, distance, field, useField, layer, dissolve, segm
GEOS_EXCEPT = True
FEATURE_EXCEPT = True

layer.select(layer.pendingAllAttributesList())

if useField:
field = layer.fieldNameIndex(field)

@@ -52,9 +50,9 @@ def buffering(progress, writer, distance, field, useField, layer, dissolve, segm
if dissolve:
first = True
for inFeat in features:
atMap = inFeat.attributes()
attrs = inFeat.attributes()
if useField:
value = atMap[field].toDouble()[0]
value = attrs[field].toDouble()[0]
else:
value = distance

@@ -78,15 +76,16 @@ def buffering(progress, writer, distance, field, useField, layer, dissolve, segm
progress.setPercentage(int(current * total))
try:
outFeat.setGeometry(tempGeom)
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
except:
FEATURE_EXCEPT = False
# without dissolve
else:
for inFeat in features:
atMap = inFeat.attributes()
attrs = inFeat.attributes()
if useField:
value = atMap[field].toDouble()[0]
value = attrs[field].toDouble()[0]
else:
value = distance

@@ -95,7 +94,7 @@ def buffering(progress, writer, distance, field, useField, layer, dissolve, segm
outGeom = inGeom.buffer(float(value), segments)
try:
outFeat.setGeometry(outGeom)
outFeat.setAttributes(atMap)
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
except:
FEATURE_EXCEPT = False
@@ -55,11 +55,9 @@ def defineCharacteristics(self):
def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT_LAYER))

writer = self.getOutputFromName(self.OUTPUT_LAYER).getVectorWriter(layer.pendingFields(),
writer = self.getOutputFromName(self.OUTPUT_LAYER).getVectorWriter(layer.pendingFields().toList(),
QGis.WKBPoint, layer.crs())

#layer.select(layer.pendingAllAttributesList())

outFeat = QgsFeature()

features = QGisLayers.features(layer)
@@ -113,7 +113,7 @@ def processAlgorithm(self, progress):
first = True
features = QGisLayers.features(layer)
for f in features:
idVar = f.attribute(fieldName)
idVar = f[fieldName]
if idVar.toString().trimmed() == i.toString().trimmed():
if first:
val = idVar
@@ -135,10 +135,6 @@ def processAlgorithm(self, progress):
QVariant(area),
QVariant(perim)
])
#~ outFeat.setAttribute("id", QVariant(fid))
#~ outFeat.setAttribute("value", QVariant(val))
#~ outFeat.setAttribute("area", QVariant(area))
#~ outFeat.setAttribute("perim", QVariant(perim))
writer.addFeature(outFeat)
except:
GEOS_EXCEPT = False
@@ -165,10 +161,6 @@ def processAlgorithm(self, progress):
QVariant(area),
QVariant(perim)
])
#print outFeat.setAttribute("id", QVariant(0))
#print outFeat.setAttribute("value", QVariant("all"))
#print outFeat.setAttribute("area", QVariant(area))
#print outFeat.setAttribute("perim", QVariant(perim))
writer.addFeature(outFeat)
except:
GEOS_EXCEPT = False
@@ -23,17 +23,22 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from sets import Set

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.outputs.OutputVector import OutputVector

from sextante.parameters.ParameterVector import ParameterVector

from sextante.outputs.OutputVector import OutputVector

from sextante.algs.ftools import voronoi


class Delaunay(GeoAlgorithm):

@@ -57,9 +62,9 @@ def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))


fields = [ QgsField("POINTA", QVariant.Double, "", 24, 15),
QgsField("POINTB", QVariant.Double, "", 24, 15),
QgsField("POINTC", QVariant.Double, "", 24, 15)
fields = [QgsField("POINTA", QVariant.Double, "", 24, 15),
QgsField("POINTB", QVariant.Double, "", 24, 15),
QgsField("POINTC", QVariant.Double, "", 24, 15)
]

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields,
@@ -100,7 +105,8 @@ def processAlgorithm(self, progress):
attrs = []
step = 0
for index in indicies:
layer.featureAtId(ptDict[ids[index]], inFeat, True)
request = QgsFeatureRequest().setFilterFid(ptDict[ids[index]])
inFeat = layer.getFeatures(request).next()
geom = QgsGeometry(inFeat.geometry())
point = QgsPoint(geom.asPoint())
polygon.append(point)
@@ -23,7 +23,6 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'


from PyQt4.QtCore import *

from qgis.core import *
@@ -42,9 +41,6 @@ class DensifyGeometries(GeoAlgorithm):
VERTICES = "VERTICES"
OUTPUT = "OUTPUT"

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

def defineCharacteristics(self):
self.name = "Densify geometries"
self.group = "Vector geometry tools"
@@ -60,19 +56,19 @@ def processAlgorithm(self, progress):

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

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

features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
current = 0
for f in features:
featGeometry = QgsGeometry(f.geometry())
attrMap = f.attributes()
attrs = f.attributes()
newGeometry = self.densifyGeometry(featGeometry, int(vertices), isPolygon)
feature = QgsFeature()
feature.setGeometry(newGeometry)
feature.setAttributes(attrMap)
feature.setAttributes(attrs)
writer.addFeature(feature)
current += 1
progress.setPercentage(int(current * total))
@@ -3,8 +3,7 @@
"""
***************************************************************************
DensifyGeometriesInterval.py by Anita Graser, Dec 2012
based on
DensifyGeometries.py
based on DensifyGeometries.py
---------------------
Date : October 2012
Copyright : (C) 2012 by Victor Olaya
@@ -58,20 +57,19 @@ def processAlgorithm(self, progress):

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

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


features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
current = 0
for f in features:
featGeometry = QgsGeometry(f.geometry())
attrMap = f.attributes()
attrs = f.attributes()
newGeometry = self.densifyGeometry(featGeometry, interval, isPolygon)
feature = QgsFeature()
feature.setGeometry(newGeometry)
feature.setAttributes(attrMap)
feature.setAttributes(attrs)
writer.addFeature(feature)

current += 1
@@ -66,24 +66,26 @@ def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
method = self.getParameterValue(self.METHOD)

provider = layer.dataProvider()
geometryType = layer.geometryType()

layer.select(layer.pendingAllAttributesList())

fields = provider.fields()
idx1 = -1
idx2 = -1
fields = layer.pendingFields()

if geometryType == QGis.Polygon:
fields.append(QgsField(QString("area"), QVariant.Double))
fields.append(QgsField(QString("perimeter"), QVariant.Double))
idx1, fields = utils.findOrCreateField(layer, fields, "area", 21, 6)
idx2, fields = utils.findOrCreateField(layer, fields, "perimeter", 21, 6)
elif geometryType == QGis.Line:
fields.append(QgsField(QString("length"), QVariant.Double))
idx1, fields = utils.findOrCreateField(layer, fields, "length", 21, 6)
idx2 = idx1
else:
fields.append(QgsField(QString("xcoords"), QVariant.Double))
fields.append(QgsField(QString("ycoords"), QVariant.Double))
idx1, fields = utils.findOrCreateField(layer, fields, "xcoord", 21, 6)
idx2, fields = utils.findOrCreateField(layer, fields, "ycoord", 21, 6)

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields.toList(),
layer.dataProvider().geometryType(), layer.crs())

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields,
provider.geometryType(), layer.crs())
print idx1, idx2

ellips = None
crs = None
@@ -105,23 +107,26 @@ def processAlgorithm(self, progress):
outFeat = QgsFeature()
inGeom = QgsGeometry()

outFeat.initAttributes(len(fields))
outFeat.setFields(fields)

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

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

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

outFeat.setGeometry(inGeom)
atMap = inFeat.attributes()
atMap.append(QVariant(attr1))
attrs = f.attributes()
attrs.insert(idx1, QVariant(attr1))
if attr2 is not None:
atMap.append(QVariant(attr2))
outFeat.setAttributes(atMap)
attrs.insert(idx2, QVariant(attr2))
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)

current += 1

4 comments on commit 9afe76d

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Mar 22, 2013

@alexbruy , this possibly fixes http://hub.qgis.org/issues/7360 ; let me have a look at confirming it.

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Mar 22, 2013

@alexbruy issue still there; might not be entirely related to new vector API then. with a set of 655 points, QGIS chokes and dies around 50% of the process. With a >13,000 points set, it dies at 0%.

@alexbruy

This comment has been minimized.

Copy link
Contributor Author

@alexbruy alexbruy replied Mar 22, 2013

This commit only fixes issues introduced by further API cleanup. Don't know why you decide that this related to #7360

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Mar 22, 2013

@alexbruy , my apologies then, I thought this commit was migrating some ftools functions to new vector API and would fix ftools' delaunay triangulation function, which is currently broken on QGIS master.

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