Skip to content

Commit

Permalink
more api updates in fTools (still incomplete)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed May 31, 2013
1 parent 979a11e commit d3d5182
Show file tree
Hide file tree
Showing 17 changed files with 93 additions and 95 deletions.
33 changes: 20 additions & 13 deletions python/plugins/fTools/tools/doDefineProj.py
Expand Up @@ -28,6 +28,8 @@
#
#---------------------------------------------------------------------

import re

from PyQt4.QtCore import *
from PyQt4.QtGui import *

Expand All @@ -50,14 +52,14 @@ def __init__(self, iface):
self.setWindowTitle(self.tr("Define current projection"))
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
QObject.connect(self.btnProjection, SIGNAL("clicked()"), self.outProjFile)
#QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.updateProj1)
#QObject.connect(self.cmbLayer, SIGNAL("currentIndexChanged(QString)"), self.updateProj2)
QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.updateProj1)
QObject.connect(self.cmbLayer, SIGNAL("currentIndexChanged(QString)"), self.updateProj2)
# populate layer list
self.progressBar.setValue(0)
mapCanvas = self.iface.mapCanvas()
layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon])
#self.inShape.addItems(layers)
#self.cmbLayer.addItems(layers)
self.inShape.addItems(layers)
self.cmbLayer.addItems(layers)

self.crs = None

Expand Down Expand Up @@ -105,20 +107,23 @@ def accept(self):
srsDefine = destLayer.crs()
if srsDefine == vLayer.crs():
responce = QMessageBox.question(self, self.tr("Define current projection"),
self.tr("Identical output spatial reference system chosen\n\nAre you sure you want to proceed?"),
QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
self.tr("Identical output spatial reference system chosen\n\nAre you sure you want to proceed?"),
QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
if responce == QMessageBox.No:
self.progressBar.setValue(0)
self.buttonOk.setEnabled( True )
return
provider = vLayer.dataProvider()
self.progressBar.setValue(35)
inPath = provider.dataSourceUri()
inPath = inPath.remove( QRegExp( "\|.*" ) )
p = re.compile("\|.*")
inPath = p.sub("", inPath)
print "PATH", inPath
self.progressBar.setValue(40)
if inPath.endsWith(".shp"):
inPath = inPath.left(inPath.length() - 4)
if inPath.endswith(".shp"):
inPath = inPath[:-4]
self.progressBar.setValue(55)
print "PATH2", inPath
if not srsDefine.isValid():
QMessageBox.information(self, self.tr("Define current projection"), self.tr("Output spatial reference system is not valid"))
else:
Expand All @@ -142,20 +147,22 @@ def accept(self):
self.progressBar.setValue(95)
vLayer.setCrs(srsDefine)
self.progressBar.setValue(100)
QMessageBox.information(self, self.tr("Define current projection"), self.tr("Defined Projection For:\n%1.shp").arg( inPath ) )
print "PATH3", inPath
QMessageBox.information(self, self.tr("Define current projection"),
self.tr("Defined Projection For:\n%s.shp") % (inPath) )
self.progressBar.setValue(0)
self.buttonOk.setEnabled( True )

def outProjFile(self):
format = "<h2>%1</h2>%2 <br/> %3"
header = "Define layer CRS:"
sentence1 = self.tr( "Please select the projection system that defines the current layer." )
sentence2 = self.tr( "Layer CRS information will be updated to the selected CRS." )
projSelector = QgsGenericProjectionSelector(self)
projSelector.setMessage( format.arg( header ).arg( sentence1 ).arg( sentence2 ))
projSelector.setMessage( "<h2>%s</h2>%s <br/> %s" % (header, sentence1, sentence2) )
if projSelector.exec_():
self.crs = QgsCoordinateReferenceSystem( projSelector.selectedCrsId(), QgsCoordinateReferenceSystem.InternalCrsId )
if projSelector.selectedAuthId().isEmpty():
print "AUTHID", projSelector.selectedAuthId()
if len(projSelector.selectedAuthId()) == 0:
QMessageBox.information(self, self.tr("Export to new projection"), self.tr("No Valid CRS selected"))
return
else:
Expand Down
20 changes: 10 additions & 10 deletions python/plugins/fTools/tools/doEliminate.py
Expand Up @@ -55,7 +55,7 @@ def __init__(self, iface):
def update(self, inputLayer):
changedLayer = ftools_utils.getVectorLayerByName(inputLayer)
selFeatures = changedLayer.selectedFeatureCount()
self.selected.setText( self.tr("Selected features: %1").arg(selFeatures))
self.selected.setText( self.tr("Selected features: %s") % (selFeatures))

def accept(self):
self.buttonOk.setEnabled(False)
Expand All @@ -75,7 +75,7 @@ def accept(self):
if outFile.exists():
if not QgsVectorFileWriter.deleteShapeFile(outFileName):
QtGui.QMessageBox.warning(self, self.tr("Delete error"),
self.tr("Can't delete file %1").arg(outFileName))
self.tr("Can't delete file %s") % (outFileName))
self.buttonOk.setEnabled(True)
return None

