more SIP updates for fTools

This commit is contained in:
Alexander Bruy 2013-06-03 16:05:08 +04:00
parent d3d51820e3
commit a75563f299
19 changed files with 132 additions and 136 deletions

View File

@ -89,7 +89,7 @@ class GeometryDialog( QDialog, Ui_Dialog ):
(self.shapefileName, self.encoding) = ftools_utils.saveDialog( self )
if self.shapefileName is None or self.encoding is None:
return
self.outShape.setText( QString( self.shapefileName ) )
self.outShape.setText( self.shapefileName )
def manageGui( self ):
self.lblField.setVisible( False )
@ -365,12 +365,12 @@ class geometryThread( QThread ):
if not index == -1:
unique = ftools_utils.getUniqueValues( vprovider, int( index ) )
else:
unique = [ QVariant( QString() ) ]
unique = [ "" ]
nFeat = vprovider.featureCount() * len( unique )
nElement = 0
self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), 0 )
self.emit( SIGNAL( "runRange( PyQt_PyObject )" ), ( 0, nFeat ) )
merge_all = self.myField == QString( "--- " + self.tr( "Merge all" ) + " ---" )
merge_all = self.myField == "--- " + self.tr( "Merge all" ) + " ---"
if not len( unique ) == self.vlayer.featureCount() or merge_all:
for i in unique:
multi_feature= []
@ -381,8 +381,8 @@ class geometryThread( QThread ):
if not merge_all:
idVar = atMap[ index ]
else:
idVar = QVariant( QString() )
if idVar.toString().trimmed() == i.toString().trimmed() or merge_all:
idVar = ""
if idVar.strip() == i.strip() or merge_all:
if first:
atts = atMap
first = False
@ -530,7 +530,7 @@ class geometryThread( QThread ):
# 2 - ellipsoidal
if self.myCalcType == 2:
settings = QSettings()
ellips = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString()
ellips = settings.value( "/qgis/measure/ellipsoid", "WGS84" )
crs = self.vlayer.crs().srsid()
elif self.myCalcType == 1:
mapCRS = self.parent.iface.mapCanvas().mapRenderer().destinationCrs()
@ -568,7 +568,7 @@ class geometryThread( QThread ):
atMap = inFeat.attributes()
maxIndex = index1 if index1>index2 else index2
if maxIndex>len(atMap):
atMap += [ QVariant() ] * ( index2+1 - len(atMap) )
atMap += [ "" ] * ( index2+1 - len(atMap) )
atMap[ index1 ] = attr1
if index1!=index2:
atMap[ index2 ] = attr2
@ -577,9 +577,9 @@ class geometryThread( QThread ):
else:
changeMap = {}
changeMap[ inFeat.id() ] = {}
changeMap[ inFeat.id() ][ index1 ] = QVariant( attr1 )
changeMap[ inFeat.id() ][ index1 ] = attr1
if index1!=index2:
changeMap[ inFeat.id() ][ index2 ] = QVariant( attr2 )
changeMap[ inFeat.id() ][ index2 ] = attr2
vprovider.changeAttributeValues( changeMap )
if self.writeShape:
@ -663,7 +663,7 @@ class geometryThread( QThread ):
point = QgsPoint( geom.asPoint() )
polygon.append( point )
if step <= 3:
attrs.append(QVariant( ids[ index ] ) )
attrs.append(ids[ index ] )
step += 1
feat.setAttributes(attrs)
geometry = QgsGeometry().fromPolygon( [ polygon ] )
@ -853,16 +853,16 @@ class geometryThread( QThread ):
geometry = QgsGeometry().fromPolygon( [ rect ] )
feat = QgsFeature()
feat.setGeometry( geometry )
feat.setAttributes( [ QVariant( minx ),
QVariant( miny ),
QVariant( maxx ),
QVariant( maxy ),
QVariant( cntx ),
QVariant( cnty ),
QVariant( area ),
QVariant( perim ),
QVariant( height ),
QVariant( width ) ] )
feat.setAttributes( [ minx,
miny,
maxx,
maxy,
cntx,
cnty,
area,
perim,
height,
width ] )
writer.addFeature( feat )
self.emit( SIGNAL( "runRange( PyQt_PyObject )" ), ( 0, 100 ) )
self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), 0 )
@ -916,16 +916,16 @@ class geometryThread( QThread ):
geometry = QgsGeometry().fromPolygon( [ rect ] )
outFeat.setGeometry( geometry )
outFeat.setAttributes( [ QVariant( minx ),
QVariant( miny ),
QVariant( maxx ),
QVariant( maxy ),
QVariant( cntx ),
QVariant( cnty ),
QVariant( area ),
QVariant( perim ),
QVariant( height ),
QVariant( width ) ] )
outFeat.setAttributes( [ minx,
miny,
maxx,
maxy,
cntx,
cnty,
area,
perim,
height,
width ] )
writer.addFeature( outFeat )
else:
self.emit( SIGNAL( "runRange( PyQt_PyObject )" ), ( 0, vprovider.featureCount() ) )
@ -953,16 +953,16 @@ class geometryThread( QThread ):
geometry = QgsGeometry().fromPolygon( [ rect ] )
outFeat.setGeometry( geometry )
outFeat.setAttributes( [ QVariant( minx ),
QVariant( miny ),
QVariant( maxx ),
QVariant( maxy ),
QVariant( cntx ),
QVariant( cnty ),
QVariant( area ),
QVariant( perim ),
QVariant( height ),
QVariant( width ) ] )
outFeat.setAttributes( [ minx,
miny,
maxx,
maxy,
cntx,
cnty,
area,
perim,
height,
width ] )
writer.addFeature( outFeat )
del writer

