Skip to content

Commit d3d5182

Browse files
committed
more api updates in fTools (still incomplete)
1 parent 979a11e commit d3d5182

17 files changed

+93
-95
lines changed

python/plugins/fTools/tools/doDefineProj.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#
2929
#---------------------------------------------------------------------
3030

31+
import re
32+
3133
from PyQt4.QtCore import *
3234
from PyQt4.QtGui import *
3335

@@ -50,14 +52,14 @@ def __init__(self, iface):
5052
self.setWindowTitle(self.tr("Define current projection"))
5153
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
5254
QObject.connect(self.btnProjection, SIGNAL("clicked()"), self.outProjFile)
53-
#QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.updateProj1)
54-
#QObject.connect(self.cmbLayer, SIGNAL("currentIndexChanged(QString)"), self.updateProj2)
55+
QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.updateProj1)
56+
QObject.connect(self.cmbLayer, SIGNAL("currentIndexChanged(QString)"), self.updateProj2)
5557
# populate layer list
5658
self.progressBar.setValue(0)
5759
mapCanvas = self.iface.mapCanvas()
5860
layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon])
59-
#self.inShape.addItems(layers)
60-
#self.cmbLayer.addItems(layers)
61+
self.inShape.addItems(layers)
62+
self.cmbLayer.addItems(layers)
6163

6264
self.crs = None
6365

@@ -105,20 +107,23 @@ def accept(self):
105107
srsDefine = destLayer.crs()
106108
if srsDefine == vLayer.crs():
107109
responce = QMessageBox.question(self, self.tr("Define current projection"),
108-
self.tr("Identical output spatial reference system chosen\n\nAre you sure you want to proceed?"),
109-
QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
110+
self.tr("Identical output spatial reference system chosen\n\nAre you sure you want to proceed?"),
111+
QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
110112
if responce == QMessageBox.No:
111113
self.progressBar.setValue(0)
112114
self.buttonOk.setEnabled( True )
113115
return
114116
provider = vLayer.dataProvider()
115117
self.progressBar.setValue(35)
116118
inPath = provider.dataSourceUri()
117-
inPath = inPath.remove( QRegExp( "\|.*" ) )
119+
p = re.compile("\|.*")
120+
inPath = p.sub("", inPath)
121+
print "PATH", inPath
118122
self.progressBar.setValue(40)
119-
if inPath.endsWith(".shp"):
120-
inPath = inPath.left(inPath.length() - 4)
123+
if inPath.endswith(".shp"):
124+
inPath = inPath[:-4]
121125
self.progressBar.setValue(55)
126+
print "PATH2", inPath
122127
if not srsDefine.isValid():
123128
QMessageBox.information(self, self.tr("Define current projection"), self.tr("Output spatial reference system is not valid"))
124129
else:
@@ -142,20 +147,22 @@ def accept(self):
142147
self.progressBar.setValue(95)
143148
vLayer.setCrs(srsDefine)
144149
self.progressBar.setValue(100)
145-
QMessageBox.information(self, self.tr("Define current projection"), self.tr("Defined Projection For:\n%1.shp").arg( inPath ) )
150+
print "PATH3", inPath
151+
QMessageBox.information(self, self.tr("Define current projection"),
152+
self.tr("Defined Projection For:\n%s.shp") % (inPath) )
146153
self.progressBar.setValue(0)
147154
self.buttonOk.setEnabled( True )
148155

149156
def outProjFile(self):
150-
format = "<h2>%1</h2>%2 <br/> %3"
151157
header = "Define layer CRS:"
152158
sentence1 = self.tr( "Please select the projection system that defines the current layer." )
153159
sentence2 = self.tr( "Layer CRS information will be updated to the selected CRS." )
154160
projSelector = QgsGenericProjectionSelector(self)
155-
projSelector.setMessage( format.arg( header ).arg( sentence1 ).arg( sentence2 ))
161+
projSelector.setMessage( "<h2>%s</h2>%s <br/> %s" % (header, sentence1, sentence2) )
156162
if projSelector.exec_():
157163
self.crs = QgsCoordinateReferenceSystem( projSelector.selectedCrsId(), QgsCoordinateReferenceSystem.InternalCrsId )
158-
if projSelector.selectedAuthId().isEmpty():
164+
print "AUTHID", projSelector.selectedAuthId()
165+
if len(projSelector.selectedAuthId()) == 0:
159166
QMessageBox.information(self, self.tr("Export to new projection"), self.tr("No Valid CRS selected"))
160167
return
161168
else:

python/plugins/fTools/tools/doEliminate.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(self, iface):
5555
def update(self, inputLayer):
5656
changedLayer = ftools_utils.getVectorLayerByName(inputLayer)
5757
selFeatures = changedLayer.selectedFeatureCount()
58-
self.selected.setText( self.tr("Selected features: %1").arg(selFeatures))
58+
self.selected.setText( self.tr("Selected features: %s") % (selFeatures))
5959

6060
def accept(self):
6161
self.buttonOk.setEnabled(False)
@@ -75,7 +75,7 @@ def accept(self):
7575
if outFile.exists():
7676
if not QgsVectorFileWriter.deleteShapeFile(outFileName):
7777
QtGui.QMessageBox.warning(self, self.tr("Delete error"),
78-
self.tr("Can't delete file %1").arg(outFileName))
78+
self.tr("Can't delete file %s") % (outFileName))
7979
self.buttonOk.setEnabled(True)
8080
return None
8181

