Skip to content
Permalink
Browse files

Merge pull request #629 from volaya/sipapi

[sextante] updated to new sip api
  • Loading branch information
NathanW2 committed Jun 3, 2013
2 parents 75cbdf6 + e46795a commit 63cc02d67e28dee96d04b44902b9d6704eb3b49b
Showing with 138 additions and 195 deletions.
  1. +5 −5 python/plugins/sextante/admintools/ImportIntoPostGIS.py
  2. +5 −5 python/plugins/sextante/admintools/PostGISExecuteSQL.py
  3. +1 −1 python/plugins/sextante/algs/AddTableField.py
  4. +1 −1 python/plugins/sextante/algs/AutoincrementalField.py
  5. +2 −2 python/plugins/sextante/algs/EquivalentNumField.py
  6. +2 −10 python/plugins/sextante/algs/FieldPyculator.py
  7. +2 −2 python/plugins/sextante/algs/FieldsCalculator.py
  8. +2 −2 python/plugins/sextante/algs/JoinAttributes.py
  9. +2 −2 python/plugins/sextante/algs/PointsLayerFromTable.py
  10. +1 −1 python/plugins/sextante/algs/Polygonize.py
  11. +3 −3 python/plugins/sextante/algs/StatisticsByCategories.py
  12. +1 −1 python/plugins/sextante/algs/ftools/BasicStatisticsNumbers.py
  13. +1 −1 python/plugins/sextante/algs/ftools/BasicStatisticsStrings.py
  14. +2 −2 python/plugins/sextante/algs/ftools/Buffer.py
  15. +3 −11 python/plugins/sextante/algs/ftools/ConvexHull.py
  16. +1 −1 python/plugins/sextante/algs/ftools/Dissolve.py
  17. +3 −4 python/plugins/sextante/algs/ftools/ExportGeometryInfo.py
  18. +2 −22 python/plugins/sextante/algs/ftools/ExtentFromLayer.py
  19. +0 −17 python/plugins/sextante/algs/ftools/FToolsUtils.py
  20. +3 −3 python/plugins/sextante/algs/ftools/MeanCoords.py
  21. +4 −4 python/plugins/sextante/algs/ftools/PointDistance.py
  22. +2 −2 python/plugins/sextante/algs/ftools/PointsInPolygon.py
  23. +3 −3 python/plugins/sextante/algs/ftools/PointsInPolygonUnique.py
  24. +7 −5 python/plugins/sextante/algs/ftools/PointsInPolygonWeighted.py
  25. +1 −1 python/plugins/sextante/algs/ftools/RandomSelectionWithinSubsets.py
  26. +1 −1 python/plugins/sextante/algs/ftools/SinglePartsToMultiparts.py
  27. +4 −4 python/plugins/sextante/algs/ftools/SumLines.py
  28. +2 −2 python/plugins/sextante/algs/ftools/UniqueValues.py
  29. +16 −16 python/plugins/sextante/algs/mmqgisx/MMQGISXAlgorithms.py
  30. +2 −2 python/plugins/sextante/core/LayerExporter.py
  31. +3 −3 python/plugins/sextante/core/QGisLayers.py
  32. +2 −6 python/plugins/sextante/core/SextanteTableWriter.py
  33. +1 −1 python/plugins/sextante/core/SextanteVectorWriter.py
  34. +3 −3 python/plugins/sextante/gdal/GdalUtils.py
  35. +1 −2 python/plugins/sextante/gui/AlgorithmExecutor.py
  36. +2 −2 python/plugins/sextante/gui/BatchInputSelectionPanel.py
  37. +4 −4 python/plugins/sextante/gui/BatchOutputSelectionPanel.py
  38. +1 −1 python/plugins/sextante/gui/ConfigDialog.py
  39. +1 −1 python/plugins/sextante/gui/CouldNotLoadResultsDialog.py
  40. +5 −5 python/plugins/sextante/gui/FileSelectionPanel.py
  41. +1 −1 python/plugins/sextante/gui/FixedTableDialog.py
  42. +2 −2 python/plugins/sextante/gui/InputLayerSelectorPanel.py
  43. +1 −1 python/plugins/sextante/gui/MissingDependencyDialog.py
  44. +4 −4 python/plugins/sextante/gui/OutputSelectionPanel.py
  45. +3 −3 python/plugins/sextante/gui/RenderingStyleFilePanel.py
  46. +3 −4 python/plugins/sextante/gui/SextanteToolbox.py
  47. +2 −2 python/plugins/sextante/gui/TestTools.py
  48. +1 −1 python/plugins/sextante/gui/UnthreadedAlgorithmExecutor.py
  49. +1 −1 python/plugins/sextante/modeler/ModelerDialog.py
  50. +1 −1 python/plugins/sextante/modeler/ModelerParametersDialog.py
  51. +1 −1 python/plugins/sextante/outputs/OutputTable.py
  52. +1 −1 python/plugins/sextante/outputs/OutputVector.py
  53. +4 −4 python/plugins/sextante/script/scripts/Number_of_unique_values_in_classes.py
  54. +1 −1 python/plugins/sextante/script/scripts/Split_vector_layer_by_attribute.py
  55. +2 −2 python/plugins/sextante/script/scripts/Summarize.py
  56. +3 −2 python/plugins/sextante/tools/vector.py
