Skip to content

Commit

Permalink
Merge pull request #629 from volaya/sipapi
Browse files Browse the repository at this point in the history
[sextante] updated to new sip api
  • Loading branch information
NathanW2 committed Jun 3, 2013
2 parents 75cbdf6 + e46795a commit 63cc02d
Show file tree
Hide file tree
Showing 56 changed files with 138 additions and 195 deletions.
10 changes: 5 additions & 5 deletions python/plugins/sextante/admintools/ImportIntoPostGIS.py
Expand Up @@ -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)

Expand Down
10 changes: 5 additions & 5 deletions python/plugins/sextante/admintools/PostGISExecuteSQL.py
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/algs/AddTableField.py
Expand Up @@ -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
2 changes: 1 addition & 1 deletion python/plugins/sextante/algs/AutoincrementalField.py
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/sextante/algs/EquivalentNumField.py
Expand Up @@ -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
Expand Down
12 changes: 2 additions & 10 deletions python/plugins/sextante/algs/FieldPyculator.py
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/sextante/algs/FieldsCalculator.py
Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/sextante/algs/JoinAttributes.py
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/sextante/algs/PointsLayerFromTable.py
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/algs/Polygonize.py
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/sextante/algs/StatisticsByCategories.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/sextante/algs/ftools/Buffer.py
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
14 changes: 3 additions & 11 deletions python/plugins/sextante/algs/ftools/ConvexHull.py
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/algs/ftools/Dissolve.py
Expand Up @@ -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() )
Expand Down
7 changes: 3 additions & 4 deletions python/plugins/sextante/algs/ftools/ExportGeometryInfo.py
Expand Up @@ -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:
Expand All @@ -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)

Expand Down
24 changes: 2 additions & 22 deletions python/plugins/sextante/algs/ftools/ExtentFromLayer.py
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
17 changes: 0 additions & 17 deletions python/plugins/sextante/algs/ftools/FToolsUtils.py
Expand Up @@ -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
6 changes: 3 additions & 3 deletions python/plugins/sextante/algs/ftools/MeanCoords.py
Expand Up @@ -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:
Expand All @@ -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)


Expand Down
8 changes: 4 additions & 4 deletions python/plugins/sextante/algs/ftools/PointDistance.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit 63cc02d

Please sign in to comment.