Skip to content

Commit

Permalink
ftools api updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Feb 6, 2013
1 parent cf85937 commit 76d1403
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 70 deletions.
59 changes: 31 additions & 28 deletions python/plugins/fTools/tools/doGeometry.py
Expand Up @@ -62,8 +62,8 @@ def update( self ):
if inputLayer != "":
changedLayer = ftools_utils.getVectorLayerByName( inputLayer )
changedField = ftools_utils.getFieldList( changedLayer )
for i in changedField:
self.cmbField.addItem( unicode( changedField[ i ].name() ) )
for f in changedField:
self.cmbField.addItem( unicode( f.name() ) )
self.cmbField.addItem( "--- " + self.tr( "Merge all" ) + " ---" )

def accept( self ):
Expand Down Expand Up @@ -615,9 +615,12 @@ def delaunay_triangulation( self ):
import voronoi
from sets import Set
vprovider = self.vlayer.dataProvider()
fields = [ QgsField( "POINTA", QVariant.Double ),
QgsField( "POINTB", QVariant.Double ),
QgsField( "POINTC", QVariant.Double ) ]

fields = QgsFields()
fields.append( QgsField( "POINTA", QVariant.Double ) )
fields.append( QgsField( "POINTB", QVariant.Double ) )
fields.append( QgsField( "POINTC", QVariant.Double ) )

writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields,
QGis.WKBPolygon, vprovider.crs() )
inFeat = QgsFeature()
Expand Down Expand Up @@ -812,16 +815,18 @@ def clip_line( x1, y1, x2, y2, w, h, x, y ):
def layer_extent( self ):
self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), 0 )
self.emit( SIGNAL( "runRange( PyQt_PyObject )" ), ( 0, 0 ) )
fields = [ QgsField( "MINX", QVariant.Double ),
QgsField( "MINY", QVariant.Double ),
QgsField( "MAXX", QVariant.Double ),
QgsField( "MAXY", QVariant.Double ),
QgsField( "CNTX", QVariant.Double ),
QgsField( "CNTY", QVariant.Double ),
QgsField( "AREA", QVariant.Double ),
QgsField( "PERIM", QVariant.Double ),
QgsField( "HEIGHT", QVariant.Double ),
QgsField( "WIDTH", QVariant.Double ) ]

fields = QgsFields()
fields.append( QgsField( "MINX", QVariant.Double ) )
fields.append( QgsField( "MINY", QVariant.Double ) )
fields.append( QgsField( "MAXX", QVariant.Double ) )
fields.append( QgsField( "MAXY", QVariant.Double ) )
fields.append( QgsField( "CNTX", QVariant.Double ) )
fields.append( QgsField( "CNTY", QVariant.Double ) )
fields.append( QgsField( "AREA", QVariant.Double ) )
fields.append( QgsField( "PERIM", QVariant.Double ) )
fields.append( QgsField( "HEIGHT", QVariant.Double ) )
fields.append( QgsField( "WIDTH", QVariant.Double ) )

writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields,
QGis.WKBPolygon, self.vlayer.crs() )
Expand Down Expand Up @@ -862,21 +867,19 @@ def layer_extent( self ):
return True

def feature_extent( self, ):
vprovider = self.vlayer.dataProvider()
vprovider.select( [] )

self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), 0 )

fields = [ QgsField( "MINX", QVariant.Double ),
QgsField( "MINY", QVariant.Double ),
QgsField( "MAXX", QVariant.Double ),
QgsField( "MAXY", QVariant.Double ),
QgsField( "CNTX", QVariant.Double ),
QgsField( "CNTY", QVariant.Double ),
QgsField( "AREA", QVariant.Double ),
QgsField( "PERIM", QVariant.Double ),
QgsField( "HEIGHT", QVariant.Double ),
QgsField( "WIDTH", QVariant.Double ) ]
fields = QgsFields()
fields.append( QgsField( "MINX", QVariant.Double ) )
fields.append( QgsField( "MINY", QVariant.Double ) )
fields.append( QgsField( "MAXX", QVariant.Double ) )
fields.append( QgsField( "MAXY", QVariant.Double ) )
fields.append( QgsField( "CNTX", QVariant.Double ) )
fields.append( QgsField( "CNTY", QVariant.Double ) )
fields.append( QgsField( "AREA", QVariant.Double ) )
fields.append( QgsField( "PERIM", QVariant.Double ) )
fields.append( QgsField( "HEIGHT", QVariant.Double ) )
fields.append( QgsField( "WIDTH", QVariant.Double ) )

writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields,
QGis.WKBPolygon, self.vlayer.crs() )
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/fTools/tools/doGeoprocessing.py
Expand Up @@ -80,8 +80,8 @@ def update( self ):
if inputLayer != "":
changedLayer = ftools_utils.getVectorLayerByName( inputLayer )
changedField = changedLayer.dataProvider().fields()
for i in changedField:
self.attrib.addItem( unicode( changedField[i].name() ) )
for f in changedField:
self.attrib.addItem( unicode( f.name() ) )
if self.myFunction == 4:
self.attrib.addItem( "--- " + self.tr( "Dissolve all" ) + " ---" )

