Skip to content
Permalink
Browse files
ftools api updates
  • Loading branch information
jef-n committed Feb 6, 2013
1 parent cf85937 commit 76d1403ebb97762bb7f68013fb3c64d697edbeff
@@ -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 ):
@@ -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()
@@ -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() )
@@ -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() )
@@ -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" ) + " ---" )

@@ -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 )
@@ -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()
@@ -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 )
@@ -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 )
@@ -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():
@@ -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)
@@ -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 = []
@@ -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))
@@ -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 )

@@ -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()
@@ -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:
@@ -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:
@@ -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()
@@ -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() )

0 comments on commit 76d1403

Please sign in to comment.