@@ -109,7 +109,7 @@ def saveChanges(self, outLayer):
109109
msg = ""
110110
for aStrm in outLayer.commitErrors():
111111
msg = msg + "\n" + aStrm
112-
QtGui.QMessageBox.warning(self, self.tr("Eliminate"), self.tr("Commit error:\n %1").arg(msg))
112+
QtGui.QMessageBox.warning(self, self.tr("Eliminate"), self.tr("Commit error:\n%s") % (msg))
113113
outLayer.rollBack()
114114
return False
115115

@@ -203,7 +203,7 @@ def eliminate(self, inLayer, boundary, progressBar, outFileName):
203203
fidsToDeselect.append(fid2Eliminate)
204204
else:
205205
QtGui.QMessageBox.warning(self, self.tr("Eliminate"),
206-
self.tr("Could not replace geometry of feature with id %1").arg( mergeWithFid ))
206+
self.tr("Could not replace geometry of feature with id %s") % (mergeWithFid))
207207
return None
208208

209209
start = start + add
@@ -219,16 +219,16 @@ def eliminate(self, inLayer, boundary, progressBar, outFileName):
219219
# copy all features that could not be eliminated to outLayer
220220
if outLayer.addFeatures(inLayer.selectedFeatures()):
221221
# inform user
222-
fidList = QtCore.QString()
222+
fidList = ""
223223

224224
for fid in inLayer.selectedFeaturesIds():
225-
if not fidList.isEmpty():
226-
fidList.append(", ")
225+
if not fidList == "":
226+
fidList += ", "
227227

228-
fidList.append(str(fid))
228+
fidList += str(fid)
229229

230230
QtGui.QMessageBox.information(self, self.tr("Eliminate"),
231-
self.tr("Could not eliminate features with these ids:\n%1").arg(fidList))
231+
self.tr("Could not eliminate features with these ids:\n%s") %s (fidList))
232232
else:
233233
QtGui.QMessageBox.warning(self, self.tr("Eliminate"), self.tr("Could not add features"))
234234

@@ -241,6 +241,6 @@ def eliminate(self, inLayer, boundary, progressBar, outFileName):
241241
ftools_utils.addShapeToCanvas(outFileName)
242242
else:
243243
QtGui.QMessageBox.information(self, self.tr("Eliminate"),
244-
self.tr("Created output shapefile:\n%1").arg(outFileName))
244+
self.tr("Created output shapefile:\n%s") %s (outFileName))
245245

246246
self.iface.mapCanvas().refresh()

python/plugins/fTools/tools/doGeoprocessing.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ def runFinishedFromThread( self, results ):
241241
out_text = ""
242242
if results[3] is not None:
243243
QMessageBox.warning( self, self.tr( "Geoprocessing" ),
244-
self.tr( "No output created. File creation error:\n%1" )
245-
.arg( results[3] ) )
244+
self.tr( "No output created. File creation error:\n%s" ) % ( results[3] ) )
246245
return
247246
if (not results[2] is None and not results[2]) or not results[1] or not results [0]:
248247
out_text = self.tr( "\nWarnings:" )
@@ -259,10 +258,10 @@ def runFinishedFromThread( self, results ):
259258
out_text = out_text + self.tr( "\nFeature geometry error: One or more output features ignored due to invalid geometry.")
260259
if not results[0]:
261260
out_text = out_text + self.tr( "\nGEOS geoprocessing error: One or more input features have invalid geometry.")
262-
addToTOC = QMessageBox.question( self, self.tr("Geoprocessing"), self.tr( "Created output shapefile:\n%1\n%2%3" ).arg( unicode( self.shapefileName ) ).arg( out_text ).arg( end_text ), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton )
261+
addToTOC = QMessageBox.question( self, self.tr("Geoprocessing"), self.tr( "Created output shapefile:\n%s\n%s%s" ) % ( unicode( self.shapefileName ), out_text, end_text ), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton )
263262
if addToTOC == QMessageBox.Yes:
264263
if not ftools_utils.addShapeToCanvas( unicode( self.shapefileName ) ):
265-
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( self.shapefileName ) ))
264+
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%s" ) % ( unicode( self.shapefileName ) ))
266265
self.populateLayers()
267266