Expand Down
13 changes: 7 additions & 6 deletions python/plugins/fTools/tools/doIntersectLines.py
Expand Up @@ -64,15 +64,15 @@ def update1(self, inputLayer):
self.inField1.clear()
changedLayer = ftools_utils.getVectorLayerByName(unicode(inputLayer))
changedField = ftools_utils.getFieldList(changedLayer)
for i in changedField:
self.inField1.addItem(unicode(changedField[i].name()))
for f in changedField:
self.inField1.addItem(unicode(f.name()))

def update2(self, inputLayer):
self.inField2.clear()
changedLayer = ftools_utils.getVectorLayerByName(unicode(inputLayer))
changedField = ftools_utils.getFieldList(changedLayer)
for i in changedField:
self.inField2.addItem(unicode(changedField[i].name()))
for f in changedField:
self.inField2.addItem(unicode(f.name()))

def accept(self):
self.buttonOk.setEnabled( False )
Expand Down Expand Up @@ -126,15 +126,16 @@ def compute(self, line1, line2, field1, field2, outPath, progressBar):
field2 = fieldList[index2]
field2.setName(unicode(field2.name()) + "_2")

fieldList = {0:field1, 1:field2}
fieldList = QgsFields()
fieldList.append( field1 )
fieldList.append( field2 )
sRs = provider1.crs()
check = QFile(self.shapefileName)
if check.exists():
if not QgsVectorFileWriter.deleteShapeFile(self.shapefileName):
return

writer = QgsVectorFileWriter(self.shapefileName, self.encoding, fieldList, QGis.WKBPoint, sRs)
#writer = QgsVectorFileWriter(outPath, "UTF-8", fieldList, QGis.WKBPoint, sRs)
inFeat = QgsFeature()
inFeatB = QgsFeature()
outFeat = QgsFeature()
Expand Down
8 changes: 4 additions & 4 deletions python/plugins/fTools/tools/doMeanCoords.py
Expand Up @@ -71,10 +71,10 @@ def update(self, inputLayer):
self.uniqueField.addItem( self.tr("(Optional) Unique ID field") )
self.changedLayer = ftools_utils.getVectorLayerByName(inputLayer)
changedField = ftools_utils.getFieldList(self.changedLayer)
for i in changedField:
if changedField[i].type() == QVariant.Int or changedField[i].type() == QVariant.Double:
self.weightField.addItem(unicode(changedField[i].name()))
self.uniqueField.addItem(unicode(changedField[i].name()))
for f in changedField:
if f.type() == QVariant.Int or f.type() == QVariant.Double:
self.weightField.addItem(unicode(f.name()))
self.uniqueField.addItem(unicode(f.name()))

def accept(self):
self.buttonOk.setEnabled( False )
Expand Down
14 changes: 6 additions & 8 deletions python/plugins/fTools/tools/doPointDistance.py
Expand Up @@ -93,19 +93,17 @@ def update1(self, inputLayer):
self.inField1.clear()
changedLayer = ftools_utils.getVectorLayerByName(unicode(inputLayer))
changedField = ftools_utils.getFieldList(changedLayer)
for i in changedField:
if changedField[i].type() == QVariant.Int or \
changedField[i].type() == QVariant.String:
self.inField1.addItem(unicode(changedField[i].name()))
for f in changedField:
if f.type() == QVariant.Int or f.type() == QVariant.String:
self.inField1.addItem(unicode(f.name()))

def update2(self, inputLayer):
self.inField2.clear()
changedLayer = ftools_utils.getVectorLayerByName(unicode(inputLayer))
changedField = ftools_utils.getFieldList(changedLayer)
for i in changedField:
if changedField[i].type() == QVariant.Int or \
changedField[i].type() == QVariant.String:
self.inField2.addItem(unicode(changedField[i].name()))
for f in changedField:
if f.type() == QVariant.Int or f.type() == QVariant.String:
self.inField2.addItem(unicode(f.name()))

def accept(self):
self.buttonOk.setEnabled( False )
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/fTools/tools/doPointsInPolygon.py
Expand Up @@ -170,8 +170,7 @@ def run(self):
index = polyProvider.fieldNameIndex(unicode(self.fieldName))
if index == -1:
index = polyProvider.fieldCount()
field = QgsField(unicode(self.fieldName), QVariant.Double, "real", 24, 15, self.tr("point count field"))
fieldList[index] = field
fieldList.append( QgsField(unicode(self.fieldName), QVariant.Double, "real", 24, 15, self.tr("point count field")) )

