Skip to content
Permalink
Browse files
started adapting sextante to new vector api
  • Loading branch information
volaya committed Feb 3, 2013
1 parent 28829dd commit 93dbfd7f35cb96ac9182edcfe8690d34889444a9
Showing with 1,153 additions and 1,116 deletions.
  1. +3 −5 python/plugins/sextante/algs/AddTableField.py
  2. +11 −12 python/plugins/sextante/algs/AutoincrementalField.py
  3. +17 −27 python/plugins/sextante/algs/EquivalentNumField.py
  4. +2 −6 python/plugins/sextante/algs/Explode.py
  5. +10 −16 python/plugins/sextante/algs/FieldPyculator.py
  6. +7 −7 python/plugins/sextante/algs/FieldsCalculator.py
  7. +16 −23 python/plugins/sextante/algs/JoinAttributes.py
  8. +2 −2 python/plugins/sextante/algs/ftools/BasicStatisticsNumbers.py
  9. +1 −1 python/plugins/sextante/algs/ftools/BasicStatisticsStrings.py
  10. +3 −3 python/plugins/sextante/algs/ftools/Buffer.py
  11. +4 −4 python/plugins/sextante/algs/ftools/Centroids.py
  12. +48 −48 python/plugins/sextante/algs/ftools/Clip.py
  13. +16 −12 python/plugins/sextante/algs/ftools/ConvexHull.py
  14. +10 −11 python/plugins/sextante/algs/ftools/Delaunay.py
  15. +3 −7 python/plugins/sextante/algs/ftools/DensifyGeometries.py
  16. +4 −8 python/plugins/sextante/algs/ftools/DensifyGeometriesInterval.py
  17. +6 −11 python/plugins/sextante/algs/ftools/Difference.py
  18. +10 −15 python/plugins/sextante/algs/ftools/Dissolve.py
  19. +43 −43 python/plugins/sextante/algs/ftools/ExtentFromLayer.py
  20. +0 −1 python/plugins/sextante/algs/ftools/ExtractNodes.py
  21. +51 −19 python/plugins/sextante/algs/ftools/FToolsUtils.py
  22. +15 −18 python/plugins/sextante/algs/ftools/Intersection.py
  23. +6 −13 python/plugins/sextante/algs/ftools/LinesIntersection.py
  24. +2 −3 python/plugins/sextante/algs/ftools/LinesToPolygons.py
  25. +12 −21 python/plugins/sextante/algs/ftools/MeanCoords.py
  26. +3 −4 python/plugins/sextante/algs/ftools/MultipartToSingleparts.py
  27. +3 −6 python/plugins/sextante/algs/ftools/NearestNeighbourAnalysis.py
  28. +17 −33 python/plugins/sextante/algs/ftools/PointDistance.py
  29. +6 −9 python/plugins/sextante/algs/ftools/PointsInPolygon.py
  30. +8 −11 python/plugins/sextante/algs/ftools/PointsInPolygonUnique.py
  31. +8 −11 python/plugins/sextante/algs/ftools/PointsInPolygonWeighted.py
  32. +3 −6 python/plugins/sextante/algs/ftools/PolygonsToLines.py
  33. +3 −7 python/plugins/sextante/algs/ftools/RandomSelectionWithinSubsets.py
  34. +1 −3 python/plugins/sextante/algs/ftools/ReprojectLayer.py
  35. +0 −2 python/plugins/sextante/algs/ftools/SelectByLocation.py
  36. +2 −3 python/plugins/sextante/algs/ftools/SimplifyGeometries.py
  37. +4 −6 python/plugins/sextante/algs/ftools/SinglePartsToMultiparts.py
  38. +11 −11 python/plugins/sextante/algs/ftools/SumLines.py
  39. +18 −20 python/plugins/sextante/algs/ftools/Union.py
  40. +2 −1 python/plugins/sextante/algs/ftools/UniqueValues.py
  41. +1 −2 python/plugins/sextante/algs/ftools/VariableDistanceBuffer.py
  42. +2 −5 python/plugins/sextante/algs/ftools/VoronoiPolygons.py
  43. +725 −302 python/plugins/sextante/algs/mmqgisx/MMQGISXAlgorithms.py
  44. +20 −333 python/plugins/sextante/algs/mmqgisx/mmqgisx_library.py
  45. +7 −3 python/plugins/sextante/core/QGisLayers.py
  46. +6 −1 python/plugins/sextante/core/SextanteVectorWriter.py
  47. +1 −1 python/plugins/sextante/outputs/OutputVector.py