View File

@ -124,7 +124,7 @@ class GeoprocessingDialog( QDialog, Ui_Dialog ):
( self.shapefileName, self.encoding ) = ftools_utils.saveDialog( self )
if self.shapefileName is None or self.encoding is None:
return
self.outShape.setText( QString( self.shapefileName ) )
self.outShape.setText( self.shapefileName )
def manageGui( self ):
if self.myFunction == 1: # Buffer
@ -491,7 +491,7 @@ class geoprocessingThread( QThread ):
for inFeat in selectionA:
atMap = inFeat.attributes()
idVar = atMap[ self.myParam ]
if idVar.toString().trimmed() == i.toString().trimmed():
if idVar.strip() == i.strip():
if first:
outID = idVar
first = False
@ -506,9 +506,9 @@ class geoprocessingThread( QThread ):
outGeom = tmpGeom.convexHull()
outFeat.setGeometry( outGeom )
(area, perim) = self.simpleMeasure( outGeom )
outFeat.setAttribute( 0, QVariant( outID ) )
outFeat.setAttribute( 1, QVariant( area ) )
outFeat.setAttribute( 2, QVariant( perim ) )
outFeat.setAttribute( 0, outID )
outFeat.setAttribute( 1, area )
outFeat.setAttribute( 2, perim )
writer.addFeature( outFeat )
except:
GEOS_EXCEPT = False
@ -547,7 +547,7 @@ class geoprocessingThread( QThread ):
while fitA.nextFeature( inFeat ):
atMap = inFeat.attributes()
idVar = atMap[ self.myParam ]
if idVar.toString().trimmed() == i.toString().trimmed():
if idVar.strip() == i.strip():
if first:
outID = idVar
first = False
@ -562,9 +562,9 @@ class geoprocessingThread( QThread ):
outGeom = tmpGeom.convexHull()
outFeat.setGeometry( outGeom )
(area, perim) = self.simpleMeasure( outGeom )
outFeat.setAttribute( 0, QVariant( outID ) )
outFeat.setAttribute( 1, QVariant( area ) )
outFeat.setAttribute( 2, QVariant( perim ) )
outFeat.setAttribute( 0, outID )
outFeat.setAttribute( 1, area )
outFeat.setAttribute( 2, perim )
writer.addFeature( outFeat )
except:
GEOS_EXCEPT = False
@ -893,7 +893,7 @@ class geoprocessingThread( QThread ):
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%s' ) % ( '\n'.join(longNames) )
message = self.tr('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,
@ -1078,7 +1078,7 @@ class geoprocessingThread( QThread ):
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%s' ) % ( "\n".join(longNames) )
message = self.tr( '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,
@ -1264,7 +1264,7 @@ class geoprocessingThread( QThread ):
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%s' ) % ( "\n".join(longNames) )
message = self.tr( '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,

View File

@ -108,7 +108,7 @@ class Dialog(QDialog, Ui_Dialog):
( self.shapefileName, self.encoding ) = ftools_utils.saveDialog( self )
if self.shapefileName is None or self.encoding is None:
return
self.outShape.setText( QString( self.shapefileName ) )
self.outShape.setText( self.shapefileName )
def compute(self, line1, line2, field1, field2, outPath, progressBar):

View File

@ -108,7 +108,7 @@ class Dialog(QDialog, Ui_Dialog):
( self.shapefileName, self.encoding ) = ftools_utils.saveDialog( self )
if self.shapefileName is None or self.encoding is None:
return
self.outShape.setText( QString( self.shapefileName ) )
self.outShape.setText( self.shapefileName )
def compute(self, inName, outName, weightField="", times=1, uniqueField=""):
vlayer = ftools_utils.getVectorLayerByName(inName)
@ -125,7 +125,7 @@ class Dialog(QDialog, Ui_Dialog):
uniqueValues = ftools_utils.getUniqueValues(provider, int( uniqueIndex ) )
single = False
else:
uniqueValues = [QVariant(1)]
uniqueValues = [1]
single = True
if self.function == 2:
fieldList = QgsFields()
@ -157,14 +157,14 @@ class Dialog(QDialog, Ui_Dialog):
if single:
check = j.strip()
else:
check = feat.attributes()[uniqueIndex].toString().trimmed()
if check == j.toString().trimmed():
check = feat.attributes()[uniqueIndex].strip()
if check == j.strip():
cx = 0.00
cy = 0.00
if weightIndex == -1:
weight = 1.00
else:
weight = float(feat.attributes()[weightIndex]
weight = float(feat.attributes()[weightIndex])
geom = QgsGeometry(feat.geometry())
geom = ftools_utils.extractPoints(geom)
for i in geom:
@ -198,13 +198,13 @@ class Dialog(QDialog, Ui_Dialog):
sd += (i-md)*(i-md)
sd = sqrt(sd/item)
outfeat.setGeometry(QgsGeometry.fromPoint(meanPoint).buffer(sd * times, 10))
outfeat.setAttribute(0, QVariant(sd))
outfeat.setAttribute(1, QVariant(j))
outfeat.setAttribute(0, sd)
outfeat.setAttribute(1, j)
else:
outfeat.setGeometry(QgsGeometry.fromPoint(meanPoint))
outfeat.setAttribute(0, QVariant(cx))
outfeat.setAttribute(1, QVariant(cy))
outfeat.setAttribute(2, QVariant(j))
outfeat.setAttribute(0, cx)
outfeat.setAttribute(1, cy)
outfeat.setAttribute(2, j)
writer.addFeature(outfeat)
if single:
break

View File

@ -58,7 +58,7 @@ class Dialog( QDialog, Ui_Dialog ):
workDir = QDir( inDir )
workDir.setFilter( QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot )
nameFilter = QStringList() << "*.shp" << "*.SHP"
nameFilter = [ "*.shp", "*.SHP" ]
workDir.setNameFilters( nameFilter )
self.inputFiles = workDir.entryList()
if self.inputFiles.count() == 0:
@ -84,7 +84,7 @@ class Dialog( QDialog, Ui_Dialog ):
self.inputFiles = None
return
self.inputFiles = QStringList()
self.inputFiles = []
for f in files:
fileName = QFileInfo( f ).fileName()
self.inputFiles.append( fileName )
@ -118,7 +118,7 @@ class Dialog( QDialog, Ui_Dialog ):
if self.inputFiles is None:
workDir = QDir( self.leInputDir.text() )
workDir.setFilter( QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot )
nameFilter = QStringList() << "*.shp" << "*.SHP"
nameFilter = [ "*.shp" << "*.SHP" ]
workDir.setNameFilters( nameFilter )
self.inputFiles = workDir.entryList()
if self.inputFiles.count() == 0:
@ -306,7 +306,7 @@ class ShapeMergeThread( QThread ):
inGeom = QgsGeometry()
fit = vprovider.getFeatures()
while fit.nextFeature( inFeat ):
mergedAttrs = [QVariant()] * len(mergedFields)
mergedAttrs = [""] * len(mergedFields)
# fill available attributes with values
fieldIndex = 0

View File

@ -63,7 +63,7 @@ class Dialog(QDialog, Ui_Dialog):
(self.shapefileName, self.encoding) = ftools_utils.saveDialog(self)
if self.shapefileName is None or self.encoding is None:
return
self.outShape.setText(QString(self.shapefileName))
self.outShape.setText(self.shapefileName)
def accept(self):
if self.inPolygon.currentText() == "":
@ -218,7 +218,7 @@ class PointsInPolygonThread(QThread):
interrupted = True
break
atMap.append(QVariant(count))
atMap.append(count)
outFeat.setAttributes(atMap)
writer.addFeature(outFeat)

View File

@ -138,7 +138,7 @@ class Dialog(QDialog, Ui_Dialog):
( self.shapefileName, self.encoding ) = ftools_utils.saveDialog( self )
if self.shapefileName is None or self.encoding is None:
return
self.outShape.setText( QString( self.shapefileName ) )
self.outShape.setText( self.shapefileName )
# combine all polygons in layer to create single polygon (slow for complex polygons)
def createSinglePolygon(self, vlayer):
@ -225,7 +225,7 @@ class Dialog(QDialog, Ui_Dialog):
add = ( 100.00 - 70.00 ) / len(points)
for i in points:
outFeat.setGeometry(i)
outFeat.setAttribute(0, QVariant(idVar))
outFeat.setAttribute(0, idVar)
writer.addFeature(outFeat)
idVar = idVar + 1
count = count + add

View File

@ -102,7 +102,7 @@ class Dialog(QDialog, Ui_Dialog):
( self.shapefileName, self.encoding ) = ftools_utils.saveDialog( self )
if self.shapefileName is None or self.encoding is None:
return
self.outShape.setText( QString( self.shapefileName ) )
self.outShape.setText( self.shapefileName )
# Generate list of random points
def simpleRandom(self, n, bound, xmin, xmax, ymin, ymax):
@ -149,7 +149,7 @@ class Dialog(QDialog, Ui_Dialog):
pGeom = QgsGeometry().fromPoint(QgsPoint(x, y))
if pGeom.intersects(bound):
outFeat.setGeometry(pGeom)
outFeat.setAttribute(0, QVariant(idVar))
outFeat.setAttribute(0, idVar)
writer.addFeature(outFeat)
idVar = idVar + 1
x = x + pointSpacing

View File

@ -85,7 +85,7 @@ class Dialog( QDialog, Ui_Dialog ):
( self.shapeFileName, self.encoding ) = ftools_utils.saveDialog( self )
if self.shapeFileName is None or self.encoding is None:
return
self.edOutputFile.setText( QString( self.shapeFileName ) )
self.edOutputFile.setText( self.shapeFileName )
def accept( self ):
vLayer = ftools_utils.getVectorLayerByName( self.cmbInputLayer.currentText() )
@ -326,7 +326,7 @@ class GeomThread( QThread ):
else: # modify existing shapefile
if not self.inputLayer.isEditable():
self.inputLayer.startEditing()
self.inputLayer.beginEditCommand( QString( "Simplify line(s)" ) )
self.inputLayer.beginEditCommand( "Simplify line(s)" )
if self.useSelection:
selection = self.inputLayer.selectedFeatures()
self.emit( SIGNAL( "rangeCalculated( PyQt_PyObject )" ), len( selection ) )
@ -451,7 +451,7 @@ class GeomThread( QThread ):
if not self.inputLayer.isEditable():
self.inputLayer.startEditing()
self.inputLayer.beginEditCommand( QString( "Densify line(s)" ) )
self.inputLayer.beginEditCommand( "Densify line(s)" )
if self.useSelection:
selection = self.inputLayer.selectedFeatures()

View File

@ -134,7 +134,7 @@ class Dialog( QDialog, Ui_Dialog ):
self.restoreGui()
if not errors.isEmpty():
msg = QString( "Processing of the following layers/files ended with error:<br><br>" ).append( errors.join( "<br>" ) )
msg = self.tr( "Processing of the following layers/files ended with error:<br><br>" ) + "<br>".join(errors)
QErrorMessage( self ).showMessage( msg )
QMessageBox.information( self, self.tr( "Finished" ), self.tr( "Processing completed." ) )
@ -162,7 +162,7 @@ class SpatialIdxThread( QThread ):
self.mutex = QMutex()
self.stopMe = 0
self.errors = QStringList()
self.errors = []
def run( self ):
self.mutex.lock()

View File

@ -117,7 +117,7 @@ class Dialog(QDialog, Ui_Dialog):
( self.shapefileName, self.encoding ) = ftools_utils.saveDialog( self )
if self.shapefileName is None or self.encoding is None:
return
self.outShape.setText( QString( self.shapefileName ) )
self.outShape.setText( self.shapefileName )
def compute(self, inName, joinName, outName, summary, sumList, keep, progressBar):
layer1 = ftools_utils.getVectorLayerByName(inName)
@ -225,13 +225,13 @@ class Dialog(QDialog, Ui_Dialog):
atMap = atMap1
for j in numFields.keys():
for k in sumList:
if k == "SUM": atMap.append(QVariant(sum(numFields[j])))
elif k == "MEAN": atMap.append(QVariant(sum(numFields[j]) / count))
elif k == "MIN": atMap.append(QVariant(min(numFields[j])))
elif k == "MED": atMap.append(QVariant(myself(numFields[j])))
else: atMap.append(QVariant(max(numFields[j])))
if k == "SUM": atMap.append(sum(numFields[j]))
elif k == "MEAN": atMap.append(sum(numFields[j]) / count)
elif k == "MIN": atMap.append(min(numFields[j]))
elif k == "MED": atMap.append(myself(numFields[j]))
else: atMap.append(max(numFields[j]))
numFields[j] = []
atMap.append(QVariant(count))
atMap.append(count)
atMap = dict(zip(seq, atMap))
if none:
outFeat.setAttributes(atMap1)

View File

@ -85,8 +85,6 @@ class Dialog(QDialog, Ui_Dialog):
vlayer = ftools_utils.getVectorLayerByName(inVect)
vprovider = vlayer.dataProvider()
index = vprovider.fieldNameIndex(inField)
#unique = []
#vprovider.uniqueValues(index, unique)
unique = ftools_utils.getUniqueValues(vprovider, int(index))
inFeat = QgsFeature()
selran = []
@ -101,7 +99,7 @@ class Dialog(QDialog, Ui_Dialog):
FIDs= []
while fit.nextFeature(inFeat):
atMap = inFeat.attributes()
if atMap[index] == QVariant(i):
if atMap[index] == i:
FID = inFeat.id()
FIDs.append(FID)
nElement += 1

View File

@ -91,7 +91,7 @@ class Dialog(QDialog, Ui_Dialog):
( self.shapefileName, self.encoding ) = ftools_utils.saveDialog( self )
if self.shapefileName is None or self.encoding is None:
return
self.outShape.setText( QString( self.shapefileName ) )
self.outShape.setText( self.shapefileName )
def compute(self, inPoly, inLns, inField, outPath, progressBar):
polyLayer = ftools_utils.getVectorLayerByName(inPoly)
@ -137,9 +137,8 @@ class Dialog(QDialog, Ui_Dialog):
outGeom = inGeom.intersection(tmpGeom)
length = length + distArea.measure(outGeom)
outFeat.setGeometry(inGeom)
atMap.append(QVariant(length))
atMap.append(length)
outFeat.setAttributes(atMap)
#outFeat.setAttribute(index, QVariant(length))
writer.addFeature(outFeat)
start = start + 1
progressBar.setValue(start)

View File

@ -103,7 +103,7 @@ class ValidateDialog( QDialog, Ui_Dialog ):
def closeEvent(self, e):
settings = QSettings()
settings.setValue( "/fTools/ValidateDialog/geometry", QVariant(self.saveGeometry()) )
settings.setValue( "/fTools/ValidateDialog/geometry", self.saveGeometry())
QDialog.closeEvent(self, e)
del self.marker
@ -111,8 +111,7 @@ class ValidateDialog( QDialog, Ui_Dialog ):
if ( e.modifiers() == Qt.ControlModifier or \
e.modifiers() == Qt.MetaModifier ) and \
e.key() == Qt.Key_C:
#selection = self.tblUnique.selectedItems()
items = QString()
items = ""
for row in range( self.tblUnique.rowCount() ):
items.append( self.tblUnique.item( row, 0 ).text()
+ "," + self.tblUnique.item( row, 1 ).text() + "\n" )
@ -156,7 +155,7 @@ class ValidateDialog( QDialog, Ui_Dialog ):
(self.shapefileName, self.encoding) = ftools_utils.saveDialog( self )
if self.shapefileName is None or self.encoding is None:
return
self.lineEditShpError.setText( QString( self.shapefileName ) )
self.lineEditShpError.setText( self.shapefileName )
def zoomToError(self, curr, prev):
if curr is None:
@ -250,7 +249,7 @@ class ValidateDialog( QDialog, Ui_Dialog ):
message = err.what()
errItem = QTableWidgetItem( message )
if err.hasWhere(): # if there is a location associated with the error
errItem.setData(Qt.UserRole, QVariant(err.where()))
errItem.setData(Qt.UserRole, err.where())
self.tblUnique.setItem( count, 1, errItem )
count += 1
self.tblUnique.setHorizontalHeaderLabels( [ self.tr("Feature"), self.tr("Error(s)") ] )
@ -336,7 +335,7 @@ class validateThread( QThread ):
geometry = QgsGeometry().fromPoint( myPoint )
ft = QgsFeature()
ft.setGeometry( geometry )
ft.setAttributes( [ QVariant( fidItem ), QVariant( message ) ] )
ft.setAttributes( [ fidItem, message ] )
writer.addFeature( ft )
del writer
return "writeShape"

View File

@ -203,8 +203,8 @@ class Dialog(QDialog, Ui_Dialog):
pt2 = QgsPoint(bound.xMaximum(), y)
line = [pt1, pt2]
outFeat.setGeometry(outGeom.fromPolyline(line))
outFeat.setAttribute(0, QVariant(idVar))
outFeat.setAttribute(1, QVariant(y))
outFeat.setAttribute(0, idVar)
outFeat.setAttribute(1, y)
writer.addFeature(outFeat)
y = y - yOffset
idVar = idVar + 1
@ -223,8 +223,8 @@ class Dialog(QDialog, Ui_Dialog):
pt2 = QgsPoint(x, bound.yMinimum())
line = [pt1, pt2]
outFeat.setGeometry(outGeom.fromPolyline(line))
outFeat.setAttribute(0, QVariant(idVar))
outFeat.setAttribute(1, QVariant(x))
outFeat.setAttribute(0, idVar)
outFeat.setAttribute(1, x)
writer.addFeature(outFeat)
x = x + xOffset
idVar = idVar + 1
@ -248,11 +248,11 @@ class Dialog(QDialog, Ui_Dialog):
pt5 = QgsPoint(x, y)
polygon = [[pt1, pt2, pt3, pt4, pt5]]
outFeat.setGeometry(outGeom.fromPolygon(polygon))
outFeat.setAttribute(0, QVariant(idVar))
outFeat.setAttribute(1, QVariant(x))
outFeat.setAttribute(2, QVariant(x + xOffset))
outFeat.setAttribute(3, QVariant(y - yOffset))
outFeat.setAttribute(4, QVariant(y))
outFeat.setAttribute(0, idVar)
outFeat.setAttribute(1, x)
outFeat.setAttribute(2, x + xOffset)
outFeat.setAttribute(3, y - yOffset)
outFeat.setAttribute(4, y)
writer.addFeature(outFeat)
idVar = idVar + 1
x = x + xOffset
@ -269,7 +269,7 @@ class Dialog(QDialog, Ui_Dialog):
( self.shapefileName, self.encoding ) = ftools_utils.saveDialog( self )
if self.shapefileName is None or self.encoding is None:
return
self.outShape.setText( QString( self.shapefileName ) )
self.outShape.setText( self.shapefileName )
def chkAlignToggled(self):
if self.chkAlign.isChecked():

View File

@ -67,7 +67,7 @@ class Dialog(QDialog, Ui_Dialog):
( self.folderName, self.encoding ) = ftools_utils.dirDialog( self )
if self.folderName is None or self.encoding is None:
return
self.outShape.setText( QString( self.folderName ) )
self.outShape.setText( self.folderName )
def accept(self):
inShape = self.inShape.currentText()
@ -124,7 +124,7 @@ class Dialog(QDialog, Ui_Dialog):
self.restoreGui()
if not errors.isEmpty():
msg = QString( "Processing of the following layers/files ended with error:<br><br>" ).append( errors.join( "<br>" ) )
msg = self.tr( "Processing of the following layers/files ended with error:<br><br>" ) + "<br>".join(errors)
QErrorMessage( self ).showMessage( msg )
QMessageBox.information(self, self.tr("Vector Split"),
@ -141,7 +141,7 @@ class SplitThread(QThread):
self.mutex = QMutex()
self.stopMe = 0
self.errors = QStringList()
self.errors = []
def run(self):
self.mutex.lock()
@ -150,12 +150,12 @@ class SplitThread(QThread):
interrupted = False
outPath = QString(self.outDir)
outPath = self.outDir
if outPath.contains("\\"):
if outPath.find("\\") != -1:
outPath.replace("\\", "/")
if not outPath.endsWith("/"):
if not outPath.endswith("/"):
outPath = outPath + "/"
provider = self.layer.dataProvider()
@ -172,7 +172,7 @@ class SplitThread(QThread):
for i in unique:
check = QFile(baseName + "_" + unicode(i.toString().trimmed()) + ".shp")
check = QFile(baseName + "_" + unicode(i.strip()) + ".shp")
fName = check.fileName()
if check.exists():
if not QgsVectorFileWriter.deleteShapeFile(fName):

View File

@ -65,7 +65,7 @@ class VisualDialog( QDialog, Ui_Dialog ):
'''
if ( e.modifiers() == Qt.ControlModifier or e.modifiers() == Qt.MetaModifier ) and e.key() == Qt.Key_C:
#selection = self.tblUnique.selectedItems()
items = QString()
items = ""
if self.myFunction in ( 1, 2 ):
for rec in range( self.tblUnique.rowCount() ):
items.append( self.tblUnique.item( rec, 0 ).text() + "\n" )
@ -245,7 +245,7 @@ class visualThread( QThread ):
for item in unique:
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
lstUnique.append(item.toString().trimmed())
lstUnique.append(item.strip())
lstCount = len( unique )
return ( lstUnique, lstCount )

View File

@ -89,7 +89,7 @@ def checkCRSCompatibility( crsA, crsB ):
# Convenience function to write vector layer to shapefile
def writeVectorLayerToShape( vlayer, outputPath, encoding ):
mCodec = QTextCodec.codecForName( QString(encoding).toLocal8Bit().data() )
mCodec = QTextCodec.codecForName( encoding )
if not mCodec:
return False
#Here we should check that the output path is valid
@ -289,8 +289,8 @@ def saveDialog( parent, filtering="Shapefiles (*.shp *.SHP)"):
if not fileDialog.exec_() == QDialog.Accepted:
return None, None
files = fileDialog.selectedFiles()
settings.setValue("/UI/lastShapefileDir", QVariant( QFileInfo( unicode( files.first() ) ).absolutePath() ) )
return ( unicode( files.first() ), unicode( fileDialog.encoding() ) )
settings.setValue("/UI/lastShapefileDir", QFileInfo( unicode( files[0] ) ).absolutePath() )
return ( unicode( files[0] ), unicode( fileDialog.encoding() ) )
# Generate a save file dialog with a dropdown box for choosing encoding style
# with mode="SingleFile" will allow to select only one file, in other cases - several files
@ -304,9 +304,9 @@ def openDialog( parent, filtering="Shapefiles (*.shp *.SHP)", dialogMode="Single
if not fileDialog.exec_() == QDialog.Accepted:
return None, None
files = fileDialog.selectedFiles()
settings.setValue("/UI/lastShapefileDir", QVariant( QFileInfo( unicode( files.first() ) ).absolutePath() ) )
settings.setValue("/UI/lastShapefileDir", QFileInfo( unicode( files[0] ) ).absolutePath() )
if dialogMode == "SingleFile":
return ( unicode( files.first() ), unicode( fileDialog.encoding() ) )
return ( unicode( files[0] ), unicode( fileDialog.encoding() ) )
else:
return ( files, unicode( fileDialog.encoding() ) )
@ -322,8 +322,8 @@ def dirDialog( parent ):
if not fileDialog.exec_() == QDialog.Accepted:
return None, None
folders = fileDialog.selectedFiles()
settings.setValue("/UI/lastShapefileDir", QVariant( QFileInfo( unicode( folders.first() ) ).absolutePath() ) )
return ( unicode( folders.first() ), unicode( fileDialog.encoding() ) )
settings.setValue("/UI/lastShapefileDir", QFileInfo( unicode( folders[0] ) ).absolutePath() )
return ( unicode( folders[0] ), unicode( fileDialog.encoding() ) )
# Return field type from it's name
def getFieldType(vlayer, fieldName):