sRs = polyProvider.crs()
if QFile(self.outPath).exists():
Expand Down
7 changes: 3 additions & 4 deletions python/plugins/fTools/tools/doRandPoints.py
Expand Up @@ -66,9 +66,9 @@ def update(self, inputLayer):
self.label_4.setEnabled(True)
changedLayer = ftools_utils.getVectorLayerByName(inputLayer)
changedFields = ftools_utils.getFieldList(changedLayer)
for i in changedFields:
if changedFields[i].typeName() == "Integer":
self.cmbField.addItem(unicode(changedFields[i].name()))
for f in changedFields:
if f.typeName() == "Integer":
self.cmbField.addItem(unicode(f.name()))
else:
self.rdoUnstratified.setChecked(True)
self.rdoStratified.setEnabled(False)
Expand Down Expand Up @@ -178,7 +178,6 @@ def simpleRandom(self, n, bound, xmin, xmax, ymin, ymax):

def vectorRandom(self, n, layer, xmin, xmax, ymin, ymax):
provider = layer.dataProvider()
provider.select([])
index = ftools_utils.createIndex(provider)
seed()
points = []
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/fTools/tools/doSelectByLocation.py
Expand Up @@ -103,8 +103,7 @@ def compute(self, inPoly, inPts, modify, selection):
geom = QgsGeometry()
selectedSet = []
index = ftools_utils.createIndex(inputProvider)
inputProvider.rewind()
inputProvider.select(inputProvider.attributeIndexes())

if selection:
features = selectLayer.selectedFeatures()
self.progressBar.setMaximum(len(features))
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/fTools/tools/doSubsetSelect.py
Expand Up @@ -54,8 +54,8 @@ def update(self, inputLayer):
self.inField.clear()
changedLayer = ftools_utils.getVectorLayerByName(inputLayer)
changedField = ftools_utils.getFieldList(changedLayer)
for i in changedField:
self.inField.addItem(unicode(changedField[i].name()))
for f in changedField:
self.inField.addItem(unicode(f.name()))
maxFeatures = changedLayer.dataProvider().featureCount()
self.spnNumber.setMaximum( maxFeatures )

Expand Down
3 changes: 1 addition & 2 deletions python/plugins/fTools/tools/doSumLines.py
Expand Up @@ -104,8 +104,7 @@ def compute(self, inPoly, inLns, inField, outPath, progressBar):
index = polyProvider.fieldNameIndex(unicode(inField))
if index == -1:
index = polyProvider.fieldCount()
field = QgsField(unicode(inField), QVariant.Double, "real", 24, 15, self.tr("length field"))
fieldList[index] = field
fieldList.append( QgsField(unicode(inField), QVariant.Double, "real", 24, 15, self.tr("length field")) )
sRs = polyProvider.crs()
inFeat = QgsFeature()
inFeatB = QgsFeature()
Expand Down
12 changes: 6 additions & 6 deletions python/plugins/fTools/tools/doValidate.py
Expand Up @@ -294,13 +294,11 @@ def check_geometry( self, vlayer ):
layer = vlayer.selectedFeatures()
nFeat = len(layer)
else:
#layer = vlayer # requires SIP >= 4.9
layer = []
vlayer.select([]) # select all features, and ignore attributes
ft = QgsFeature()
fit = vlayer.getFeatures()
fit = vlayer.getFeatures( QgsFeatureRequest().setSubsetOfAttributes([]) )
while fit.nextFeature(ft):
layer.append(QgsFeature(ft))
layer.append( QgsFeature(ft) )
nFeat = len(layer)
nElement = 0
if nFeat > 0:
Expand All @@ -318,8 +316,10 @@ def check_geometry( self, vlayer ):
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nFeat )

if self.writeShape:
fields = [ QgsField( "FEAT_ID", QVariant.Int ),
QgsField( "ERROR", QVariant.String ) ]
fields = QgsFields()
fields.append( QgsField( "FEAT_ID", QVariant.Int ) )
fields.append( QgsField( "ERROR", QVariant.String ) )

writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields,
QGis.WKBPoint, vlayer.crs() )
for rec in lstErrors:
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/fTools/tools/doVectorSplit.py
Expand Up @@ -59,8 +59,8 @@ def update(self, inputLayer):
self.inField.clear()
changedLayer = ftools_utils.getVectorLayerByName(inputLayer)
changedField = ftools_utils.getFieldList(changedLayer)
for i in changedField:
self.inField.addItem(unicode(changedField[i].name()))
for f in changedField:
self.inField.addItem(unicode(f.name()))

def outFile(self):
self.outShape.clear()
Expand Down
2 changes: 0 additions & 2 deletions python/plugins/sextante/algs/FieldPyculator.py
Expand Up @@ -67,8 +67,6 @@ def processAlgorithm(self, progress):
output = self.getOutputFromName(self.OUTPUT_LAYER)
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT_LAYER))
vprovider = layer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
fields = vprovider.fields()
fields.append(QgsField(fieldname, QVariant.Double))
writer = output.getVectorWriter(fields, vprovider.geometryType(), vprovider.crs() )
Expand Down

0 comments on commit 76d1403

Please sign in to comment.