@@ -63,23 +63,21 @@ def processAlgorithm(self, progress):
output = self.getOutputFromName(self.OUTPUT_LAYER)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT_LAYER))
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
fields = vprovider.fields()
fields[len(fields)] = QgsField(fieldname, self.TYPES[fieldtype])
writer = output.getVectorWriter(fields, vprovider.geometryType(), vprovider.crs() )
outFeat = QgsFeature()
inGeom = QgsGeometry()
nFeat = vprovider.featureCount()
inGeom = QgsGeometry()
nElement = 0
features = QGisLayers.features(vlayer)
nFeat = len(features)
for inFeat in features:
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
inGeom = inFeat.geometry()
outFeat.setGeometry( inGeom )
atMap = inFeat.attributeMap()
outFeat.setAttributeMap( atMap )
atMap.append(QVariant())
outFeat.addAttribute( len(vprovider.fields()), QVariant() )
writer.addFeature( outFeat )
del writer
@@ -44,25 +44,24 @@ def processAlgorithm(self, progress):
output = self.getOutputFromName(self.OUTPUT)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
fields = vprovider.fields()
fields[len(fields)] = QgsField("AUTO", QVariant.Int)
writer = output.getVectorWriter(fields, vprovider.geometryType(), vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
nFeat = vprovider.featureCount()
nElement = 0
while vprovider.nextFeature(inFeat):
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
inGeom = inFeat.geometry()
outFeat.setGeometry( inGeom )
atMap = inFeat.attributeMap()
outFeat.setAttributeMap( atMap )
outFeat.addAttribute( len(vprovider.fields()), QVariant(nElement) )
writer.addFeature( outFeat )
features = QGisLayers.features(vlayer)
nFeat = len(features)
for inFeat in features:
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
inGeom = inFeat.geometry()
outFeat.setGeometry( inGeom )
atMap = inFeat.attributeMap()
atMap.append(QVariant(nElement))
outFeat.setAttributeMap( atMap )
writer.addFeature( outFeat )
del writer

def defineCharacteristics(self):
@@ -29,7 +29,6 @@
from sextante.parameters.ParameterVector import ParameterVector
from sextante.core.QGisLayers import QGisLayers
from sextante.outputs.OutputVector import OutputVector
from PyQt4 import QtGui
from sextante.parameters.ParameterTableField import ParameterTableField

class EquivalentNumField(GeoAlgorithm):
@@ -48,37 +47,28 @@ def processAlgorithm(self, progress):
output = self.getOutputFromName(self.OUTPUT)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
vprovider = vlayer.dataProvider()
field_index = vprovider.fieldNameIndex(fieldname)
allAttrs = vprovider.attributeIndexes()
vprovider.select(allAttrs)
fieldindex = vlayer.fieldNameIndex(fieldname)
fields = vprovider.fields()
fields[len(fields)] = QgsField("NUM_FIELD", QVariant.Int)
writer = output.getVectorWriter(fields, vprovider.geometryType(), vprovider.crs() )
inFeat = QgsFeature()
fields.append(QgsField("NUM_FIELD", QVariant.Int))
writer = output.getVectorWriter(fields, vprovider.geometryType(), vprovider.crs() )
outFeat = QgsFeature()
inGeom = QgsGeometry()
nFeat = vprovider.featureCount()
inGeom = QgsGeometry()
nElement = 0
classes = {}
features = QGisLayers.features(layer)
features = QGisLayers.features(vlayer)
nFeat = len(features)
for feature in features:
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
atMap = feature.attributeMap()
clazz = atMap[field_index].toString()
if clazz not in classes:
classes[clazz] = len(classes.keys())
features = QGisLayers.features(layer)
for feature in features:
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
inGeom = features.geometry()
outFeat.setGeometry( inGeom )
atMap = inFeat.attributeMap()
clazz = atMap[field_index].toString()
outFeat.setAttributeMap( atMap )
outFeat.addAttribute( len(vprovider.fields()), QVariant(classes[clazz]) )
writer.addFeature( outFeat )
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
inGeom = feature.geometry()
outFeat.setGeometry( inGeom )
atMap = feature.attributes()
clazz = atMap[fieldindex].toString()
if clazz not in classes:
classes[clazz] = len(classes.keys())
atMap.append(QVariant(classes[clazz]))
outFeat.setAttributes(atMap)
writer.addFeature( outFeat )
del writer

def defineCharacteristics(self):
@@ -24,7 +24,6 @@
__revision__ = '$Format:%H$'

from sextante.core.GeoAlgorithm import GeoAlgorithm
from PyQt4 import QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
@@ -46,11 +45,8 @@ def processAlgorithm(self, progress):
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
output = self.getOutputFromName(self.OUTPUT)
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
fields = vprovider.fields()
writer = output.getVectorWriter(fields, QGis.WKBLineString, vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
nFeat = vprovider.featureCount()
@@ -60,9 +56,9 @@ def processAlgorithm(self, progress):
nElement += 1
progress.setPercentage((nElement*100)/nFeat)
inGeom = feature.geometry()
atMap = feature.attributeMap()
atMap = feature.attributes()
segments = self.extractAsSingleSegments( inGeom )
outFeat.setAttributeMap( atMap )
outFeat.setAttributes( atMap )
for segment in segments:
outFeat.setGeometry(segment)
writer.addFeature(outFeat)
@@ -70,7 +70,7 @@ def processAlgorithm(self, progress):
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
fields = vprovider.fields()
fields[len(fields)] = QgsField(fieldname, QVariant.Double)
fields.append(QgsField(fieldname, QVariant.Double))
writer = output.getVectorWriter(fields, vprovider.geometryType(), vprovider.crs() )
outFeat = QgsFeature()
new_ns = {}
@@ -86,11 +86,13 @@ def processAlgorithm(self, progress):
(unicode(sys.exc_info()[0].__name__), unicode(sys.exc_info()[1])))

#replace all fields tags
field_map = vprovider.fields()
for num, field in field_map.iteritems():
fields = vprovider.fields()
num = 0
for field in fields:
field_name = unicode(field.name())
replval = '__attr[' + str(num) + ']'
code = code.replace("<"+field_name+">",replval)
num += 1

#replace all special vars
code = code.replace('$id','__id')
@@ -109,18 +111,12 @@ def processAlgorithm(self, progress):
(unicode(sys.exc_info()[0].__name__), unicode(sys.exc_info()[1])))