Expand Down Expand Up @@ -109,7 +109,7 @@ def saveChanges(self, outLayer):
msg = ""
for aStrm in outLayer.commitErrors():
msg = msg + "\n" + aStrm
QtGui.QMessageBox.warning(self, self.tr("Eliminate"), self.tr("Commit error:\n %1").arg(msg))
QtGui.QMessageBox.warning(self, self.tr("Eliminate"), self.tr("Commit error:\n%s") % (msg))
outLayer.rollBack()
return False

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

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

for fid in inLayer.selectedFeaturesIds():
if not fidList.isEmpty():
fidList.append(", ")
if not fidList == "":
fidList += ", "

fidList.append(str(fid))
fidList += str(fid)

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

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

self.iface.mapCanvas().refresh()
33 changes: 16 additions & 17 deletions python/plugins/fTools/tools/doGeoprocessing.py
Expand Up @@ -241,8 +241,7 @@ def runFinishedFromThread( self, results ):
out_text = ""
if results[3] is not None:
QMessageBox.warning( self, self.tr( "Geoprocessing" ),
self.tr( "No output created. File creation error:\n%1" )
.arg( results[3] ) )
self.tr( "No output created. File creation error:\n%s" ) % ( results[3] ) )
return
if (not results[2] is None and not results[2]) or not results[1] or not results [0]:
out_text = self.tr( "\nWarnings:" )
Expand All @@ -259,10 +258,10 @@ def runFinishedFromThread( self, results ):
out_text = out_text + self.tr( "\nFeature geometry error: One or more output features ignored due to invalid geometry.")
if not results[0]:
out_text = out_text + self.tr( "\nGEOS geoprocessing error: One or more input features have invalid geometry.")
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 )
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 )
if addToTOC == QMessageBox.Yes:
if not ftools_utils.addShapeToCanvas( unicode( self.shapefileName ) ):
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( self.shapefileName ) ))
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%s" ) % ( unicode( self.shapefileName ) ))
self.populateLayers()

def runStatusFromThread( self, status ):
Expand Down Expand Up @@ -378,7 +377,7 @@ def buffering( self, useField ):
for inFeat in selectionA:
atMap = inFeat.attributes()
if useField:
value = atMap[ self.myParam ].toDouble()[ 0 ]
value = atMap[ self.myParam ]
else:
value = self.myParam
inGeom = QgsGeometry( inFeat.geometry() )
Expand All @@ -404,11 +403,11 @@ def buffering( self, useField ):
# with dissolve
if self.myMerge:
first = True
fit = vproviderA.getFeatures()
fit = vproviderA.getFeatures()
while fit.nextFeature( inFeat ):
atMap = inFeat.attributes()
if useField:
value = atMap[ self.myParam ].toDouble()[ 0 ]
value = atMap[ self.myParam ]
else:
value = self.myParam
inGeom = QgsGeometry( inFeat.geometry() )
Expand All @@ -435,11 +434,11 @@ def buffering( self, useField ):
FEATURE_EXCEPT = False
# without dissolve
else:
fit = vproviderA.getFeatures()
fit = vproviderA.getFeatures()
while fit.nextFeature( inFeat ):
atMap = inFeat.attributes()
if useField:
value = atMap[ self.myParam ].toDouble()[ 0 ]
value = atMap[ self.myParam ]
else:
value = self.myParam
inGeom = QgsGeometry( inFeat.geometry() )
Expand Down Expand Up @@ -574,7 +573,7 @@ def convex_hull(self, useField ):
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
hull = []
fitA = vproviderA.getFeatures()
fitA = vproviderA.getFeatures()
while fitA.nextFeature( inFeat ):
inGeom = QgsGeometry( inFeat.geometry() )
points = ftools_utils.extractPoints( inGeom )
Expand Down Expand Up @@ -644,7 +643,7 @@ def dissolve( self, useField ):
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
atMap = inFeat.attributes()
tempItem = unicode(atMap[self.myParam].toString().trimmed())
tempItem = unicode(atMap[self.myParam]).strip()