268267
def runStatusFromThread( self, status ):
@@ -378,7 +377,7 @@ def buffering( self, useField ):
378377
for inFeat in selectionA:
379378
atMap = inFeat.attributes()
380379
if useField:
381-
value = atMap[ self.myParam ].toDouble()[ 0 ]
380+
value = atMap[ self.myParam ]
382381
else:
383382
value = self.myParam
384383
inGeom = QgsGeometry( inFeat.geometry() )
@@ -404,11 +403,11 @@ def buffering( self, useField ):
404403
# with dissolve
405404
if self.myMerge:
406405
first = True
407-
fit = vproviderA.getFeatures()
406+
fit = vproviderA.getFeatures()
408407
while fit.nextFeature( inFeat ):
409408
atMap = inFeat.attributes()
410409
if useField:
411-
value = atMap[ self.myParam ].toDouble()[ 0 ]
410+
value = atMap[ self.myParam ]
412411
else:
413412
value = self.myParam
414413
inGeom = QgsGeometry( inFeat.geometry() )
@@ -435,11 +434,11 @@ def buffering( self, useField ):
435434
FEATURE_EXCEPT = False
436435
# without dissolve
437436
else:
438-
fit = vproviderA.getFeatures()
437+
fit = vproviderA.getFeatures()
439438
while fit.nextFeature( inFeat ):
440439
atMap = inFeat.attributes()
441440
if useField:
442-
value = atMap[ self.myParam ].toDouble()[ 0 ]
441+
value = atMap[ self.myParam ]
443442
else:
444443
value = self.myParam
445444
inGeom = QgsGeometry( inFeat.geometry() )
@@ -574,7 +573,7 @@ def convex_hull(self, useField ):
574573
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
575574
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
576575
hull = []
577-
fitA = vproviderA.getFeatures()
576+
fitA = vproviderA.getFeatures()
578577
while fitA.nextFeature( inFeat ):
579578
inGeom = QgsGeometry( inFeat.geometry() )
580579
points = ftools_utils.extractPoints( inGeom )
@@ -644,7 +643,7 @@ def dissolve( self, useField ):
644643
nElement += 1
645644
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
646645
atMap = inFeat.attributes()
647-
tempItem = unicode(atMap[self.myParam].toString().trimmed())
646+
tempItem = unicode(atMap[self.myParam]).strip()
648647

649648
if not (tempItem in outFeats):
650649
outFeats[tempItem] = QgsGeometry(inFeat.geometry())
@@ -699,7 +698,7 @@ def dissolve( self, useField ):
699698
nElement += 1
700699
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
701700
atMap = inFeat.attributes()
702-
tempItem = unicode(atMap[self.myParam].toString().trimmed())
701+
tempItem = unicode(atMap[self.myParam]).strip()
703702

704703
if not (tempItem in outFeats):
705704
outFeats[tempItem] = QgsGeometry(inFeat.geometry())
@@ -817,7 +816,7 @@ def difference( self ):
817816
# we have selection in overlay layer
818817
if self.mySelectionB:
819818
selectionB = self.vlayerB.selectedFeaturesIds()
820-
fitA = vproviderA.getFeatures()
819+
fitA = vproviderA.getFeatures()
821820
while fitA.nextFeature( inFeatA ):
822821
nElement += 1
823822
add = True
@@ -894,7 +893,7 @@ def intersect( self ):
894893
fields = ftools_utils.combineVectorFields( self.vlayerA, self.vlayerB )
895894
longNames = ftools_utils.checkFieldNameLength( fields )
896895
if not longNames.isEmpty():
897-
message = QString( 'Following field names are longer than 10 characters:\n%1' ).arg( longNames.join( '\n' ) )
896+
message = QString( 'Following field names are longer than 10 characters:\n%s' ) % ( '\n'.join(longNames) )
898897
return GEOS_EXCEPT, FEATURE_EXCEPT, crs_match, message
899898

900899
writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields,
@@ -993,7 +992,7 @@ def intersect( self ):
993992
# we have selection in overlay layer
994993
if self.mySelectionB:
995994
selectionB = self.vlayerB.selectedFeaturesIds()
996-
fitA = vproviderA.getFeatures()
995+
fitA = vproviderA.getFeatures()
997996
while fitA.nextFeature( inFeatA ):
998997
nElement += 1
999998
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
@@ -1079,7 +1078,7 @@ def union( self ):
10791078
fields = ftools_utils.combineVectorFields( self.vlayerA, self.vlayerB )
10801079
longNames = ftools_utils.checkFieldNameLength( fields )
10811080
if not longNames.isEmpty():
1082-
message = QString( 'Following field names are longer than 10 characters:\n%1' ).arg( longNames.join( '\n' ) )
1081+
message = QString( 'Following field names are longer than 10 characters:\n%s' ) % ( "\n".join(longNames) )
10831082
return GEOS_EXCEPT, FEATURE_EXCEPT, crs_match, message
10841083