#run
if need_attrs:
attr_ind = vprovider.attributeIndexes()
else:
attr_ind = []
vprovider.select(attr_ind, QgsRectangle(), True)

features = QGisLayers.features(layer)
nFeatures = len(features)
nElement = 1
for feat in features:
progress.setPercentage(int((100 * nElement)/nFeatures))
attrMap = feat.attributeMap()
attrMap = feat.attributes()
feat_id = feat.id()

#add needed vars
@@ -132,10 +128,8 @@ def processAlgorithm(self, progress):
new_ns['__geom'] = geom

if need_attrs:
attr = []
for num,a in attrMap.iteritems():
attr.append(self.Qvar2py(a))
new_ns['__attr'] = attr
pyattrs = [self.Qvar2py(a) for a in attrMap]
new_ns['__attr'] = pyattrs

#clear old result
if new_ns.has_key(self.RESULT_VAR_NAME):
@@ -165,8 +159,8 @@ def processAlgorithm(self, progress):
#write feature
nElement += 1
outFeat.setGeometry( feat.geometry() )
outFeat.setAttributeMap( attrMap )
outFeat.addAttribute(len(vprovider.fields()), QVariant(new_ns[self.RESULT_VAR_NAME]))
attrMap.append(QVariant(new_ns[self.RESULT_VAR_NAME]))
outFeat.setAttributeMap( attrMap )
writer.addFeature(outFeat)

del writer
@@ -60,10 +60,8 @@ def processAlgorithm(self, progress):
output = self.getOutputFromName(self.OUTPUT_LAYER)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT_LAYER))
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select(allAttrs)
fields = vprovider.fields()
fields[len(fields)] = QgsField(fieldname, QVariant.Double)
fields.append(QgsField(fieldname, QVariant.Double))
writer = output.getVectorWriter(fields, vprovider.geometryType(), vprovider.crs())
outFeat = QgsFeature()
inGeom = QgsGeometry()
@@ -72,10 +70,12 @@ def processAlgorithm(self, progress):
features = QGisLayers.features(vlayer)
for inFeat in features:
progress.setPercentage(int((100 * nElement) / nFeat))
attrs = inFeat.attributeMap()
attrs = inFeat.attributes()
expression = formula
for (k, attr) in attrs.iteritems():
k = 0
for attr in attrs:
expression = expression.replace(str(fields[k].name()), str(attr.toString()))
k += 1
try:
result = eval(expression)
except Exception:
@@ -85,8 +85,8 @@ def processAlgorithm(self, progress):
inGeom = inFeat.geometry()
outFeat.setGeometry(inGeom)
atMap = inFeat.attributeMap()
outFeat.setAttributeMap(atMap)
outFeat.addAttribute(len(vprovider.fields()), QVariant(result))
atMap.append(QVariant(result))
outFeat.setAttributeMap(atMap)
writer.addFeature(outFeat)
del writer