@@ -54,11 +54,11 @@ def processAlgorithm(self, progress):
settings = QSettings()
mySettings = "/PostgreSQL/connections/"+ connection
try:
database = settings.value(mySettings+"/database").toString()
username = settings.value(mySettings+"/username").toString()
host = settings.value(mySettings+"/host").toString()
port = int(settings.value(mySettings+"/port").toString())
password = settings.value(mySettings+"/password").toString()
database = settings.value(mySettings+"/database")
username = settings.value(mySettings+"/username")
host = settings.value(mySettings+"/host")
port = settings.value(mySettings+"/port", type = int)
password = settings.value(mySettings+"/password")
except Exception, e:
raise GeoAlgorithmExecutionException("Wrong database connection name: " + connection)

@@ -46,11 +46,11 @@ def processAlgorithm(self, progress):
settings = QSettings()
mySettings = "/PostgreSQL/connections/"+ connection
try:
database = settings.value(mySettings+"/database").toString()
username = settings.value(mySettings+"/username").toString()
host = settings.value(mySettings+"/host").toString()
port = int(settings.value(mySettings+"/port").toString())
password = settings.value(mySettings+"/password").toString()
database = settings.value(mySettings+"/database")
username = settings.value(mySettings+"/username")
host = settings.value(mySettings+"/host")
port = settings.value(mySettings+"/port", type = int)
password = settings.value(mySettings+"/password")
except Exception, e:
raise GeoAlgorithmExecutionException("Wrong database connection name: " + connection)
try:
@@ -89,7 +89,7 @@ def processAlgorithm(self, progress):
inGeom = inFeat.geometry()
outFeat.setGeometry( inGeom )
atMap = inFeat.attributes()
atMap.append(QVariant())
atMap.append(None)
outFeat.setAttributes(atMap)
writer.addFeature( outFeat )
del writer
@@ -59,7 +59,7 @@ def processAlgorithm(self, progress):
inGeom = inFeat.geometry()
outFeat.setGeometry( inGeom )
attrs = inFeat.attributes()
attrs.append(QVariant(nElement))
attrs.append(nElement)
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
del writer
@@ -63,10 +63,10 @@ def processAlgorithm(self, progress):
inGeom = feature.geometry()
outFeat.setGeometry( inGeom )
atMap = feature.attributes()
clazz = atMap[fieldindex].toString()
clazz = atMap[fieldindex]
if clazz not in classes:
classes[clazz] = len(classes.keys())
atMap.append(QVariant(classes[clazz]))
atMap.append(classes[clazz])
outFeat.setAttributes(atMap)
writer.addFeature( outFeat )
del writer
@@ -142,7 +142,7 @@ def processAlgorithm(self, progress):
new_ns['__geom'] = geom

if need_attrs:
pyattrs = [self.Qvar2py(a) for a in attrs]
pyattrs = [a for a in attrs]
new_ns['__attr'] = pyattrs

#clear old result
@@ -161,20 +161,12 @@ def processAlgorithm(self, progress):
#write feature
nElement += 1
outFeat.setGeometry( feat.geometry() )
attrs.append(QVariant(new_ns[self.RESULT_VAR_NAME]))
attrs.append(new_ns[self.RESULT_VAR_NAME])
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)

del writer

def Qvar2py(self,qv):
if qv.type() == 2:
return qv.toInt()[0]
if qv.type() == 10:
return unicode(qv.toString())
if qv.type() == 6:
return qv.toDouble()[0]
return None

