Skip to content
Permalink
Browse files

more SIP updates for fTools

  • Loading branch information
alexbruy committed Jun 3, 2013
1 parent d3d5182 commit a75563f299bcb44bd47820c011460b57f65441e2
@@ -89,7 +89,7 @@ def outFile( self ):
(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 @@ def single_to_multi( self ):
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 @@ def single_to_multi( self ):
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 @@ def export_geometry_info( self ):
# 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 @@ def export_geometry_info( self ):
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 @@ def export_geometry_info( self ):
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 @@ def delaunay_triangulation( self ):
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 @@ def layer_extent( self ):
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 @@ def feature_extent( self, ):
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 @@ def feature_extent( self, ):
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
@@ -124,7 +124,7 @@ def outFile( self ):
( 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
@@ -403,7 +403,7 @@ 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:
@@ -434,7 +434,7 @@ 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:
@@ -491,7 +491,7 @@ def convex_hull(self, useField ):
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 @@ def convex_hull(self, useField ):
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 @@ def convex_hull(self, useField ):
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 @@ def convex_hull(self, useField ):
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
@@ -573,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 )
@@ -816,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
@@ -893,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%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,
@@ -992,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 )
@@ -1078,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%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 @@ 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%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,
@@ -108,7 +108,7 @@ def outFile(self):
( 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):

@@ -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]
@@ -108,7 +108,7 @@ def outFile(self):
( 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 @@ def compute(self, inName, outName, weightField="", times=1, uniqueField=""):
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 @@ def compute(self, inName, outName, weightField="", times=1, uniqueField=""):
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 @@ def compute(self, inName, outName, weightField="", times=1, uniqueField=""):
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
@@ -58,7 +58,7 @@ def inputDir( self ):

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 @@ def inputFile( self ):
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 @@ def accept( self ):
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 @@ def run( self ):
inGeom = QgsGeometry()
fit = vprovider.getFeatures()
while fit.nextFeature( inFeat ):
mergedAttrs = [QVariant()] * len(mergedFields)
mergedAttrs = [""] * len(mergedFields)

# fill available attributes with values
fieldIndex = 0

0 comments on commit a75563f

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