@@ -16,8 +16,6 @@
* *
***************************************************************************
"""
from sextante.core.SextanteVectorWriter import SextanteVectorWriter
from sextante.parameters.ParameterTableField import ParameterTableField

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
@@ -28,6 +26,7 @@
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.outputs.OutputVector import OutputVector
from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterTableField import ParameterTableField
from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
@@ -61,22 +60,17 @@ def processAlgorithm(self, progress):
# Layer 1
layer = QGisLayers.getObjectFromUri(input)
provider = layer.dataProvider()
allAttrs = provider.attributeIndexes()
provider.select(allAttrs)
join_field1_index = provider.fieldNameIndex(field)
join_field1_index = layer.fieldNameIndex(field)
# Layer 2
layer2 = QGisLayers.getObjectFromUri(input2)
provider2 = layer2.dataProvider()
allAttrs = provider2.attributeIndexes()
provider2.select(allAttrs)
fields2 = provider2.fields()
join_field2_index = provider2.fieldNameIndex(field2)
join_field2_index = layer2.fieldNameIndex(field2)

# Output
outFields = provider.fields()
for (i, f) in fields2.iteritems():
f.setName("x_" + f.name())
outFields[len(outFields)] = f
outFields = input.fields()
for f in fields2:
outFields.append(f)

writer = output.getVectorWriter(outFields, provider.geometryType(), provider.crs())

@@ -85,22 +79,21 @@ def processAlgorithm(self, progress):
outFeat = QgsFeature()

# Create output vector layer with additional attribute
while provider.nextFeature(inFeat):
features = QGisLayers.features(layer);
for inFeat in features:
inGeom = inFeat.geometry()
atMap = inFeat.attributeMap()
join_value1 = atMap[join_field1_index].toString()
provider2.rewind()
atMap = inFeat.attributes()
join_value1 = atMap[join_field1_index].toString()
while provider2.nextFeature(inFeat2):
## Maybe it should cache this entries...
atMap2 = inFeat2.attributeMap()
join_value2 = atMap2[join_field2_index].toString()
if join_value1 == join_value2:
# create the new feature
outFeat.setGeometry(inGeom)
outFeat.setAttributeMap(atMap)
l = len(provider.fields())
for (i, a) in atMap2.iteritems():
outFeat.addAttribute(l + i, a)

writer.addFeature(outFeat)
outFeat.setGeometry(inGeom)
atMap.extend(atMap2)
break;
outFeat.setAttributes(atMap)
writer.addFeature(outFeat)

del writer
@@ -92,7 +92,7 @@ def processAlgorithm(self, progress):
outputFile = self.getOutputValue(self.OUTPUT_HTML_FILE)

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

cvValue = 0
minValue = 0
@@ -110,7 +110,7 @@ def processAlgorithm(self, progress):
total = 100.0 / float(count)
current = 0
for ft in features:
value = float(ft.attributeMap()[index].toDouble()[0])
value = float(ft.attributes()[index].toDouble()[0])

if isFirst:
minValue = value
@@ -101,7 +101,7 @@ def processAlgorithm(self, progress):
total = 100.0 / float(count)
current = 0
for ft in features:
length = float(len(ft.attributeMap()[index].toString()))
length = float(len(ft.attributes()[index].toString()))

if isFirst:
minValue = length
@@ -52,7 +52,7 @@ def buffering(progress, writer, distance, field, useField, layer, dissolve, segm
if dissolve:
first = True
for inFeat in features:
atMap = inFeat.attributeMap()
atMap = inFeat.attributes()
if useField:
value = atMap[field].toDouble()[0]
else:
@@ -84,7 +84,7 @@ def buffering(progress, writer, distance, field, useField, layer, dissolve, segm
# without dissolve
else:
for inFeat in features:
atMap = inFeat.attributeMap()
atMap = inFeat.attributes()
if useField:
value = atMap[field].toDouble()[0]
else:
@@ -95,7 +95,7 @@ def buffering(progress, writer, distance, field, useField, layer, dissolve, segm
outGeom = inGeom.buffer(float(value), segments)
try:
outFeat.setGeometry(outGeom)
outFeat.setAttributeMap(atMap)
outFeat.setAttributes(atMap)
writer.addFeature(outFeat)
except:
FEATURE_EXCEPT = False
Loading

0 comments on commit 93dbfd7

Please sign in to comment.