def checkParameterValuesBeforeExecuting(self):
##TODO check that formula is correct and fields exist
@@ -91,7 +91,7 @@ def processAlgorithm(self, progress):
expression = formula
k = 0
for attr in attrs:
expression = expression.replace(unicode(fields[k].name()), unicode(attr.toString()))
expression = expression.replace(unicode(fields[k].name()), unicode(attr))
k += 1
try:
result = eval(expression)
@@ -102,7 +102,7 @@ def processAlgorithm(self, progress):
inGeom = inFeat.geometry()
outFeat.setGeometry(inGeom)
attrs = inFeat.attributes()
attrs.append(QVariant(result))
attrs.append(result)
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
del writer
@@ -83,12 +83,12 @@ def processAlgorithm(self, progress):
for inFeat in features:
inGeom = inFeat.geometry()
attrs = inFeat.attributes()
joinValue1 = attrs[joinField1Index].toString()
joinValue1 = attrs[joinField1Index]
features2 = QGisLayers.features(layer2);
for inFeat2 in features2:
## Maybe it should cache this entries...
attrs2 = inFeat2.attributes()
joinValue2 = attrs2[joinField2Index].toString()
joinValue2 = attrs2[joinField2Index]
if joinValue1 == joinValue2:
# create the new feature
outFeat.setGeometry(inGeom)
@@ -58,8 +58,8 @@ def processAlgorithm(self, progress):
progress.setPercentage((nElement*100)/nFeat)
attrs = feature.attributes()
try:
x = float(attrs[xfieldindex].toString())
y = float(attrs[yfieldindex].toString())
x = float(attrs[xfieldindex])
y = float(attrs[yfieldindex])
except:
continue
pt = QgsPoint(x, y)
@@ -80,7 +80,7 @@ def processAlgorithm(self, progress):
for polygon in polygons:
outFeat.setGeometry(QgsGeometry.fromWkt( polygon.wkt ))
if self.getParameterValue(self.GEOMETRY):
outFeat.setAttributes([None]*fieldsCount + [ QVariant(polygon.area), QVariant(polygon.length)])
outFeat.setAttributes([None]*fieldsCount + [ polygon.area, polygon.length])
writer.addFeature(outFeat)
current += 1
progress.setPercentage(50+int(current * total))
@@ -69,8 +69,8 @@ def processAlgorithm(self, progress):
progress.setPercentage(int((100 * nFeats) / nFeat))
attrs = feat.attributes()
try:
value = float(attrs[valuesField].toDouble()[0])
cat = unicode(attrs[categoriesField].toString())
value = float(attrs[valuesField])
cat = unicode(attrs[categoriesField])
if cat not in values:
values[cat] = []
values[cat].append(value)
@@ -108,7 +108,7 @@ def calculateStats(values):
maxvalue = max(v, maxvalue)

if n > 1:
variance = M2/(n - 1)
variance = M2/(n - 1)
else:
variance = 0;
stddev = math.sqrt(variance)
@@ -108,7 +108,7 @@ def processAlgorithm(self, progress):
total = 100.0 / float(count)
current = 0
for ft in features:
value = float(ft.attributes()[index].toDouble()[0])
value = float(ft.attributes()[index])
if isFirst:
minValue = value
maxValue = value
@@ -100,7 +100,7 @@ def processAlgorithm(self, progress):
total = 100.0 / float(count)
current = 0
for ft in features:
length = float(len(ft.attributes()[index].toString()))
length = float(len(ft.attributes()[index]))