if not (tempItem in outFeats):
outFeats[tempItem] = QgsGeometry(inFeat.geometry())
Expand Down Expand Up @@ -699,7 +698,7 @@ def dissolve( self, useField ):
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
atMap = inFeat.attributes()
tempItem = unicode(atMap[self.myParam].toString().trimmed())
tempItem = unicode(atMap[self.myParam]).strip()

if not (tempItem in outFeats):
outFeats[tempItem] = QgsGeometry(inFeat.geometry())
Expand Down Expand Up @@ -817,7 +816,7 @@ def difference( self ):
# we have selection in overlay layer
if self.mySelectionB:
selectionB = self.vlayerB.selectedFeaturesIds()
fitA = vproviderA.getFeatures()
fitA = vproviderA.getFeatures()
while fitA.nextFeature( inFeatA ):
nElement += 1
add = True
Expand Down Expand Up @@ -894,7 +893,7 @@ def intersect( self ):
fields = ftools_utils.combineVectorFields( self.vlayerA, self.vlayerB )
longNames = ftools_utils.checkFieldNameLength( fields )
if not longNames.isEmpty():
message = QString( 'Following field names are longer than 10 characters:\n%1' ).arg( longNames.join( '\n' ) )
message = QString( 'Following field names are longer than 10 characters:\n%s' ) % ( '\n'.join(longNames) )
return GEOS_EXCEPT, FEATURE_EXCEPT, crs_match, message

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

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

writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields,
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/fTools/tools/doIntersectLines.py
Expand Up @@ -95,10 +95,10 @@ def accept(self):
self.outShape.clear()
self.compute(line1, line2, field1, field2, outPath, self.progressBar)
self.progressBar.setValue(100)
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)
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)
if addToTOC == QMessageBox.Yes:
if not ftools_utils.addShapeToCanvas( unicode( outPath ) ):
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( outPath ) ))
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%s" ) % ( unicode( outPath ) ))
self.populateLayers()
self.progressBar.setValue(0)
self.buttonOk.setEnabled( True )
Expand Down Expand Up @@ -144,7 +144,7 @@ def compute(self, line1, line2, field1, field2, outPath, progressBar):

index = ftools_utils.createIndex( provider2 )

fit1 = vprovider.getFeatures( QgsFeatureRequest().setSubsetOfAttributes([index1]) )
fit1 = vprovider.getFeatures( QgsFeatureRequest().setSubsetOfAttributes([index1]) )
while fit1.nextFeature(inFeat):
inGeom = inFeat.geometry()
v1 = inFeat.attributes()[index1]
Expand Down
8 changes: 4 additions & 4 deletions python/plugins/fTools/tools/doMeanCoords.py
Expand Up @@ -95,7 +95,7 @@ def accept(self):
self.compute(inName, outPath, self.weightField.currentText(), self.sizeValue.value(), self.uniqueField.currentText())
self.progressBar.setValue(100)
self.outShape.clear()
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)
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)
if addToTOC == QMessageBox.Yes:
vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
QgsMapLayerRegistry.instance().addMapLayers([vlayer])
Expand Down Expand Up @@ -150,12 +150,12 @@ def compute(self, inName, outName, weightField="", times=1, uniqueField=""):
cy = 0.00
points = []
weights = []
fit = provider.getFeatures()
fit = provider.getFeatures()
while fit.nextFeature(feat):
nElement += 1
self.progressBar.setValue(nElement)
if single:
check = j.toString().trimmed()
check = j.strip()
else:
check = feat.attributes()[uniqueIndex].toString().trimmed()
if check == j.toString().trimmed():
Expand All @@ -164,7 +164,7 @@ def compute(self, inName, outName, weightField="", times=1, uniqueField=""):
if weightIndex == -1:
weight = 1.00
else:
weight = float(feat.attributes()[weightIndex].toDouble()[0])
weight = float(feat.attributes()[weightIndex]
geom = QgsGeometry(feat.geometry())
geom = ftools_utils.extractPoints(geom)
for i in geom:
Expand Down

0 comments on commit d3d5182

Please sign in to comment.