10851084
writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields,
@@ -1265,7 +1264,7 @@ def symetrical_difference( self ):
12651264
fields = ftools_utils.combineVectorFields( self.vlayerA, self.vlayerB )
12661265
longNames = ftools_utils.checkFieldNameLength( fields )
12671266
if not longNames.isEmpty():
1268-
message = QString( 'Following field names are longer than 10 characters:\n%1' ).arg( longNames.join( '\n' ) )
1267+
message = QString( 'Following field names are longer than 10 characters:\n%s' ) % ( "\n".join(longNames) )
12691268
return GEOS_EXCEPT, FEATURE_EXCEPT, crs_match, message
12701269

12711270
writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields,

python/plugins/fTools/tools/doIntersectLines.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ def accept(self):
9595
self.outShape.clear()
9696
self.compute(line1, line2, field1, field2, outPath, self.progressBar)
9797
self.progressBar.setValue(100)
98-
addToTOC = QMessageBox.question(self, self.tr("Generate Centroids"), self.tr("Created output point shapefile:\n%1\n\nWould you like to add the new layer to the TOC?").arg( outPath ), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
98+
addToTOC = QMessageBox.question(self, self.tr("Generate Centroids"), self.tr("Created output point shapefile:\n%s\n\nWould you like to add the new layer to the TOC?") % ( outPath ), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
9999
if addToTOC == QMessageBox.Yes:
100100
if not ftools_utils.addShapeToCanvas( unicode( outPath ) ):
101-
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( outPath ) ))
101+
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%s" ) % ( unicode( outPath ) ))
102102
self.populateLayers()
103103
self.progressBar.setValue(0)
104104
self.buttonOk.setEnabled( True )
@@ -144,7 +144,7 @@ def compute(self, line1, line2, field1, field2, outPath, progressBar):
144144

145145
index = ftools_utils.createIndex( provider2 )
146146

147-
fit1 = vprovider.getFeatures( QgsFeatureRequest().setSubsetOfAttributes([index1]) )
147+
fit1 = vprovider.getFeatures( QgsFeatureRequest().setSubsetOfAttributes([index1]) )
148148
while fit1.nextFeature(inFeat):
149149
inGeom = inFeat.geometry()
150150
v1 = inFeat.attributes()[index1]

python/plugins/fTools/tools/doMeanCoords.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def accept(self):
9595
self.compute(inName, outPath, self.weightField.currentText(), self.sizeValue.value(), self.uniqueField.currentText())
9696
self.progressBar.setValue(100)
9797
self.outShape.clear()
98-
addToTOC = QMessageBox.question(self, self.tr("Coordinate statistics"), self.tr("Created output point shapefile:\n%1\n\nWould you like to add the new layer to the TOC?").arg( outPath ), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
98+
addToTOC = QMessageBox.question(self, self.tr("Coordinate statistics"), self.tr("Created output point shapefile:\n%s\n\nWould you like to add the new layer to the TOC?") % ( outPath ), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
9999
if addToTOC == QMessageBox.Yes:
100100
vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
101101
QgsMapLayerRegistry.instance().addMapLayers([vlayer])
@@ -150,12 +150,12 @@ def compute(self, inName, outName, weightField="", times=1, uniqueField=""):
150150
cy = 0.00
151151
points = []
152152
weights = []
153-
fit = provider.getFeatures()
153+
fit = provider.getFeatures()
154154
while fit.nextFeature(feat):
155155
nElement += 1
156156
self.progressBar.setValue(nElement)
157157
if single:
158-
check = j.toString().trimmed()
158+
check = j.strip()
159159
else:
160160
check = feat.attributes()[uniqueIndex].toString().trimmed()
161161
if check == j.toString().trimmed():
@@ -164,7 +164,7 @@ def compute(self, inName, outName, weightField="", times=1, uniqueField=""):
164164
if weightIndex == -1:
165165
weight = 1.00
166166
else:
167-
weight = float(feat.attributes()[weightIndex].toDouble()[0])
167+
weight = float(feat.attributes()[weightIndex]
168168
geom = QgsGeometry(feat.geometry())
169169
geom = ftools_utils.extractPoints(geom)
170170
for i in geom:

0 commit comments

Comments
 (0)