if isFirst:
minValue = length
@@ -53,7 +53,7 @@ def buffering(progress, writer, distance, field, useField, layer, dissolve, segm
for inFeat in features:
attrs = inFeat.attributes()
if useField:
value = attrs[field].toDouble()[0]
value = attrs[field]
else:
value = distance

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

@@ -115,7 +115,7 @@ def processAlgorithm(self, progress):
features = QGisLayers.features(layer)
for f in features:
idVar = f[fieldName]
if idVar.toString().trimmed() == i.toString().trimmed():
if unicode(idVar).strip() == unicode(i).strip:
if first:
val = idVar
first = False
@@ -131,11 +131,7 @@ def processAlgorithm(self, progress):
outGeom = tmpGeom.convexHull()
(area, perim) = utils.simpleMeasure(outGeom)
outFeat.setGeometry(outGeom)
outFeat.setAttributes([QVariant(fid),
QVariant(val),
QVariant(area),
QVariant(perim)
])
outFeat.setAttributes([fid,val,area,perim])
writer.addFeature(outFeat)
except:
GEOS_EXCEPT = False
@@ -157,11 +153,7 @@ def processAlgorithm(self, progress):
outGeom = tmpGeom.convexHull()
(area, perim) = utils.simpleMeasure(outGeom)
outFeat.setGeometry(outGeom)
outFeat.setAttributes([QVariant(0),
QVariant("all"),
QVariant(area),
QVariant(perim)
])
outFeat.setAttributes([0, "all", area, perim])
writer.addFeature(outFeat)
except:
GEOS_EXCEPT = False
@@ -92,7 +92,7 @@ def processAlgorithm(self, progress):
progress.setPercentage(int(nElement/nFeat * 100))
atMap = inFeat.attributes()
tempItem = atMap[ field ]
if tempItem.toString().trimmed() == item.toString().trimmed():
if tempItem.strip() == item.strip():
if first:
QgsGeometry( inFeat.geometry() )
tmpInGeom = QgsGeometry( inFeat.geometry() )
@@ -95,8 +95,7 @@ def processAlgorithm(self, progress):
# 0 - layer CRS
# 1 - project CRS
# 2 - ellipsoidal
if method == 2:
settings = QSettings()
if method == 2:
ellips = QgsProject.instance().readEntry("Measure", "/Ellipsoid", GEO_NONE)[0]
crs = layer.crs().srsid()
elif method == 1:
@@ -123,9 +122,9 @@ def processAlgorithm(self, progress):

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

@@ -104,17 +104,7 @@ def layerExtent(self, layer, writer, progress):
geometry = QgsGeometry().fromPolygon([rect])
feat = QgsFeature()
feat.setGeometry(geometry)
attrs = [QVariant(minx),
QVariant(miny),
QVariant(maxx),
QVariant(maxy),
QVariant(cntx),
QVariant(cnty),
QVariant(area),
QVariant(perim),
QVariant(height),
QVariant(width)
]
attrs = [minx,miny,maxx,maxy,cntx,cnty,area,perim,height,width]
feat.setAttributes(attrs)
writer.addFeature(feat)

@@ -144,17 +134,7 @@ def featureExtent(self, layer, writer, progress):

geometry = QgsGeometry().fromPolygon([rect])
feat.setGeometry(geometry)
attrs = [QVariant(minx),
QVariant(miny),
QVariant(maxx),
QVariant(maxy),
QVariant(cntx),
QVariant(cnty),
QVariant(area),
QVariant(perim),
QVariant(height),
QVariant(width)
]
attrs = [minx,miny,maxx,maxy,cntx,cnty,area,perim,height,width]
feat.setAttributes(attrs)

writer.addFeature(feat)
@@ -158,20 +158,3 @@ def combineVectorFields(layerA, layerB):

return fields

# Create a unique field name based on input field name
def createUniqueFieldNameFromName(field):
check = field.name().right(2)
shortName = field.name().left(8)
if check.startsWith("_"):
(val, test) = check.right(1).toInt()
if test:
if val < 2:
val = 2
else:
val = val + 1
field.setName(shortName.left(len(shortName) - 1) + unicode(val))
else:
field.setName(shortName + "_2")
else:
field.setName(shortName + "_2")
return field
@@ -79,12 +79,12 @@ def processAlgorithm(self, progress):
for feat in features:
current += 1
progress.setPercentage(current * total)
clazz = feat.attributes()[uniqueIndex].toString().trimmed()
clazz = feat.attributes()[uniqueIndex].strip()
if weightIndex == -1:
weight = 1.00
else:
try:
weight = float(feat.attributes()[weightIndex].toDouble()[0])
weight = float(feat.attributes()[weightIndex])
except:
weight = 1.00
if clazz not in means:
@@ -106,7 +106,7 @@ def processAlgorithm(self, progress):
meanPoint = QgsPoint(cx, cy)

outFeat.setGeometry(QgsGeometry.fromPoint(meanPoint))
outFeat.setAttributes([QVariant(cx), QVariant(cy), clazz])
outFeat.setAttributes([cx, cy, clazz])
writer.addFeature(outFeat)


@@ -124,14 +124,14 @@ def linearMatrix(self, inLayer, inField, targetLayer, targetField, matType, nPoi
total = 100.0 / float(len(features))
for inFeat in features:
inGeom = inFeat.geometry()
inID = inFeat.attributes()[inIdx].toString()
inID = inFeat.attributes()[inIdx]
featList = index.nearestNeighbor(inGeom.asPoint(), nPoints)
distList = []
vari = 0.0
for i in featList:
request = QgsFeatureRequest().setFilterFid(i)
outFeat = targetLayer.getFeatures(request).next()
outID = outFeat.attributes()[outIdx].toString()
outID = outFeat.attributes()[outIdx]
outGeom = outFeat.geometry()
dist = distArea.measureLine(inGeom.asPoint(), outGeom.asPoint())
if matType == 0:
@@ -167,15 +167,15 @@ def regularMatrix(self, inLayer, inField, targetLayer, targetField, nPoints, pro

for inFeat in features:
inGeom = inFeat.geometry()
inID = inFeat.attributes()[inIdx].toString()
inID = inFeat.attributes()[inIdx]
if first:
featList = index.nearestNeighbor(inGeom.asPoint(), nPoints)
first = False
data = ["ID"]
for i in featList:
request = QgsFeatureRequest().setFilterFid(i)
outFeat = targetLayer.getFeatures(request).next()
data.append(unicode(outFeat.attributes[outIdx].toString()))
data.append(unicode(outFeat.attributes[outIdx]))
self.writer.writerow(data)

data = [unicode(inID)]

0 comments on commit 63cc02d

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