diff --git a/debian/control.raring b/debian/control.raring index a6f7391f5fe..c9742fd4962 100644 --- a/debian/control.raring +++ b/debian/control.raring @@ -31,6 +31,7 @@ Build-Depends: python-qt4-dev (>=4.1.0), python-sip (>= 4.5.0), python-sip-dev (>= 4.5.0), + libpython2.7-dev, libosgearth-dev, libopenscenegraph-dev, git, diff --git a/python/plugins/fTools/tools/doEliminate.py b/python/plugins/fTools/tools/doEliminate.py index d526e6987a0..a79c3f15e07 100644 --- a/python/plugins/fTools/tools/doEliminate.py +++ b/python/plugins/fTools/tools/doEliminate.py @@ -141,7 +141,7 @@ class Dialog(QtGui.QDialog, Ui_Dialog): else: QtGui.QMessageBox.warning(self, self.tr("Eliminate"), self.tr("Could not delete features")) return None - + # ANALYZE start = 20.00 progressBar.setValue(start) @@ -160,7 +160,7 @@ class Dialog(QtGui.QDialog, Ui_Dialog): for fid2Eliminate in inLayer.selectedFeaturesIds(): feat = QgsFeature() - if inLayer.featureAtId(fid2Eliminate, feat, True, False): + if inLayer.getFeatures( QgsFeatureRequest().setFilterFid( fid2Eliminate ).setSubsetOfAttributes([]) ).nextFeature( feat ): geom2Eliminate = feat.geometry() bbox = geom2Eliminate.boundingBox() outLayer.select(bbox, False) # make a new selection @@ -171,7 +171,7 @@ class Dialog(QtGui.QDialog, Ui_Dialog): for selFid in outLayer.selectedFeaturesIds(): selFeat = QgsFeature() - if outLayer.featureAtId(selFid, selFeat, True, False): + if outLayer.getFeatures( QgsFeatureRequest().setFilterFid( selFid ).setSubsetOfAttributes([]) ).nextFeature( selFeat ): selGeom = selFeat.geometry() if geom2Eliminate.intersects(selGeom): # we have a candidate @@ -190,7 +190,7 @@ class Dialog(QtGui.QDialog, Ui_Dialog): max = selValue mergeWithFid = selFid mergeWithGeom = QgsGeometry(selGeom) # deep copy of the geometry - + if mergeWithFid != None: # a successful candidate newGeom = mergeWithGeom.combine(geom2Eliminate) @@ -206,8 +206,8 @@ class Dialog(QtGui.QDialog, Ui_Dialog): else: QtGui.QMessageBox.warning(self, self.tr("Eliminate"), self.tr("Could not replace geometry of feature with id %1").arg( mergeWithFid )) - return None - + return None + start = start + add progressBar.setValue(start) # end for fid2Eliminate @@ -215,7 +215,7 @@ class Dialog(QtGui.QDialog, Ui_Dialog): # deselect features that are already eliminated in inLayer for aFid in fidsToDeselect: inLayer.deselect(aFid, False) - + #end while if inLayer.selectedFeatureCount() > 0: @@ -232,7 +232,7 @@ class Dialog(QtGui.QDialog, Ui_Dialog): QtGui.QMessageBox.information(self, self.tr("Eliminate"), self.tr("Could not eliminate features with these ids:\n%1").arg(fidList)) - else: + else: QtGui.QMessageBox.warning(self, self.tr("Eliminate"), self.tr("Could not add features")) # stop editing outLayer and commit any pending changes diff --git a/python/plugins/fTools/tools/doGeometry.py b/python/plugins/fTools/tools/doGeometry.py index be73057d023..6b1e0ceae71 100644 --- a/python/plugins/fTools/tools/doGeometry.py +++ b/python/plugins/fTools/tools/doGeometry.py @@ -353,12 +353,9 @@ class geometryThread( QThread ): def single_to_multi( self ): vprovider = self.vlayer.dataProvider() - allAttrs = vprovider.attributeIndexes() - vprovider.select( allAttrs ) - fields = vprovider.fields() allValid = True geomType = self.singleToMultiGeom( vprovider.geometryType() ) - writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields, + writer = QgsVectorFileWriter( self.myName, self.myEncoding, vprovider.fields(), geomType, vprovider.crs() ) inFeat = QgsFeature() outFeat = QgsFeature() @@ -376,12 +373,11 @@ class geometryThread( QThread ): merge_all = self.myField == QString( "--- " + self.tr( "Merge all" ) + " ---" ) if not len( unique ) == self.vlayer.featureCount() or merge_all: for i in unique: - vprovider.rewind() multi_feature= [] first = True - vprovider.select( allAttrs ) - while vprovider.nextFeature( inFeat ): - atMap = inFeat.attributeMap() + fit = vprovider.getFeatures() + while fit.nextFeature( inFeat ): + atMap = inFeat.attributes() if not merge_all: idVar = atMap[ index ] else: @@ -396,7 +392,7 @@ class geometryThread( QThread ): multi_feature.extend( feature_list ) nElement += 1 self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), nElement ) - outFeat.setAttributeMap( atts ) + outFeat.setAttributes( atts ) outGeom = QgsGeometry( self.convertGeometry( multi_feature, vType ) ) if not outGeom.isGeosValid(): allValid = "valid_error" @@ -409,11 +405,8 @@ class geometryThread( QThread ): def multi_to_single( self ): vprovider = self.vlayer.dataProvider() - allAttrs = vprovider.attributeIndexes() - vprovider.select( allAttrs ) - fields = vprovider.fields() geomType = self.multiToSingleGeom( vprovider.geometryType() ) - writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields, + writer = QgsVectorFileWriter( self.myName, self.myEncoding, vprovider.fields(), geomType, vprovider.crs() ) inFeat = QgsFeature() outFeat = QgsFeature() @@ -423,13 +416,14 @@ class geometryThread( QThread ): nElement = 0 self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), 0 ) self.emit( SIGNAL( "runRange( PyQt_PyObject )" ), ( 0, nFeat ) ) - while vprovider.nextFeature( inFeat ): + fit = vprovider.getFeatures() + while fit.nextFeature( inFeat ): nElement += 1 self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), nElement ) inGeom = inFeat.geometry() - atMap = inFeat.attributeMap() + atMap = inFeat.attributes() featList = self.extractAsSingle( inGeom ) - outFeat.setAttributeMap( atMap ) + outFeat.setAttributes( atMap ) for i in featList: outFeat.setGeometry( i ) writer.addFeature( outFeat ) @@ -438,10 +432,7 @@ class geometryThread( QThread ): def extract_nodes( self ): vprovider = self.vlayer.dataProvider() - allAttrs = vprovider.attributeIndexes() - vprovider.select( allAttrs ) - fields = vprovider.fields() - writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields, + writer = QgsVectorFileWriter( self.myName, self.myEncoding, vprovider.fields(), QGis.WKBPoint, vprovider.crs() ) inFeat = QgsFeature() outFeat = QgsFeature() @@ -451,13 +442,14 @@ class geometryThread( QThread ): nElement = 0 self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), 0 ) self.emit( SIGNAL( "runRange( PyQt_PyObject )" ), ( 0, nFeat ) ) - while vprovider.nextFeature( inFeat ): + fit = vprovider.getFeatures() + while fit.nextFeature( inFeat ): nElement += 1 self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), nElement ) inGeom = inFeat.geometry() - atMap = inFeat.attributeMap() + atMap = inFeat.attributes() pointList = ftools_utils.extractPoints( inGeom ) - outFeat.setAttributeMap( atMap ) + outFeat.setAttributes( atMap ) for i in pointList: outFeat.setGeometry( outGeom.fromPoint( i ) ) writer.addFeature( outFeat ) @@ -466,10 +458,7 @@ class geometryThread( QThread ): def polygons_to_lines( self ): vprovider = self.vlayer.dataProvider() - allAttrs = vprovider.attributeIndexes() - vprovider.select( allAttrs ) - fields = vprovider.fields() - writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields, + writer = QgsVectorFileWriter( self.myName, self.myEncoding, vproviders.fields(), QGis.WKBLineString, vprovider.crs() ) inFeat = QgsFeature() outFeat = QgsFeature() @@ -479,16 +468,18 @@ class geometryThread( QThread ): nElement = 0 self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), 0) self.emit( SIGNAL( "runRange( PyQt_PyObject )" ), ( 0, nFeat ) ) - while vprovider.nextFeature( inFeat ): + + fit = vprovider.getFeatures() + while fit.nextFeature( inFeat ): multi = False nElement += 1 self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), nElement ) inGeom = inFeat.geometry() if inGeom.isMultipart(): multi = True - atMap = inFeat.attributeMap() + atMap = inFeat.attributes() lineList = self.extractAsLine( inGeom ) - outFeat.setAttributeMap( atMap ) + outFeat.setAttributes( atMap ) for h in lineList: outFeat.setGeometry( outGeom.fromPolyline( h ) ) writer.addFeature( outFeat ) @@ -497,10 +488,7 @@ class geometryThread( QThread ): def lines_to_polygons( self ): vprovider = self.vlayer.dataProvider() - allAttrs = vprovider.attributeIndexes() - vprovider.select( allAttrs ) - fields = vprovider.fields() - writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields, + writer = QgsVectorFileWriter( self.myName, self.myEncoding, vproviders.fields(), QGis.WKBPolygon, vprovider.crs() ) inFeat = QgsFeature() outFeat = QgsFeature() @@ -509,7 +497,9 @@ class geometryThread( QThread ): nElement = 0 self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), 0) self.emit( SIGNAL( "runRange( PyQt_PyObject )" ), ( 0, nFeat ) ) - while vprovider.nextFeature( inFeat ): + + fit = vprovider.getFeatures() + while fit.nextFeature( inFeat ): outGeomList = [] multi = False nElement += 1 @@ -522,8 +512,8 @@ class geometryThread( QThread ): polyGeom = self.remove_bad_lines( outGeomList ) if len( polyGeom ) <> 0: outFeat.setGeometry( QgsGeometry.fromPolygon( polyGeom ) ) - atMap = inFeat.attributeMap() - outFeat.setAttributeMap( atMap ) + atMap = inFeat.attributes() + outFeat.setAttributes( atMap ) writer.addFeature( outFeat ) del writer return True @@ -552,7 +542,6 @@ class geometryThread( QThread ): nElement = 0 vprovider = self.vlayer.dataProvider() - allAttrs = vprovider.attributeIndexes() self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), 0) self.emit( SIGNAL( "runRange( PyQt_PyObject )" ), ( 0, vprovider.featureCount() ) ) @@ -560,8 +549,8 @@ class geometryThread( QThread ): ( fields, index1, index2 ) = self.checkGeometryFields( self.vlayer ) writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields, vprovider.geometryType(), vprovider.crs() ) - vprovider.select( allAttrs ) - while vprovider.nextFeature(inFeat): + fit = vprovider.getFeatures() + while fit.nextFeature(inFeat): self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), nElement ) nElement += 1 inGeom = inFeat.geometry() @@ -572,8 +561,8 @@ class geometryThread( QThread ): ( attr1, attr2 ) = self.simpleMeasure( inGeom, self.myCalcType, ellips, crs ) outFeat.setGeometry( inGeom ) - atMap = inFeat.attributeMap() - outFeat.setAttributeMap( atMap ) + atMap = inFeat.attributes() + outFeat.setAttributes( atMap ) outFeat.addAttribute( index1, QVariant( attr1 ) ) outFeat.addAttribute( index2, QVariant( attr2 ) ) writer.addFeature( outFeat ) @@ -582,8 +571,8 @@ class geometryThread( QThread ): else: # update existing file ( index1, index2 ) = self.findOrCreateFields( self.vlayer ) - vprovider.select( allAttrs ) - while vprovider.nextFeature(inFeat): + fit = vprovider.getFeatures() + while fit.nextFeature(inFeat): self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), nElement ) nElement += 1 inGeom = inFeat.geometry() @@ -601,10 +590,7 @@ class geometryThread( QThread ): def polygon_centroids( self ): vprovider = self.vlayer.dataProvider() - allAttrs = vprovider.attributeIndexes() - vprovider.select( allAttrs ) - fields = vprovider.fields() - writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields, + writer = QgsVectorFileWriter( self.myName, self.myEncoding, vprovider.fields(), QGis.WKBPoint, vprovider.crs() ) inFeat = QgsFeature() outFeat = QgsFeature() @@ -612,15 +598,16 @@ class geometryThread( QThread ): nElement = 0 self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), 0 ) self.emit( SIGNAL( "runRange( PyQt_PyObject )" ), ( 0, nFeat ) ) - while vprovider.nextFeature( inFeat ): + fit = vprovider.getFeatures() + while fit.nextFeature( inFeat ): nElement += 1 self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), nElement ) inGeom = inFeat.geometry() - atMap = inFeat.attributeMap() + atMap = inFeat.attributes() outGeom = inGeom.centroid() if outGeom is None: return "math_error" - outFeat.setAttributeMap( atMap ) + outFeat.setAttributes( atMap ) outFeat.setGeometry( QgsGeometry( outGeom ) ) writer.addFeature( outFeat ) del writer @@ -630,11 +617,9 @@ class geometryThread( QThread ): import voronoi from sets import Set vprovider = self.vlayer.dataProvider() - allAttrs = vprovider.attributeIndexes() - vprovider.select( allAttrs ) - fields = { 0 : QgsField( "POINTA", QVariant.Double ), - 1 : QgsField( "POINTB", QVariant.Double ), - 2 : QgsField( "POINTC", QVariant.Double ) } + fields = [ QgsField( "POINTA", QVariant.Double ), + QgsField( "POINTB", QVariant.Double ), + QgsField( "POINTC", QVariant.Double ) ] writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields, QGis.WKBPolygon, vprovider.crs() ) inFeat = QgsFeature() @@ -642,7 +627,8 @@ class geometryThread( QThread ): pts = [] ptDict = {} ptNdx = -1 - while vprovider.nextFeature( inFeat ): + fit = vprovider.getFeatures() + while fit.nextFeature( inFeat ): geom = QgsGeometry( inFeat.geometry() ) point = geom.asPoint() x = point.x() @@ -669,7 +655,7 @@ class geometryThread( QThread ): polygon = [] step = 0 for index in indicies: - vprovider.featureAtId( ptDict[ ids[ index ] ], inFeat, True, allAttrs ) + vprovider.getFeatures( QgsFeatureRequest().setFilterFid( ptDict[ ids[ index ] ] ) ).nextFeature( inFeat ) geom = QgsGeometry( inFeat.geometry() ) point = QgsPoint( geom.asPoint() ) polygon.append( point ) @@ -685,8 +671,6 @@ class geometryThread( QThread ): def voronoi_polygons( self ): vprovider = self.vlayer.dataProvider() - allAttrs = vprovider.attributeIndexes() - vprovider.select( allAttrs ) writer = QgsVectorFileWriter( self.myName, self.myEncoding, vprovider.fields(), QGis.WKBPolygon, vprovider.crs() ) inFeat = QgsFeature() @@ -700,7 +684,8 @@ class geometryThread( QThread ): pts = [] ptDict = {} ptNdx = -1 - while vprovider.nextFeature( inFeat ): + fit = vprovider.getFeatures() + while fit.nextFeature( inFeat ): geom = QgsGeometry( inFeat.geometry() ) point = geom.asPoint() x = point.x() - extent.xMinimum() @@ -721,12 +706,12 @@ class geometryThread( QThread ): self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), 0 ) self.emit( SIGNAL( "runRange( PyQt_PyObject )" ), ( 0, nFeat ) ) for site, edges in c.polygons.iteritems(): - vprovider.featureAtId( ptDict[ ids[ site ] ], inFeat, True, allAttrs ) + vprovider.getFeatures( QgsFeatureRequest().setFilterFid( ptDict[ ids[ site ] ] ) ).nextFeature( inFeat ) lines = self.clip_voronoi( edges, c, width, height, extent, extraX, extraY ) geom = QgsGeometry.fromMultiPoint( lines ) geom = QgsGeometry( geom.convexHull() ) outFeat.setGeometry( geom ) - outFeat.setAttributeMap( inFeat.attributeMap() ) + outFeat.setAttributes( inFeat.attributes() ) writer.addFeature( outFeat ) nElement += 1 self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), nElement ) @@ -829,16 +814,16 @@ class geometryThread( QThread ): def layer_extent( self ): self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), 0 ) self.emit( SIGNAL( "runRange( PyQt_PyObject )" ), ( 0, 0 ) ) - fields = { 0 : QgsField( "MINX", QVariant.Double ), - 1 : QgsField( "MINY", QVariant.Double ), - 2 : QgsField( "MAXX", QVariant.Double ), - 3 : QgsField( "MAXY", QVariant.Double ), - 4 : QgsField( "CNTX", QVariant.Double ), - 5 : QgsField( "CNTY", QVariant.Double ), - 6 : QgsField( "AREA", QVariant.Double ), - 7 : QgsField( "PERIM", QVariant.Double ), - 8 : QgsField( "HEIGHT", QVariant.Double ), - 9 : QgsField( "WIDTH", QVariant.Double ) } + 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 ) ] writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields, QGis.WKBPolygon, self.vlayer.crs() ) @@ -861,16 +846,16 @@ class geometryThread( QThread ): geometry = QgsGeometry().fromPolygon( [ rect ] ) feat = QgsFeature() feat.setGeometry( geometry ) - feat.setAttributeMap( { 0 : QVariant( minx ), - 1 : QVariant( miny ), - 2 : QVariant( maxx ), - 3 : QVariant( maxy ), - 4 : QVariant( cntx ), - 5 : QVariant( cnty ), - 6 : QVariant( area ), - 7 : QVariant( perim ), - 8 : QVariant( height ), - 9 : QVariant( width ) } ) + feat.setAttributes( [ QVariant( minx ), + QVariant( miny ), + QVariant( maxx ), + QVariant( maxy ), + QVariant( cntx ), + QVariant( cnty ), + QVariant( area ), + QVariant( perim ), + QVariant( height ), + QVariant( width ) ] ) writer.addFeature( feat ) self.emit( SIGNAL( "runRange( PyQt_PyObject )" ), ( 0, 100 ) ) self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), 0 ) @@ -926,20 +911,21 @@ class geometryThread( QThread ): geometry = QgsGeometry().fromPolygon( [ rect ] ) outFeat.setGeometry( geometry ) - outFeat.setAttributeMap( { 0 : QVariant( minx ), - 1 : QVariant( miny ), - 2 : QVariant( maxx ), - 3 : QVariant( maxy ), - 4 : QVariant( cntx ), - 5 : QVariant( cnty ), - 6 : QVariant( area ), - 7 : QVariant( perim ), - 8 : QVariant( height ), - 9 : QVariant( width ) } ) + outFeat.setAttributes( [ QVariant( minx ), + QVariant( miny ), + QVariant( maxx ), + QVariant( maxy ), + QVariant( cntx ), + QVariant( cnty ), + QVariant( area ), + QVariant( perim ), + QVariant( height ), + QVariant( width ) ] ) writer.addFeature( outFeat ) else: self.emit( SIGNAL( "runRange( PyQt_PyObject )" ), ( 0, vprovider.featureCount() ) ) - while vprovider.nextFeature( inFeat ): + fit = vprovider.getFeatures() + while fit.nextFeature( inFeat ): self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), nElement ) nElement += 1 @@ -962,16 +948,16 @@ class geometryThread( QThread ): geometry = QgsGeometry().fromPolygon( [ rect ] ) outFeat.setGeometry( geometry ) - outFeat.setAttributeMap( { 0 : QVariant( minx ), - 1 : QVariant( miny ), - 2 : QVariant( maxx ), - 3 : QVariant( maxy ), - 4 : QVariant( cntx ), - 5 : QVariant( cnty ), - 6 : QVariant( area ), - 7 : QVariant( perim ), - 8 : QVariant( height ), - 9 : QVariant( width ) } ) + outFeat.setAttributes( [ QVariant( minx ), + QVariant( miny ), + QVariant( maxx ), + QVariant( maxy ), + QVariant( cntx ), + QVariant( cnty ), + QVariant( area ), + QVariant( perim ), + QVariant( height ), + QVariant( width ) ] ) writer.addFeature( outFeat ) del writer diff --git a/python/plugins/fTools/tools/doGeoprocessing.py b/python/plugins/fTools/tools/doGeoprocessing.py index 64796b84328..edbaca71d02 100644 --- a/python/plugins/fTools/tools/doGeoprocessing.py +++ b/python/plugins/fTools/tools/doGeoprocessing.py @@ -323,11 +323,8 @@ class geoprocessingThread( QThread ): GEOS_EXCEPT = True FEATURE_EXCEPT = True vproviderA = self.vlayerA.dataProvider() - allAttrs = vproviderA.attributeIndexes() - vproviderA.select( allAttrs ) - fields = vproviderA.fields() - writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields, + writer = QgsVectorFileWriter( self.myName, self.myEncoding, vproviderA.fields(), QGis.WKBPolygon, vproviderA.crs() ) # check if writer was created properly, if not, return with error if writer.hasError(): @@ -349,7 +346,7 @@ class geoprocessingThread( QThread ): if self.myMerge: first = True for inFeat in selectionA: - atMap = inFeat.attributeMap() + atMap = inFeat.attributes() if useField: value = atMap[ self.myParam ].doDouble()[ 0 ] else: @@ -379,7 +376,7 @@ class geoprocessingThread( QThread ): # without dissolve else: for inFeat in selectionA: - atMap = inFeat.attributeMap() + atMap = inFeat.attributes() if useField: value = atMap[ self.myParam ].toDouble()[ 0 ] else: @@ -389,7 +386,7 @@ class geoprocessingThread( QThread ): outGeom = inGeom.buffer( float( value ), self.mySegments ) try: outFeat.setGeometry( outGeom ) - outFeat.setAttributeMap( atMap ) + outFeat.setAttributes( atMap ) writer.addFeature( outFeat ) except: FEATURE_EXCEPT = False @@ -407,8 +404,9 @@ class geoprocessingThread( QThread ): # with dissolve if self.myMerge: first = True - while vproviderA.nextFeature( inFeat ): - atMap = inFeat.attributeMap() + fit = vproviderA.getFeatures() + while fit.nextFeature( inFeat ): + atMap = inFeat.attributes() if useField: value = atMap[ self.myParam ].toDouble()[ 0 ] else: @@ -437,8 +435,9 @@ class geoprocessingThread( QThread ): FEATURE_EXCEPT = False # without dissolve else: - while vproviderA.nextFeature( inFeat ): - atMap = inFeat.attributeMap() + fit = vproviderA.getFeatures() + while fit.nextFeature( inFeat ): + atMap = inFeat.attributes() if useField: value = atMap[ self.myParam ].toDouble()[ 0 ] else: @@ -448,7 +447,7 @@ class geoprocessingThread( QThread ): outGeom = inGeom.buffer( float( value ), self.mySegments ) try: outFeat.setGeometry( outGeom ) - outFeat.setAttributeMap( atMap ) + outFeat.setAttributes( atMap ) writer.addFeature( outFeat ) except: FEATURE_EXCEPT = False @@ -465,10 +464,7 @@ class geoprocessingThread( QThread ): GEOS_EXCEPT = True FEATURE_EXCEPT = True vproviderA = self.vlayerA.dataProvider() - allAttrsA = vproviderA.attributeIndexes() - vproviderA.select(allAttrsA) - fields = vproviderA.fields() - writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields, + writer = QgsVectorFileWriter( self.myName, self.myEncoding, vprovider.fields(), QGis.WKBPolygon, vproviderA.crs() ) if writer.hasError(): return GEOS_EXCEPT, FEATURE_EXCEPT, True, writer.errorMessage() @@ -494,7 +490,7 @@ class geoprocessingThread( QThread ): outID = 0 vproviderA.rewind() for inFeat in selectionA: - atMap = inFeat.attributeMap() + atMap = inFeat.attributes() idVar = atMap[ self.myParam ] if idVar.toString().trimmed() == i.toString().trimmed(): if first: @@ -547,9 +543,10 @@ class geoprocessingThread( QThread ): hull = [] first = True outID = 0 - vproviderA.rewind() - while vproviderA.nextFeature( inFeat ): - atMap = inFeat.attributeMap() + + fitA = vproviderA.getFeatures() + while fitA.nextFeature( inFeat ): + atMap = inFeat.attributes() idVar = atMap[ self.myParam ] if idVar.toString().trimmed() == i.toString().trimmed(): if first: @@ -577,7 +574,8 @@ class geoprocessingThread( QThread ): self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 ) self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) ) hull = [] - while vproviderA.nextFeature( inFeat ): + fitA = vproviderA.getFeatures() + while fitA.nextFeature( inFeat ): inGeom = QgsGeometry( inFeat.geometry() ) points = ftools_utils.extractPoints( inGeom ) hull.extend( points ) @@ -597,10 +595,8 @@ class geoprocessingThread( QThread ): GEOS_EXCEPT = True FEATURE_EXCEPT = True vproviderA = self.vlayerA.dataProvider() - allAttrsA = vproviderA.attributeIndexes() - fields = vproviderA.fields() - writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields, + writer = QgsVectorFileWriter( self.myName, self.myEncoding, vproviderA.fields(), vproviderA.geometryType(), vproviderA.crs() ) if writer.hasError(): return GEOS_EXCEPT, FEATURE_EXCEPT, True, writer.errorMessage() @@ -610,9 +606,6 @@ class geoprocessingThread( QThread ): nElement = 0 attrs = None - vproviderA.rewind() - vproviderA.select( allAttrsA ) - # there is selection in input layer if self.mySelectionA: nFeat = self.vlayerA.selectedFeatureCount() @@ -625,7 +618,7 @@ class geoprocessingThread( QThread ): nElement += 1 self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement ) if first: - attrs = inFeat.attributeMap() + attrs = inFeat.attributes() tmpInGeom = QgsGeometry( inFeat.geometry() ) outFeat.setGeometry( tmpInGeom ) first = False @@ -638,7 +631,7 @@ class geoprocessingThread( QThread ): except: GEOS_EXCEPT = False continue - outFeat.setAttributeMap( attrs ) + outFeat.setAttributes( attrs ) writer.addFeature( outFeat ) else: self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0) @@ -650,7 +643,7 @@ class geoprocessingThread( QThread ): for inFeat in selectionA: nElement += 1 self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement ) - atMap = inFeat.attributeMap() + atMap = inFeat.attributes() tempItem = unicode(atMap[self.myParam].toString().trimmed()) if not (tempItem in outFeats): @@ -664,7 +657,7 @@ class geoprocessingThread( QThread ): continue for k in outFeats.keys(): feature = QgsFeature() - feature.setAttributeMap(attrs[k]) + feature.setAttributes(attrs[k]) feature.setGeometry(outFeats[k]) writer.addFeature( feature ) # there is no selection in input layer @@ -674,11 +667,12 @@ class geoprocessingThread( QThread ): self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0) self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) ) first = True - while vproviderA.nextFeature( inFeat ): + fitA = vproviderA.getFeatures() + while fitA.nextFeature( inFeat ): nElement += 1 self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement ) if first: - attrs = inFeat.attributeMap() + attrs = inFeat.attributes() tmpInGeom = QgsGeometry( inFeat.geometry() ) outFeat.setGeometry( tmpInGeom ) first = False @@ -691,7 +685,7 @@ class geoprocessingThread( QThread ): except: GEOS_EXCEPT = False continue - outFeat.setAttributeMap( attrs ) + outFeat.setAttributes( attrs ) writer.addFeature( outFeat ) else: self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0) @@ -700,10 +694,11 @@ class geoprocessingThread( QThread ): outFeats = {} attrs = {} - while vproviderA.nextFeature( inFeat ): + fitA = vproviderA.getFeatures() + while fitA.nextFeature( inFeat ): nElement += 1 self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement ) - atMap = inFeat.attributeMap() + atMap = inFeat.attributes() tempItem = unicode(atMap[self.myParam].toString().trimmed()) if not (tempItem in outFeats): @@ -717,7 +712,7 @@ class geoprocessingThread( QThread ): continue for k in outFeats.keys(): feature = QgsFeature() - feature.setAttributeMap(attrs[k]) + feature.setAttributes(attrs[k]) feature.setGeometry(outFeats[k]) writer.addFeature( feature ) del writer @@ -727,12 +722,7 @@ class geoprocessingThread( QThread ): GEOS_EXCEPT = True FEATURE_EXCEPT = True vproviderA = self.vlayerA.dataProvider() - allAttrsA = vproviderA.attributeIndexes() - vproviderA.select( allAttrsA ) vproviderB = self.vlayerB.dataProvider() - allAttrsB = vproviderB.attributeIndexes() - vproviderB.select( allAttrsB ) - fields = vproviderA.fields() # check for crs compatibility crsA = vproviderA.crs() @@ -742,7 +732,7 @@ class geoprocessingThread( QThread ): else: crs_match = crsA == crsB - writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields, + writer = QgsVectorFileWriter( self.myName, self.myEncoding, vproviderA.fields(), vproviderA.geometryType(), vproviderA.crs() ) if writer.hasError(): return GEOS_EXCEPT, FEATURE_EXCEPT, crs_match, writer.errorMessage() @@ -753,8 +743,6 @@ class geoprocessingThread( QThread ): nElement = 0 index = ftools_utils.createIndex( vproviderB ) - vproviderB.rewind() - vproviderB.select( allAttrsB ) # there is selection in input layer if self.mySelectionA: @@ -771,12 +759,12 @@ class geoprocessingThread( QThread ): add = True geom = QgsGeometry( inFeatA.geometry() ) diff_geom = QgsGeometry( geom ) - atMap = inFeatA.attributeMap() + atMap = inFeatA.attributes() intersects = index.intersects( geom.boundingBox() ) for id in intersects: # is intersect feature in selection if id in selectionB: - vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB ) + vproviderB.getFeatures( QgsFeatureRequest().setFilterFid( int( id ) ) ).nextFeature( inFeatB ) tmpGeom = QgsGeometry( inFeatB.geometry() ) try: if diff_geom.intersects( tmpGeom ): @@ -788,7 +776,7 @@ class geoprocessingThread( QThread ): if add: try: outFeat.setGeometry( diff_geom ) - outFeat.setAttributeMap( atMap ) + outFeat.setAttributes( atMap ) writer.addFeature( outFeat ) except: FEATURE_EXCEPT = False @@ -801,10 +789,10 @@ class geoprocessingThread( QThread ): add = True geom = QgsGeometry( inFeatA.geometry() ) diff_geom = QgsGeometry( geom ) - atMap = inFeatA.attributeMap() + atMap = inFeatA.attributes() intersects = index.intersects( geom.boundingBox() ) for id in intersects: - vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB ) + vproviderB.getFeatures( QgsFeatureRequest().setFilterFid( int( id ) ) ).nextFeature( inFeatB ) tmpGeom = QgsGeometry( inFeatB.geometry() ) try: if diff_geom.intersects( tmpGeom ): @@ -816,7 +804,7 @@ class geoprocessingThread( QThread ): if add: try: outFeat.setGeometry( diff_geom ) - outFeat.setAttributeMap( atMap ) + outFeat.setAttributes( atMap ) writer.addFeature( outFeat ) except: FEATURE_EXCEPT = False @@ -826,23 +814,22 @@ class geoprocessingThread( QThread ): nFeat = vproviderA.featureCount() self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 ) self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) ) - vproviderA.rewind() - vproviderA.select( allAttrsA ) # we have selection in overlay layer if self.mySelectionB: selectionB = self.vlayerB.selectedFeaturesIds() - while vproviderA.nextFeature( inFeatA ): + fitA = vproviderA.getFeatures() + while fitA.nextFeature( inFeatA ): nElement += 1 add = True self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement ) geom = QgsGeometry( inFeatA.geometry() ) diff_geom = QgsGeometry( geom ) - atMap = inFeatA.attributeMap() + atMap = inFeatA.attributes() intersects = index.intersects( geom.boundingBox() ) for id in intersects: # now check if id in selection if id in selectionB: - vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB ) + vproviderB.getFeatures( QgsFeatureRequest().setFilterFid( int( id ) ) ).nextFeature( inFeatB ) tmpGeom = QgsGeometry( inFeatB.geometry() ) try: if diff_geom.intersects( tmpGeom ): @@ -854,23 +841,24 @@ class geoprocessingThread( QThread ): if add: try: outFeat.setGeometry( diff_geom ) - outFeat.setAttributeMap( atMap ) + outFeat.setAttributes( atMap ) writer.addFeature( outFeat ) except: FEATURE_EXCEPT = False continue # we have no selection in overlay layer else: - while vproviderA.nextFeature( inFeatA ): + fitA = vproviderA.getFeatures() + while fitA.nextFeature( inFeatA ): nElement += 1 add = True self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement ) geom = QgsGeometry( inFeatA.geometry() ) diff_geom = QgsGeometry( geom ) - atMap = inFeatA.attributeMap() + atMap = inFeatA.attributes() intersects = index.intersects( geom.boundingBox() ) for id in intersects: - vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB ) + vproviderB.getFeatures( QgsFeatureRequest().setFilterFid( int( id ) ) ).nextFeature( inFeatB ) tmpGeom = QgsGeometry( inFeatB.geometry() ) try: if diff_geom.intersects( tmpGeom ): @@ -882,7 +870,7 @@ class geoprocessingThread( QThread ): if add: try: outFeat.setGeometry( diff_geom ) - outFeat.setAttributeMap( atMap ) + outFeat.setAttributes( atMap ) writer.addFeature( outFeat ) except: FEATURE_EXCEPT = False @@ -894,11 +882,7 @@ class geoprocessingThread( QThread ): GEOS_EXCEPT = True FEATURE_EXCEPT = True vproviderA = self.vlayerA.dataProvider() - allAttrsA = vproviderA.attributeIndexes() - vproviderA.select( allAttrsA ) vproviderB = self.vlayerB.dataProvider() - allAttrsB = vproviderB.attributeIndexes() - vproviderB.select( allAttrsB ) # check for crs compatibility crsA = vproviderA.crs() @@ -925,8 +909,6 @@ class geoprocessingThread( QThread ): nElement = 0 index = ftools_utils.createIndex( vproviderB ) - vproviderB.rewind() - vproviderB.select( allAttrsB ) # there is selection in input layer if self.mySelectionA: @@ -941,15 +923,15 @@ class geoprocessingThread( QThread ): nElement += 1 self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement ) geom = QgsGeometry( inFeatA.geometry() ) - atMapA = inFeatA.attributeMap() + atMapA = inFeatA.attributes() intersects = index.intersects( geom.boundingBox() ) for id in intersects: if id in selectionB: - vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB ) + vproviderB.getFeatures( QgsFeatureRequest().setFilterFid( int( id ) ) ).nextFeature( inFeatB ) tmpGeom = QgsGeometry( inFeatB.geometry() ) try: if geom.intersects( tmpGeom ): - atMapB = inFeatB.attributeMap() + atMapB = inFeatB.attributes() int_geom = QgsGeometry( geom.intersection( tmpGeom ) ) if int_geom.wkbType() == 0: int_com = geom.combine( tmpGeom ) @@ -963,7 +945,7 @@ class geoprocessingThread( QThread ): gList = ftools_utils.getGeomType( geom.wkbType() ) if int_geom.wkbType() in gList: outFeat.setGeometry( int_geom ) - outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) ) + outFeat.setAttributes( atMapA.extend( atMapB ) ) writer.addFeature( outFeat ) except: FEATURE_EXCEPT = False @@ -977,14 +959,14 @@ class geoprocessingThread( QThread ): nElement += 1 self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement ) geom = QgsGeometry( inFeatA.geometry() ) - atMapA = inFeatA.attributeMap() + atMapA = inFeatA.attributes() intersects = index.intersects( geom.boundingBox() ) for id in intersects: - vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB ) + vproviderB.getFeatures( QgsFeatureRequest().setFilterFid( int( id ) ) ).nextFeature( inFeatB ) tmpGeom = QgsGeometry( inFeatB.geometry() ) try: if geom.intersects( tmpGeom ): - atMapB = inFeatB.attributeMap() + atMapB = inFeatB.attributes() int_geom = QgsGeometry( geom.intersection( tmpGeom ) ) if int_geom.wkbType() == 0: int_com = geom.combine( tmpGeom ) @@ -994,7 +976,7 @@ class geoprocessingThread( QThread ): gList = ftools_utils.getGeomType( geom.wkbType() ) if int_geom.wkbType() in gList: outFeat.setGeometry( int_geom ) - outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) ) + outFeat.setAttributes( atMapA.extend( atMapB ) ) writer.addFeature( outFeat ) except: EATURE_EXCEPT = False @@ -1007,24 +989,23 @@ class geoprocessingThread( QThread ): nFeat = vproviderA.featureCount() self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0) self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) ) - vproviderA.rewind() - vproviderA.select( allAttrsA ) # we have selection in overlay layer if self.mySelectionB: selectionB = self.vlayerB.selectedFeaturesIds() - while vproviderA.nextFeature( inFeatA ): + fitA = vproviderA.getFeatures() + while fitA.nextFeature( inFeatA ): nElement += 1 self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement ) geom = QgsGeometry( inFeatA.geometry() ) - atMapA = inFeatA.attributeMap() + atMapA = inFeatA.attributes() intersects = index.intersects( geom.boundingBox() ) for id in intersects: if id in selectionB: - vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB ) + vproviderB.getFeatures( QgsFeatureRequest().setFilterFid( int( id ) ) ).nextFeature( inFeatB ) tmpGeom = QgsGeometry( inFeatB.geometry() ) try: if geom.intersects( tmpGeom ): - atMapB = inFeatB.attributeMap() + atMapB = inFeatB.attributes() int_geom = QgsGeometry( geom.intersection( tmpGeom ) ) if int_geom.wkbType() == 0: int_com = geom.combine( tmpGeom ) @@ -1034,7 +1015,7 @@ class geoprocessingThread( QThread ): gList = ftools_utils.getGeomType( geom.wkbType() ) if int_geom.wkbType() in gList: outFeat.setGeometry( int_geom ) - outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) ) + outFeat.setAttributes( atMapA.extend( atMapB ) ) writer.addFeature( outFeat ) except: FEATURE_EXCEPT = False @@ -1044,18 +1025,19 @@ class geoprocessingThread( QThread ): break # we have no selection in overlay layer else: - while vproviderA.nextFeature( inFeatA ): + fitA = vproviderA.getFeatures() + while fita.nextFeature( inFeatA ): nElement += 1 self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement ) geom = QgsGeometry( inFeatA.geometry() ) - atMapA = inFeatA.attributeMap() + atMapA = inFeatA.attributes() intersects = index.intersects( geom.boundingBox() ) for id in intersects: - vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB ) + vproviderB.getFeatures( QgsFeatureRequest().setFilterFid( int( id ) ) ).nextFeature( inFeatB ) tmpGeom = QgsGeometry( inFeatB.geometry() ) try: if geom.intersects( tmpGeom ): - atMapB = inFeatB.attributeMap() + atMapB = inFeatB.attributes() int_geom = QgsGeometry( geom.intersection( tmpGeom ) ) if int_geom.wkbType() == 0: int_com = geom.combine( tmpGeom ) @@ -1065,7 +1047,7 @@ class geoprocessingThread( QThread ): gList = ftools_utils.getGeomType( geom.wkbType() ) if int_geom.wkbType() in gList: outFeat.setGeometry( int_geom ) - outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) ) + outFeat.setAttributes( atMapA.extend( atMapB ) ) writer.addFeature( outFeat ) except: FEATURE_EXCEPT = False @@ -1080,11 +1062,7 @@ class geoprocessingThread( QThread ): GEOS_EXCEPT = True FEATURE_EXCEPT = True vproviderA = self.vlayerA.dataProvider() - allAttrsA = vproviderA.attributeIndexes() - vproviderA.select( allAttrsA ) vproviderB = self.vlayerB.dataProvider() - allAttrsB = vproviderB.attributeIndexes() - vproviderB.select( allAttrsB ) # check for crs compatibility crsA = vproviderA.crs() @@ -1110,10 +1088,6 @@ class geoprocessingThread( QThread ): outFeat = QgsFeature() indexA = ftools_utils.createIndex( vproviderB ) indexB = ftools_utils.createIndex( vproviderA ) - vproviderA.rewind() - vproviderA.select( allAttrsA ) - vproviderB.rewind() - vproviderB.select(allAttrsB) nFeat = vproviderA.featureCount() * vproviderB.featureCount() self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0) @@ -1122,18 +1096,19 @@ class geoprocessingThread( QThread ): count = 0 nElement = 0 - while vproviderA.nextFeature( inFeatA ): + fitA = vproviderA.getFeatures() + while fit.nextFeature( inFeatA ): self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement ) nElement += 1 found = False geom = QgsGeometry( inFeatA.geometry() ) diff_geom = QgsGeometry( geom ) - atMapA = inFeatA.attributeMap() + atMapA = inFeatA.attributes() intersects = indexA.intersects( geom.boundingBox() ) if len( intersects ) < 1: try: outFeat.setGeometry( geom ) - outFeat.setAttributeMap( atMapA ) + outFeat.setAttributes( atMapA ) writer.addFeature( outFeat ) except: # this really shouldn't happen, as we @@ -1142,8 +1117,8 @@ class geoprocessingThread( QThread ): else: for id in intersects: count += 1 - vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB ) - atMapB = inFeatB.attributeMap() + vproviderB.getFeatures( QgsFeatureRequest().setFilterFid( int( id ) ) ).nextFeature( inFeatB ) + atMapB = inFeatB.attributes() tmpGeom = QgsGeometry( inFeatB.geometry() ) try: if geom.intersects( tmpGeom ): @@ -1173,7 +1148,7 @@ class geoprocessingThread( QThread ): int_geom = QgsGeometry( i ) try: outFeat.setGeometry( int_geom ) - outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) ) + outFeat.setAttributes( atMapA.extend( atMapB ) ) writer.addFeature( outFeat ) except Exception, err: FEATURE_EXCEPT = False @@ -1186,7 +1161,7 @@ class geoprocessingThread( QThread ): if int_geom.wkbType() in gList: try: outFeat.setGeometry( int_geom ) - outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) ) + outFeat.setAttributes( atMapA.extend( atMapB ) ) writer.addFeature( outFeat ) except Exception, err: FEATURE_EXCEPT = False @@ -1195,7 +1170,7 @@ class geoprocessingThread( QThread ): # intersects, but the geometry doesn't try: outFeat.setGeometry( geom ) - outFeat.setAttributeMap( atMapA ) + outFeat.setAttributes( atMapA ) writer.addFeature( outFeat ) except: # also shoudn't ever happen @@ -1212,33 +1187,32 @@ class geoprocessingThread( QThread ): if i.type() == geom.type(): diff_geom = QgsGeometry( i ) outFeat.setGeometry( diff_geom ) - outFeat.setAttributeMap( atMapA ) + outFeat.setAttributes( atMapA ) writer.addFeature( outFeat ) except Exception, err: FEATURE_EXCEPT = False length = len( vproviderA.fields().values() ) - vproviderB.rewind() - vproviderB.select(allAttrsB) - while vproviderB.nextFeature( inFeatA ): + fitB = vproviderB.getFeatures() + while fitB.nextFeature( inFeatA ): add = False geom = QgsGeometry( inFeatA.geometry() ) diff_geom = QgsGeometry( geom ) - atMap = inFeatA.attributeMap().values() + atMap = inFeatA.attributes() atMap = dict( zip( range( length, length + len( atMap ) ), atMap ) ) intersects = indexB.intersects( geom.boundingBox() ) if len(intersects) < 1: try: outFeat.setGeometry( geom ) - outFeat.setAttributeMap( atMap ) + outFeat.setAttributes( atMap ) writer.addFeature( outFeat ) except Exception, err: FEATURE_EXCEPT = False else: for id in intersects: - vproviderA.featureAtId( int( id ), inFeatB , True, allAttrsA ) + vproviderB.getFeatures( QgsFeatureRequest().setFilterFid( int( id ) ) ).nextFeature( inFeatB ) tmpGeom = QgsGeometry( inFeatB.geometry() ) try: @@ -1249,7 +1223,7 @@ class geoprocessingThread( QThread ): # this only happends if the bounding box # intersects, but the geometry doesn't outFeat.setGeometry( diff_geom ) - outFeat.setAttributeMap( atMap ) + outFeat.setAttributes( atMap ) writer.addFeature( outFeat ) except Exception, err: add = False @@ -1258,7 +1232,7 @@ class geoprocessingThread( QThread ): if add: try: outFeat.setGeometry( diff_geom ) - outFeat.setAttributeMap( atMap ) + outFeat.setAttributes( atMap ) writer.addFeature( outFeat ) except Exception, err: FEATURE_EXCEPT = False @@ -1271,12 +1245,6 @@ class geoprocessingThread( QThread ): def symetrical_difference( self ): GEOS_EXCEPT = True FEATURE_EXCEPT = True - vproviderA = self.vlayerA.dataProvider() - allAttrsA = vproviderA.attributeIndexes() - vproviderA.select( allAttrsA ) - vproviderB = self.vlayerB.dataProvider() - allAttrsB = vproviderB.attributeIndexes() - vproviderB.select( allAttrsB ) # check for crs compatibility crsA = vproviderA.crs() @@ -1303,25 +1271,22 @@ class geoprocessingThread( QThread ): indexA = ftools_utils.createIndex( vproviderB ) indexB = ftools_utils.createIndex( vproviderA ) - vproviderA.rewind() - vproviderA.select( allAttrsA ) - vproviderB.rewind() - vproviderB.select(allAttrsB) nFeat = vproviderA.featureCount() * vproviderB.featureCount() nElement = 0 self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0) self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) ) - while vproviderA.nextFeature( inFeatA ): + fitA = vproviderA.getFeatures() + while fitA.nextFeature( inFeatA ): nElement += 1 self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement ) add = True geom = QgsGeometry( inFeatA.geometry() ) diff_geom = QgsGeometry( geom ) - atMapA = inFeatA.attributeMap() + atMapA = inFeatA.attributes() intersects = indexA.intersects( geom.boundingBox() ) for id in intersects: - vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB ) + vproviderB.getFeatures( QgsFeatureRequest().setFilterFid( int( id ) ) ).nextFeature( inFeatB ) tmpGeom = QgsGeometry( inFeatB.geometry() ) try: if diff_geom.intersects( tmpGeom ): @@ -1333,27 +1298,26 @@ class geoprocessingThread( QThread ): if add: try: outFeat.setGeometry( diff_geom ) - outFeat.setAttributeMap( atMapA ) + outFeat.setAttributes( atMapA ) writer.addFeature( outFeat ) except: FEATURE_EXCEPT = False continue - length = len( vproviderA.fields().values() ) - vproviderB.rewind() - vproviderB.select(allAttrsB) + length = len( vproviderA.fields() ) - while vproviderB.nextFeature( inFeatA ): + fitB = vproviderB.getFeatures() + while fitB.nextFeature( inFeatA ): nElement += 1 self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement ) add = True geom = QgsGeometry( inFeatA.geometry() ) diff_geom = QgsGeometry( geom ) - atMap = inFeatA.attributeMap().values() + atMap = inFeatA.attributes() atMap = dict( zip( range( length, length + len( atMap ) ), atMap ) ) intersects = indexB.intersects( geom.boundingBox() ) for id in intersects: - vproviderA.featureAtId( int( id ), inFeatB , True, allAttrsA ) + vproviderA.getFeatures( QgsFeatureRequest().setFilterFid( int( id ) ) ).nextFeature( inFeatB ) tmpGeom = QgsGeometry( inFeatB.geometry() ) try: if diff_geom.intersects( tmpGeom ): @@ -1365,7 +1329,7 @@ class geoprocessingThread( QThread ): if add: try: outFeat.setGeometry( diff_geom ) - outFeat.setAttributeMap( atMap ) + outFeat.setAttributes( atMap ) writer.addFeature( outFeat ) except: FEATURE_EXCEPT = False @@ -1376,12 +1340,6 @@ class geoprocessingThread( QThread ): def clip( self ): GEOS_EXCEPT = True FEATURE_EXCEPT = True - vproviderA = self.vlayerA.dataProvider() - allAttrsA = vproviderA.attributeIndexes() - vproviderA.select( allAttrsA ) - vproviderB = self.vlayerB.dataProvider() - allAttrsB = vproviderB.attributeIndexes() - vproviderB.select( allAttrsB ) # check for crs compatibility crsA = vproviderA.crs() @@ -1391,8 +1349,7 @@ class geoprocessingThread( QThread ): else: crs_match = crsA == crsB - fields = vproviderA.fields() - writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields, + writer = QgsVectorFileWriter( self.myName, self.myEncoding, vproviderA.fields(), vproviderA.geometryType(), vproviderA.crs() ) if writer.hasError(): return GEOS_EXCEPT, FEATURE_EXCEPT, crs_match, writer.errorMessage() @@ -1402,10 +1359,7 @@ class geoprocessingThread( QThread ): outFeat = QgsFeature() index = ftools_utils.createIndex( vproviderB ) - vproviderA.rewind() - vproviderA.select( allAttrsA ) - vproviderB.rewind() - vproviderB.select( allAttrsB ) + nElement = 0 # there is selection in input layer @@ -1422,13 +1376,13 @@ class geoprocessingThread( QThread ): self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement ) geom = QgsGeometry( inFeatA.geometry() ) int_geom = QgsGeometry( geom ) - atMap = inFeatA.attributeMap() + atMap = inFeatA.attributes() intersects = index.intersects( geom.boundingBox() ) found = False first = True for id in intersects: if id in selectionB: - vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB ) + vproviderB.getFeatures( QgsFeatureRequest().setFilterFid( int( id ) ) ).nextFeature( inFeatB ) tmpGeom = QgsGeometry( inFeatB.geometry() ) if tmpGeom.intersects( geom ): found = True @@ -1453,7 +1407,7 @@ class geoprocessingThread( QThread ): new_geom = QgsGeometry( int_com.difference( int_sym ) ) try: outFeat.setGeometry( new_geom ) - outFeat.setAttributeMap( atMap ) + outFeat.setAttributes( atMap ) writer.addFeature( outFeat ) except: FEAT_EXCEPT = False @@ -1467,12 +1421,12 @@ class geoprocessingThread( QThread ): nElement += 1 self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement ) geom = QgsGeometry( inFeatA.geometry() ) - atMap = inFeatA.attributeMap() + atMap = inFeatA.attributes() intersects = index.intersects( geom.boundingBox() ) found = False first = True for id in intersects: - vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB ) + vproviderB.getFeatures( QgsFeatureRequest().setFilterFid( int( id ) ) ).nextFeature( inFeatB ) tmpGeom = QgsGeometry( inFeatB.geometry() ) if tmpGeom.intersects( geom ): found = True @@ -1497,7 +1451,7 @@ class geoprocessingThread( QThread ): new_geom = QgsGeometry( int_com.difference( int_sym ) ) try: outFeat.setGeometry( new_geom ) - outFeat.setAttributeMap( atMap ) + outFeat.setAttributes( atMap ) writer.addFeature( outFeat ) except: FEAT_EXCEPT = False @@ -1513,17 +1467,18 @@ class geoprocessingThread( QThread ): # we have selection in overlay layer if self.mySelectionB: selectionB = self.vlayerB.selectedFeaturesIds() - while vproviderA.nextFeature( inFeatA ): + fitA = vproviderA.getFeatures() + while fitA.nextFeature( inFeatA ): nElement += 1 self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement ) geom = QgsGeometry( inFeatA.geometry() ) - atMap = inFeatA.attributeMap() + atMap = inFeatA.attributes() intersects = index.intersects( geom.boundingBox() ) found = False first = True for id in intersects: if id in selectionB: - vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB ) + vproviderB.getFeatures( QgsFeatureRequest().setFilterFid( int( id ) ) ).nextFeature( inFeatB ) tmpGeom = QgsGeometry( inFeatB.geometry() ) if tmpGeom.intersects( geom ): found = True @@ -1548,7 +1503,7 @@ class geoprocessingThread( QThread ): new_geom = QgsGeometry( int_com.difference( int_sym ) ) try: outFeat.setGeometry( new_geom ) - outFeat.setAttributeMap( atMap ) + outFeat.setAttributes( atMap ) writer.addFeature( outFeat ) except: FEAT_EXCEPT = False @@ -1558,17 +1513,18 @@ class geoprocessingThread( QThread ): continue # we have no selection in overlay layer else: - while vproviderA.nextFeature( inFeatA ): + fitA = vproviderA.getFeatures() + while fitA.nextFeature( inFeatA ): nElement += 1 self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement ) geom = QgsGeometry( inFeatA.geometry() ) - atMap = inFeatA.attributeMap() + atMap = inFeatA.attributes() intersects = index.intersects( geom.boundingBox() ) first = True found = False if len( intersects ) > 0: for id in intersects: - vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB ) + vproviderB.getFeatures( QgsFeatureRequest().setFilterFid( int( id ) ) ).nextFeature( inFeatB ) tmpGeom = QgsGeometry( inFeatB.geometry() ) if tmpGeom.intersects( geom ): found = True @@ -1593,7 +1549,7 @@ class geoprocessingThread( QThread ): new_geom = QgsGeometry( int_com.difference( int_sym ) ) try: outFeat.setGeometry( new_geom ) - outFeat.setAttributeMap( atMap ) + outFeat.setAttributes( atMap ) writer.addFeature( outFeat ) except: FEAT_EXCEPT = False diff --git a/python/plugins/fTools/tools/doIntersectLines.py b/python/plugins/fTools/tools/doIntersectLines.py index 03725cd8b54..b9635efdc01 100644 --- a/python/plugins/fTools/tools/doIntersectLines.py +++ b/python/plugins/fTools/tools/doIntersectLines.py @@ -114,7 +114,6 @@ class Dialog(QDialog, Ui_Dialog): layer1 = ftools_utils.getVectorLayerByName(line1) provider1 = layer1.dataProvider() - allAttrs = provider1.attributeIndexes() fieldList = ftools_utils.getFieldList(layer1) index1 = provider1.fieldNameIndex(field1) field1 = fieldList[index1] @@ -122,7 +121,6 @@ class Dialog(QDialog, Ui_Dialog): layer2 = ftools_utils.getVectorLayerByName(line2) provider2 = layer2.dataProvider() - allAttrs = provider2.attributeIndexes() fieldList = ftools_utils.getFieldList(layer2) index2 = provider2.fieldNameIndex(field2) field2 = fieldList[index2] @@ -145,16 +143,16 @@ class Dialog(QDialog, Ui_Dialog): index = ftools_utils.createIndex( provider2 ) - provider1.select([index1]) - while provider1.nextFeature(inFeat): + fit1 = vprovider.getFeatures( QgsFeatureRequest().setSubsetOfAttributes([index1]) ) + while fit1.nextFeature(inFeat): inGeom = inFeat.geometry() - v1 = inFeat.attributeMap()[index1] + v1 = inFeat.attributes()[index1] lineList = index.intersects( inGeom.boundingBox() ) for i in lineList: - provider2.featureAtId( int( i ), inFeatB , True, [index2] ) + provider2.getFeatures( QgsFeatureRequest().setFilterFid( int( i ) ).setSubsetOfAttributes([index2]) ).nextFeature( inFeatB ) tmpGeom = QgsGeometry( inFeatB.geometry() ) - v2 = inFeatB.attributeMap()[index2] + v2 = inFeatB.attributes()[index2] if inGeom.intersects(tmpGeom): tempGeom = inGeom.intersection(tmpGeom) diff --git a/python/plugins/fTools/tools/doMeanCoords.py b/python/plugins/fTools/tools/doMeanCoords.py index 5a70c9d4428..c0a5c808656 100644 --- a/python/plugins/fTools/tools/doMeanCoords.py +++ b/python/plugins/fTools/tools/doMeanCoords.py @@ -116,8 +116,6 @@ class Dialog(QDialog, Ui_Dialog): weightIndex = provider.fieldNameIndex(weightField) uniqueIndex = provider.fieldNameIndex(uniqueField) feat = QgsFeature() - allAttrs = provider.attributeIndexes() - provider.select(allAttrs) sRs = provider.crs() check = QFile(self.shapefileName) if check.exists(): @@ -143,26 +141,25 @@ class Dialog(QDialog, Ui_Dialog): self.progressBar.setValue(0) self.progressBar.setRange(0, nFeat) for j in uniqueValues: - provider.rewind() - provider.select(allAttrs) cx = 0.00 cy = 0.00 points = [] weights = [] - while provider.nextFeature(feat): + fit = provider.getFeatures() + while fit.nextFeature(feat): nElement += 1 self.progressBar.setValue(nElement) if single: check = j.toString().trimmed() else: - check = feat.attributeMap()[uniqueIndex].toString().trimmed() + check = feat.attributes()[uniqueIndex].toString().trimmed() if check == j.toString().trimmed(): cx = 0.00 cy = 0.00 if weightIndex == -1: weight = 1.00 else: - weight = float(feat.attributeMap()[weightIndex].toDouble()[0]) + weight = float(feat.attributes()[weightIndex].toDouble()[0]) geom = QgsGeometry(feat.geometry()) geom = ftools_utils.extractPoints(geom) for i in geom: diff --git a/python/plugins/fTools/tools/doMergeShapes.py b/python/plugins/fTools/tools/doMergeShapes.py index db4cf25acd3..3b2ed2e17d7 100644 --- a/python/plugins/fTools/tools/doMergeShapes.py +++ b/python/plugins/fTools/tools/doMergeShapes.py @@ -240,26 +240,39 @@ class ShapeMergeThread( QThread ): # create attribute list with uniquie fields # from all selected layers - mergedFields = {} - count = 0 + mergedFields = [] self.emit( SIGNAL( "rangeChanged( PyQt_PyObject )" ), len( self.shapes ) ) self.emit( SIGNAL( "checkStarted()" ) ) + + shapeIndex = 0 + fieldMap = {} for fileName in self.shapes: layerPath = QFileInfo( self.baseDir + "/" + fileName ).absoluteFilePath() newLayer = QgsVectorLayer( layerPath, QFileInfo( layerPath ).baseName(), "ogr" ) if not newLayer.isValid(): continue + vprovider = newLayer.dataProvider() - layerFields = vprovider.fields() - for layerIndex, layerField in layerFields.iteritems(): + + fieldIndex = 0 + for layerField in vprovider.fields(): fieldFound = False - for mergedIndex, mergedField in mergedFields.iteritems(): - if ( mergedField.name() == layerField.name() ) and ( mergedField.type() == layerField.type() ): + for mergedField in mergedFields: + if mergedField.name() == layerField.name() and mergedField.type() == layerField.type(): fieldFound = True + break if not fieldFound: - mergedFields[ count ] = layerField - count += 1 + if not fieldMap.has_key(shapeIndex): + fieldMap[shapeIndex]={} + + fieldMap[shapeIndex][fieldIndex] = len(mergedFields) + + mergedFields.append( layerField ) + + fieldIndex += 1 + + shapeIndex += 1 self.emit( SIGNAL( "featureProcessed()" ) ) self.emit( SIGNAL( "checkFinished()" ) ) @@ -269,11 +282,11 @@ class ShapeMergeThread( QThread ): self.crs = newLayer.crs() self.geom = newLayer.wkbType() vprovider = newLayer.dataProvider() - self.fields = mergedFields writer = QgsVectorFileWriter( self.outputFileName, self.outputEncoding, - self.fields, self.geom, self.crs ) + mergedFields, self.geom, self.crs ) + shapeIndex = 0 for fileName in self.shapes: layerPath = QFileInfo( self.baseDir + "/" + fileName ).absoluteFilePath() newLayer = QgsVectorLayer( layerPath, QFileInfo( layerPath ).baseName(), "ogr" ) @@ -282,25 +295,26 @@ class ShapeMergeThread( QThread ): vprovider = newLayer.dataProvider() vprovider.setEncoding( self.inputEncoding ) layerFields = vprovider.fields() - allAttrs = vprovider.attributeIndexes() - vprovider.select( allAttrs ) nFeat = vprovider.featureCount() self.emit( SIGNAL( "rangeChanged( PyQt_PyObject )" ), nFeat ) self.emit( SIGNAL( "fileNameChanged( PyQt_PyObject )" ), fileName ) inFeat = QgsFeature() outFeat = QgsFeature() inGeom = QgsGeometry() - while vprovider.nextFeature( inFeat ): - atMap = inFeat.attributeMap() - mergedAttrs = {} + fit = vprovider.getFeatures() + while fit.nextFeature( inFeat ): + mergedAttrs = [QVariant()] * len(mergedFields) + # fill available attributes with values - for layerIndex, layerField in layerFields.iteritems(): - for mergedIndex, mergedField in self.fields.iteritems(): - if ( mergedField.name() == layerField.name() ) and ( mergedField.type() == layerField.type() ): - mergedAttrs[ mergedIndex ] = atMap[ layerIndex ] + fieldIndex = 0 + for v in inFeat.attributes(): + if fieldMap.has_key(shapeIndex) and fieldMap[shapeIndex].has_key(layerIndex): + mergedAttrs[ fieldMap[shapeIndex][layerIndex] ] = v + fieldIndex += 1 + inGeom = QgsGeometry( inFeat.geometry() ) outFeat.setGeometry( inGeom ) - outFeat.setAttributeMap( mergedAttrs ) + outFeat.setAttributes( mergedAttrs ) writer.addFeature( outFeat ) self.emit( SIGNAL( "featureProcessed()" ) ) @@ -308,10 +322,13 @@ class ShapeMergeThread( QThread ): self.mutex.lock() s = self.stopMe self.mutex.unlock() + if s == 1: interrupted = True break + shapeIndex += 1 + del writer if not interrupted: diff --git a/python/plugins/fTools/tools/doPointDistance.py b/python/plugins/fTools/tools/doPointDistance.py index b09d2e91edb..ba6ca6168c8 100644 --- a/python/plugins/fTools/tools/doPointDistance.py +++ b/python/plugins/fTools/tools/doPointDistance.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + #----------------------------------------------------------- # # fTools @@ -158,15 +158,11 @@ class Dialog(QDialog, Ui_Dialog): layer2 = ftools_utils.getVectorLayerByName(line2) provider1 = layer1.dataProvider() provider2 = layer2.dataProvider() - allAttrs = provider1.attributeIndexes() - provider1.select(allAttrs) - allAttrs = provider2.attributeIndexes() - provider2.select(allAttrs) sindex = QgsSpatialIndex() inFeat = QgsFeature() - while provider2.nextFeature(inFeat): + fit2 = provider2.getFeatures() + while fit2.nextFeature(inFeat): sindex.insertFeature(inFeat) - provider2.rewind() if nearest < 1: nearest = layer2.featureCount() else: nearest = nearest index1 = provider1.fieldNameIndex(field1) @@ -196,20 +192,21 @@ class Dialog(QDialog, Ui_Dialog): first = True start = 15.00 add = 85.00 / provider1.featureCount() - while provider1.nextFeature(inFeat): + fit1 = provider1.getFeatures() + while fit1.nextFeature(inFeat): inGeom = inFeat.geometry() - inID = inFeat.attributeMap()[index1].toString() + inID = inFeat.attributes()[index1].toString() if first: featList = sindex.nearestNeighbor(inGeom.asPoint(), nearest) first = False data = ["ID"] for i in featList: - provider2.featureAtId(int(i), outFeat, True, [index2]) - data.append(unicode(outFeat.attributeMap()[index2].toString())) + provider2.getFeatures( QgsFeatureRequest().setFilterFid( int(i) ).setSubsetOfAttributes([index2]) ).nextFeature( outFeat ) + data.append(unicode(outFeat.attributes()[index2].toString())) writer.writerow(data) data = [unicode(inID)] for j in featList: - provider2.featureAtId(int(j), outFeat, True) + provider2.getFeatures( QgsFeatureRequest().setFilterFid( int(j) ) ).nextFeature( outFeat ) outGeom = outFeat.geometry() dist = distArea.measureLine(inGeom.asPoint(), outGeom.asPoint()) data.append(str(float(dist))) @@ -225,15 +222,16 @@ class Dialog(QDialog, Ui_Dialog): outGeom = QgsGeometry() start = 15.00 add = 85.00 / provider1.featureCount() - while provider1.nextFeature(inFeat): + fit1 = provider1.getFeatures() + while fit1.nextFeature(inFeat): inGeom = inFeat.geometry() - inID = inFeat.attributeMap()[index1].toString() + inID = inFeat.attributes()[index1].toString() featList = sindex.nearestNeighbor(inGeom.asPoint(), nearest) distList = [] vari = 0.00 for i in featList: - provider2.featureAtId(int(i), outFeat, True, [index2]) - outID = outFeat.attributeMap()[index2].toString() + provider2.getFeatures( QgsFeatureRequest().setFilterFid( int(i) ).setSubsetOfAttributes([index2]) ).nextFeature( outFeat ) + outID = outFeat.attributes()[index2].toString() outGeom = outFeat.geometry() dist = distArea.measureLine(inGeom.asPoint(), outGeom.asPoint()) if dist > 0: diff --git a/python/plugins/fTools/tools/doPointsInPolygon.py b/python/plugins/fTools/tools/doPointsInPolygon.py index 266f3e224d4..e896918d452 100644 --- a/python/plugins/fTools/tools/doPointsInPolygon.py +++ b/python/plugins/fTools/tools/doPointsInPolygon.py @@ -166,9 +166,6 @@ class PointsInPolygonThread(QThread): polyProvider = self.layerPoly.dataProvider() pointProvider = self.layerPoints.dataProvider() - allAttrs = polyProvider.attributeIndexes() - polyProvider.select(allAttrs) - fieldList = ftools_utils.getFieldList(self.layerPoly) index = polyProvider.fieldNameIndex(unicode(self.fieldName)) if index == -1: @@ -185,8 +182,6 @@ class PointsInPolygonThread(QThread): polyProvider.geometryType(), sRs) spatialIndex = ftools_utils.createIndex( pointProvider ) - pointProvider.rewind() - pointProvider.select() self.emit(SIGNAL("rangeChanged(int)"), polyProvider.featureCount() ) @@ -194,10 +189,11 @@ class PointsInPolygonThread(QThread): pntFeat = QgsFeature() outFeat = QgsFeature() inGeom = QgsGeometry() - while polyProvider.nextFeature(polyFeat): + polyFit = polyProvider.getFeatures() + while polyFit.nextFeature(polyFeat): inGeom = polyFeat.geometry() - atMap = polyFeat.attributeMap() - outFeat.setAttributeMap(atMap) + atMap = polyFeat.attributes() + outFeat.setAttributes(atMap) outFeat.setGeometry(inGeom) count = 0 @@ -211,7 +207,7 @@ class PointsInPolygonThread(QThread): if hasIntersection: for p in pointList: - pointProvider.featureAtId(p, pntFeat , True) + pointProvider.getFeatures( QgsFeatureRequest().setFilterFid( p ) ).nextFeature( pntFeat ) tmpGeom = QgsGeometry(pntFeat.geometry()) if inGeom.intersects(tmpGeom): count += 1 diff --git a/python/plugins/fTools/tools/doRandPoints.py b/python/plugins/fTools/tools/doRandPoints.py index 90b6da1bb33..62280026da8 100644 --- a/python/plugins/fTools/tools/doRandPoints.py +++ b/python/plugins/fTools/tools/doRandPoints.py @@ -143,19 +143,16 @@ class Dialog(QDialog, Ui_Dialog): # combine all polygons in layer to create single polygon (slow for complex polygons) def createSinglePolygon(self, vlayer): provider = vlayer.dataProvider() - allAttrs = provider.attributeIndexes() - provider.select(allAttrs) feat = QgsFeature() geom = QgsGeometry() #geom2 = QgsGeometry() - provider.nextFeature(feat) + fit = provider.getFeatures() + fit.nextFeature(feat) geom = QgsGeometry(feat.geometry()) count = 10.00 add = ( 40.00 - 10.00 ) / provider.featureCount() - #provider.rewind() - #provider.nextFeature(feat) #geom = QgsGeometry(feat.geometry()) - while provider.nextFeature(feat): + while fit.nextFeature(feat): geom = geom.combine(QgsGeometry( feat.geometry() )) count = count + add self.progressBar.setValue(count) @@ -194,7 +191,7 @@ class Dialog(QDialog, Ui_Dialog): pGeom = QgsGeometry().fromPoint(point) ids = index.intersects(pGeom.buffer(5,5).boundingBox()) for id in ids: - provider.featureAtId(int(id),feat,True) + provider.getFeatures( QgsFeatureRequest().setFilterFid( int(id) ) ).nextFeature( feat ) tGeom = QgsGeometry(feat.geometry()) if pGeom.intersects(tGeom): points.append(pGeom) @@ -238,8 +235,6 @@ class Dialog(QDialog, Ui_Dialog): # def loopThruPolygons(self, inLayer, numRand, design): sProvider = inLayer.dataProvider() - sAllAttrs = sProvider.attributeIndexes() - sProvider.select(sAllAttrs) sFeat = QgsFeature() sGeom = QgsGeometry() sPoints = [] @@ -250,13 +245,14 @@ class Dialog(QDialog, Ui_Dialog): break count = 10.00 add = 60.00 / sProvider.featureCount() - while sProvider.nextFeature(sFeat): + sFit = sProvider.getFeatures() + while sFit.nextFeature(sFeat): sGeom = sFeat.geometry() if design == self.tr("density"): sDistArea = QgsDistanceArea() value = int(round(numRand * sDistArea.measure(sGeom))) elif design == self.tr("field"): - sAtMap = sFeat.attributeMap() + sAtMap = sFeat.attributes() value = sAtMap[index].toInt()[0] else: value = numRand diff --git a/python/plugins/fTools/tools/doSelectByLocation.py b/python/plugins/fTools/tools/doSelectByLocation.py index 9c7394ba5b2..8630eafc489 100644 --- a/python/plugins/fTools/tools/doSelectByLocation.py +++ b/python/plugins/fTools/tools/doSelectByLocation.py @@ -97,11 +97,7 @@ class Dialog(QDialog, Ui_Dialog): inputLayer = ftools_utils.getVectorLayerByName(inPoly) selectLayer = ftools_utils.getVectorLayerByName(inPts) inputProvider = inputLayer.dataProvider() - allAttrs = inputProvider.attributeIndexes() - inputProvider.select(allAttrs, QgsRectangle()) selectProvider = selectLayer.dataProvider() - allAttrs = selectProvider.attributeIndexes() - selectProvider.select(allAttrs, QgsRectangle()) feat = QgsFeature() infeat = QgsFeature() geom = QgsGeometry() @@ -116,18 +112,19 @@ class Dialog(QDialog, Ui_Dialog): geom = QgsGeometry(feat.geometry()) intersects = index.intersects(geom.boundingBox()) for id in intersects: - inputProvider.featureAtId(int(id), infeat, True) + inputProvider.getFeatures( QgsFeatureRequest().setFilterFid( int(id) ) ).nextFeature( infeat ) tmpGeom = QgsGeometry(infeat.geometry()) if geom.intersects(tmpGeom): selectedSet.append(infeat.id()) self.progressBar.setValue(self.progressBar.value()+1) else: self.progressBar.setMaximum(selectProvider.featureCount()) - while selectProvider.nextFeature(feat): + selectFit = selectProvider.getFeatures() + while selectFit.nextFeature(feat): geom = QgsGeometry(feat.geometry()) intersects = index.intersects(geom.boundingBox()) for id in intersects: - inputProvider.featureAtId(int(id), infeat, True) + inputProvider.getFeatures( QgsFeatureRequest().setFilterFid( int(id) ) ).nextFeature( infeat ) tmpGeom = QgsGeometry( infeat.geometry() ) if geom.intersects(tmpGeom): selectedSet.append(infeat.id()) diff --git a/python/plugins/fTools/tools/doSimplify.py b/python/plugins/fTools/tools/doSimplify.py index 025d234999c..ca8c1809a58 100644 --- a/python/plugins/fTools/tools/doSimplify.py +++ b/python/plugins/fTools/tools/doSimplify.py @@ -270,8 +270,6 @@ class GeomThread( QThread ): if self.writeShape: vProvider = self.inputLayer.dataProvider() - allAttrs = vProvider.attributeIndexes() - vProvider.select( allAttrs ) shapeFields = vProvider.fields() crs = vProvider.crs() wkbType = self.inputLayer.wkbType() @@ -284,7 +282,7 @@ class GeomThread( QThread ): self.emit( SIGNAL( "rangeCalculated( PyQt_PyObject )" ), len( selection ) ) for f in selection: featGeometry = QgsGeometry( f.geometry() ) - attrMap = f.attributeMap() + attrMap = f.attributes() pointsBefore += geomVertexCount( featGeometry ) newGeometry = featGeometry.simplify( self.tolerance ) @@ -292,7 +290,7 @@ class GeomThread( QThread ): feature = QgsFeature() feature.setGeometry( newGeometry ) - feature.setAttributeMap( attrMap ) + feature.setAttributes( attrMap ) shapeFileWriter.addFeature( feature ) featureId += 1 self.emit( SIGNAL( "featureProcessed()" ) ) @@ -306,9 +304,10 @@ class GeomThread( QThread ): else: self.emit( SIGNAL( "rangeCalculated( PyQt_PyObject )" ), vProvider.featureCount() ) f = QgsFeature() - while vProvider.nextFeature( f ): + fit = vProvider.getFeatures() + while fit.nextFeature( f ): featGeometry = QgsGeometry( f.geometry() ) - attrMap = f.attributeMap() + attrMap = f.attributes() pointsBefore += geomVertexCount( featGeometry ) newGeometry = featGeometry.simplify( self.tolerance ) @@ -316,7 +315,7 @@ class GeomThread( QThread ): feature = QgsFeature() feature.setGeometry( newGeometry ) - feature.setAttributeMap( attrMap ) + feature.setAttributes( attrMap ) shapeFileWriter.addFeature( feature ) featureId += 1 self.emit( SIGNAL( "featureProcessed()" ) ) @@ -355,7 +354,8 @@ class GeomThread( QThread ): vProvider = self.inputLayer.dataProvider() self.emit( SIGNAL( "rangeCalculated( PyQt_PyObject )" ), vProvider.featureCount() ) f = QgsFeature() - while vProvider.nextFeature( f ): + fit = vProvider.getFeatures() + while fit.nextFeature( f ): featureId = f.id() featGeometry = QgsGeometry( f.geometry() ) @@ -399,8 +399,6 @@ class GeomThread( QThread ): if self.writeShape: # prepare writer vProvider = self.inputLayer.dataProvider() - allAttrs = vProvider.attributeIndexes() - vProvider.select( allAttrs ) shapeFields = vProvider.fields() crs = vProvider.crs() wkbType = self.inputLayer.wkbType() @@ -414,12 +412,12 @@ class GeomThread( QThread ): self.emit( SIGNAL( "rangeCalculated( PyQt_PyObject )" ), len( selection ) ) for f in selection: featGeometry = QgsGeometry( f.geometry() ) - attrMap = f.attributeMap() + attrMap = f.attributes() newGeometry = densifyGeometry( featGeometry, int( self.tolerance ), isPolygon ) feature = QgsFeature() feature.setGeometry( newGeometry ) - feature.setAttributeMap( attrMap ) + feature.setAttributes( attrMap ) shapeFileWriter.addFeature( feature ) featureId += 1 self.emit( SIGNAL( "featureProcessed()" ) ) @@ -433,14 +431,15 @@ class GeomThread( QThread ): else: self.emit( SIGNAL( "rangeCalculated( PyQt_PyObject )" ), vProvider.featureCount() ) f = QgsFeature() - while vProvider.nextFeature( f ): + fit = vProvider.getFeatures() + while fit.nextFeature( f ): featGeometry = QgsGeometry( f.geometry() ) - attrMap = f.attributeMap() + attrMap = f.attributes() newGeometry = densifyGeometry( featGeometry, int( self.tolerance ), isPolygon ) feature = QgsFeature() feature.setGeometry( newGeometry ) - feature.setAttributeMap( attrMap ) + feature.setAttributes( attrMap ) shapeFileWriter.addFeature( feature ) featureId += 1 self.emit( SIGNAL( "featureProcessed()" ) ) @@ -478,7 +477,8 @@ class GeomThread( QThread ): vProvider = self.inputLayer.dataProvider() self.emit( SIGNAL( "rangeCalculated( PyQt_PyObject )" ), vProvider.featureCount() ) f = QgsFeature() - while vProvider.nextFeature( f ): + fit = vProvider.getFeatures() + while fit.nextFeature( f ): featureId = f.id() featGeometry = QgsGeometry( f.geometry() ) newGeometry = densifyGeometry( featGeometry, int( self.tolerance ), isPolygon ) diff --git a/python/plugins/fTools/tools/doSpatialJoin.py b/python/plugins/fTools/tools/doSpatialJoin.py index 9d9fd7ce4dc..ced8cfc9a77 100644 --- a/python/plugins/fTools/tools/doSpatialJoin.py +++ b/python/plugins/fTools/tools/doSpatialJoin.py @@ -123,14 +123,11 @@ class Dialog(QDialog, Ui_Dialog): def compute(self, inName, joinName, outName, summary, sumList, keep, progressBar): layer1 = ftools_utils.getVectorLayerByName(inName) provider1 = layer1.dataProvider() - allAttrs = provider1.attributeIndexes() - provider1.select(allAttrs) fieldList1 = ftools_utils.getFieldList(layer1).values() layer2 = ftools_utils.getVectorLayerByName(joinName) provider2 = layer2.dataProvider() - allAttrs = provider2.attributeIndexes() - provider2.select(allAttrs) + fieldList2 = ftools_utils.getFieldList(layer2) fieldList = [] if provider1.crs() != provider2.crs(): @@ -180,11 +177,12 @@ class Dialog(QDialog, Ui_Dialog): progressBar.setValue(15) start = 15.00 add = 85.00 / provider1.featureCount() - provider1.rewind() + index = ftools_utils.createIndex(provider2) - while provider1.nextFeature(inFeat): + fit1 = provider1.getFeatures() + while fit1.nextFeature(inFeat): inGeom = inFeat.geometry() - atMap1 = inFeat.attributeMap() + atMap1 = inFeat.attributes() outFeat.setGeometry(inGeom) none = True joinList = [] @@ -206,12 +204,12 @@ class Dialog(QDialog, Ui_Dialog): count = 0 for i in joinList: #tempGeom = i.geometry() - provider2.featureAtId(int(i), inFeatB , True, allAttrs) + provider2.getFeatures( QgsFeatureRequest().setFilterFid( int(i) ) ).nextFeature( inFeatB ) tmpGeom = QgsGeometry( inFeatB.geometry() ) if inGeom.intersects(tmpGeom): count = count + 1 none = False - atMap2 = inFeatB.attributeMap() + atMap2 = inFeatB.attributes() if not summary: atMap = atMap1.values() atMap2 = atMap2.values() @@ -234,9 +232,9 @@ class Dialog(QDialog, Ui_Dialog): atMap.append(QVariant(count)) atMap = dict(zip(seq, atMap)) if none: - outFeat.setAttributeMap(atMap1) + outFeat.setAttributes(atMap1) else: - outFeat.setAttributeMap(atMap) + outFeat.setAttributes(atMap) if keep: # keep all records writer.addFeature(outFeat) else: # keep only matching records diff --git a/python/plugins/fTools/tools/doSubsetSelect.py b/python/plugins/fTools/tools/doSubsetSelect.py index e1872c36655..ffac1ed3bd7 100644 --- a/python/plugins/fTools/tools/doSubsetSelect.py +++ b/python/plugins/fTools/tools/doSubsetSelect.py @@ -83,9 +83,6 @@ class Dialog(QDialog, Ui_Dialog): mlayer = ftools_utils.getMapLayerByName(inVect) mlayer.removeSelection(True) vlayer = ftools_utils.getVectorLayerByName(inVect) - vprovider = vlayer.dataProvider() - allAttrs = vprovider.attributeIndexes() - vprovider.select(allAttrs) index = vprovider.fieldNameIndex(inField) #unique = [] #vprovider.uniqueValues(index, unique) @@ -96,12 +93,13 @@ class Dialog(QDialog, Ui_Dialog): nElement = 0 self.progressBar.setValue(0) self.progressBar.setRange(0, nFeat) + fit = vprovider.getFeatures() if not len(unique) == mlayer.featureCount(): for i in unique: - vprovider.rewind() + fit.rewind() FIDs= [] - while vprovider.nextFeature(inFeat): - atMap = inFeat.attributeMap() + while fit.nextFeature(inFeat): + atMap = inFeat.attributes() if atMap[index] == QVariant(i): FID = inFeat.id() FIDs.append(FID) diff --git a/python/plugins/fTools/tools/doSumLines.py b/python/plugins/fTools/tools/doSumLines.py index db890087a74..03690f1d8ac 100644 --- a/python/plugins/fTools/tools/doSumLines.py +++ b/python/plugins/fTools/tools/doSumLines.py @@ -100,10 +100,6 @@ class Dialog(QDialog, Ui_Dialog): lineProvider = lineLayer.dataProvider() if polyProvider.crs() <> lineProvider.crs(): QMessageBox.warning(self, self.tr("CRS warning!"), self.tr("Warning: Input layers have non-matching CRS.\nThis may cause unexpected results.")) - allAttrs = polyProvider.attributeIndexes() - polyProvider.select(allAttrs) - allAttrs = lineProvider.attributeIndexes() - lineProvider.select(allAttrs) fieldList = ftools_utils.getFieldList(polyLayer) index = polyProvider.fieldNameIndex(unicode(inField)) if index == -1: @@ -117,7 +113,6 @@ class Dialog(QDialog, Ui_Dialog): inGeom = QgsGeometry() outGeom = QgsGeometry() distArea = QgsDistanceArea() - lineProvider.rewind() start = 15.00 add = 85.00 / polyProvider.featureCount() check = QFile(self.shapefileName) @@ -127,9 +122,10 @@ class Dialog(QDialog, Ui_Dialog): writer = QgsVectorFileWriter(self.shapefileName, self.encoding, fieldList, polyProvider.geometryType(), sRs) #writer = QgsVectorFileWriter(outPath, "UTF-8", fieldList, polyProvider.geometryType(), sRs) spatialIndex = ftools_utils.createIndex( lineProvider ) - while polyProvider.nextFeature(inFeat): + polyFit = polyProvider.getFeatures() + while polyFit.nextFeature(inFeat): inGeom = QgsGeometry(inFeat.geometry()) - atMap = inFeat.attributeMap() + atMap = inFeat.attributes() lineList = [] length = 0 #(check, lineList) = lineLayer.featuresInRectangle(inGeom.boundingBox(), True, False) @@ -140,13 +136,13 @@ class Dialog(QDialog, Ui_Dialog): else: check = 1 if check == 0: for i in lineList: - lineProvider.featureAtId( int( i ), inFeatB , True, allAttrs ) + lineProvider.getFeatures( QgsFeatureRequest().setFilterFid( int(i) ) ).nextFeature( inFeatB ) tmpGeom = QgsGeometry( inFeatB.geometry() ) if inGeom.intersects(tmpGeom): outGeom = inGeom.intersection(tmpGeom) length = length + distArea.measure(outGeom) outFeat.setGeometry(inGeom) - outFeat.setAttributeMap(atMap) + outFeat.setAttributes(atMap) outFeat.addAttribute(index, QVariant(length)) writer.addFeature(outFeat) start = start + 1 diff --git a/python/plugins/fTools/tools/doValidate.py b/python/plugins/fTools/tools/doValidate.py index 934067ccbf8..0ef8bdcfc34 100644 --- a/python/plugins/fTools/tools/doValidate.py +++ b/python/plugins/fTools/tools/doValidate.py @@ -182,7 +182,7 @@ class ValidateDialog( QDialog, Ui_Dialog ): ft = QgsFeature() (fid,ok) = self.tblUnique.item(row, 0).text().toInt() - if not ok or not self.vlayer.featureAtId( fid, ft, True): + if not ok or not self.vlayer.getFeatures( QgsFeatureRequest().setFilterFid( fid ) ).nextFeature( ft ): return rect = mc.mapRenderer().layerExtentToOutputExtent( self.vlayer, ft.geometry().boundingBox() ) @@ -298,7 +298,8 @@ class validateThread( QThread ): layer = [] vlayer.select([]) # select all features, and ignore attributes ft = QgsFeature() - while vlayer.nextFeature(ft): + fit = vlayer.getFeatures() + while fit.nextFeature(ft): layer.append(QgsFeature(ft)) nFeat = len(layer) nElement = 0 @@ -317,8 +318,8 @@ class validateThread( QThread ): self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nFeat ) if self.writeShape: - fields = { 0 : QgsField( "FEAT_ID", QVariant.Int ), - 1 : QgsField( "ERROR", QVariant.String ) } + fields = [ QgsField( "FEAT_ID", QVariant.Int ), + QgsField( "ERROR", QVariant.String ) ] writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields, QGis.WKBPoint, vlayer.crs() ) for rec in lstErrors: @@ -335,8 +336,7 @@ class validateThread( QThread ): geometry = QgsGeometry().fromPoint( myPoint ) ft = QgsFeature() ft.setGeometry( geometry ) - ft.setAttributeMap( { 0 : QVariant( fidItem ), - 1 : QVariant( message ) } ) + ft.setAttributes( [ QVariant( fidItem ), QVariant( message ) ] ) writer.addFeature( ft ) del writer return "writeShape" diff --git a/python/plugins/fTools/tools/doVectorSplit.py b/python/plugins/fTools/tools/doVectorSplit.py index 4bb859061f2..bf622a9b26c 100644 --- a/python/plugins/fTools/tools/doVectorSplit.py +++ b/python/plugins/fTools/tools/doVectorSplit.py @@ -162,8 +162,7 @@ class SplitThread(QThread): index = provider.fieldNameIndex(self.field) unique = ftools_utils.getUniqueValues(provider, int(index)) baseName = unicode( outPath + self.layer.name() + "_" + self.field + "_" ) - allAttrs = provider.attributeIndexes() - provider.select(allAttrs) + fieldList = ftools_utils.getFieldList(self.layer) sRs = provider.crs() geom = self.layer.wkbType() @@ -171,6 +170,8 @@ class SplitThread(QThread): self.emit(SIGNAL("rangeCalculated(PyQt_PyObject)"), len(unique)) + fit = provider.getFeatures() + for i in unique: check = QFile(baseName + "_" + unicode(i.toString().trimmed()) + ".shp") fName = check.fileName() @@ -180,9 +181,10 @@ class SplitThread(QThread): continue writer = QgsVectorFileWriter(fName, self.encoding, fieldList, geom, sRs) - provider.rewind() - while provider.nextFeature(inFeat): - atMap = inFeat.attributeMap() + + fit.rewind() + while fit.nextFeature(inFeat): + atMap = inFeat.attributes() if atMap[index] == i: writer.addFeature(inFeat) del writer diff --git a/python/plugins/fTools/tools/doVisual.py b/python/plugins/fTools/tools/doVisual.py index 6e17e61617f..80c6af44e18 100644 --- a/python/plugins/fTools/tools/doVisual.py +++ b/python/plugins/fTools/tools/doVisual.py @@ -236,9 +236,6 @@ class visualThread( QThread ): def list_unique_values( self, vlayer, myField ): vprovider = vlayer.dataProvider() - allAttrs = vprovider.attributeIndexes() - vprovider.select( allAttrs ) - fields = vprovider.fields() index = vprovider.fieldNameIndex( myField ) unique = ftools_utils.getUniqueValues( vprovider, int( index ) ) lstUnique = [] @@ -256,9 +253,6 @@ class visualThread( QThread ): def basic_statistics( self, vlayer, myField ): vprovider = vlayer.dataProvider() - allAttrs = vprovider.attributeIndexes() - vprovider.select( allAttrs ) - fields = vprovider.fields() index = vprovider.fieldNameIndex( myField ) feat = QgsFeature() sumVal = 0.0 @@ -279,7 +273,7 @@ class visualThread( QThread ): self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 ) self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) ) for f in selection: - atMap = f.attributeMap() + atMap = f.attributes() lenVal = float( len( atMap[ index ].toString() ) ) if first: minVal = lenVal @@ -301,9 +295,9 @@ class visualThread( QThread ): if nFeat > 0: self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 ) self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) ) - vprovider.select( allAttrs ) - while vprovider.nextFeature( feat ): - atMap = feat.attributeMap() + fit = vprovider.getFeatures() + while fit.nextFeature( feat ): + atMap = feat.attributes() lenVal = float( len( atMap[ index ].toString() ) ) if first: minVal = lenVal @@ -348,7 +342,7 @@ class visualThread( QThread ): self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 ) self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) ) for f in selection: - atMap = f.attributeMap() + atMap = f.attributes() value = float( atMap[ index ].toDouble()[ 0 ] ) if first: minVal = value @@ -367,9 +361,9 @@ class visualThread( QThread ): if nFeat > 0: self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 ) self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) ) - vprovider.select( allAttrs ) - while vprovider.nextFeature( feat ): - atMap = feat.attributeMap() + fit = vprovider.getFeatures() + while fit.nextFeature( feat ): + atMap = feat.attributes() value = float( atMap[ index ].toDouble()[ 0 ] ) if first: minVal = value @@ -415,10 +409,6 @@ class visualThread( QThread ): def nearest_neighbour_analysis( self, vlayer ): vprovider = vlayer.dataProvider() - allAttrs = vprovider.attributeIndexes() - vprovider.select( allAttrs ) - feat = QgsFeature() - neighbour = QgsFeature() sumDist = 0.00 distance = QgsDistanceArea() A = vlayer.extent() @@ -430,9 +420,12 @@ class visualThread( QThread ): if nFeat > 0: self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 ) self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) ) - while vprovider.nextFeature( feat ): + feat = QgsFeature() + neighbour = QgsFeature() + fit = vprovider.getFeatures() + while fit.nextFeature( feat ): neighbourID = index.nearestNeighbor( feat.geometry().asPoint(), 2 )[ 1 ] - vprovider.featureAtId( neighbourID, neighbour, True, [] ) + vprovider.getFeatures( QgsFeatureRequest().setFilterFid( neighbourID ).setSubsetOfAttributes( [] ) ).nextFeature( neighbour ) nearDist = distance.measureLine( neighbour.geometry().asPoint(), feat.geometry().asPoint() ) sumDist += nearDist nElement += 1 diff --git a/python/plugins/fTools/tools/ftools_utils.py b/python/plugins/fTools/tools/ftools_utils.py index aa85382373c..6a1e40d6356 100644 --- a/python/plugins/fTools/tools/ftools_utils.py +++ b/python/plugins/fTools/tools/ftools_utils.py @@ -32,7 +32,6 @@ # Utility functions # ------------------------------------------------- # -# combineVectorAttributes( QgsAttributeMap, QgsAttributeMap ) # convertFieldNameType( QgsField.name() ) # combineVectorFields( QgsVectorLayer, QgsVectorLayer ) # checkCRSCompatibility( QgsCoordinateReferenceSystem, QgsCoordinateReferenceSystem ) @@ -63,15 +62,6 @@ from qgis.gui import * import locale -# From two input attribute maps, create single attribute map -def combineVectorAttributes( atMapA, atMapB ): - attribA = atMapA.values() - lengthA = len(attribA) - attribB = atMapB.values() - lengthB = len(attribB) - attribA.extend( attribB ) - return dict( zip( range( 0, lengthB + lengthA ), attribA ) ) - # For use with memory provider/layer, converts full field type to simple string def convertFieldNameType( inName ): if inName == "Integer": @@ -83,12 +73,10 @@ def convertFieldNameType( inName ): # From two input field maps, create single field map def combineVectorFields( layerA, layerB ): - fieldsA = layerA.dataProvider().fields().values() - fieldsB = layerB.dataProvider().fields().values() + fieldsA = layerA.dataProvider().fields() + fieldsB = layerB.dataProvider().fields() fieldsB = testForUniqueness( fieldsA, fieldsB ) - seq = range( 0, len( fieldsA ) + len( fieldsB ) ) fieldsA.extend( fieldsB ) - fieldsA = dict( zip ( seq, fieldsA ) ) return fieldsA # Check if two input CRSs are identical @@ -258,20 +246,14 @@ def getMapLayerByName( myName ): # Return the field list of a vector layer def getFieldList( vlayer ): - vprovider = vlayer.dataProvider() - feat = QgsFeature() - allAttrs = vprovider.attributeIndexes() - vprovider.select( allAttrs ) - myFields = vprovider.fields() - return myFields + return vlayer.dataProvider().fields() # Convinience function to create a spatial index for input QgsVectorDataProvider def createIndex( provider ): feat = QgsFeature() index = QgsSpatialIndex() - provider.rewind() - provider.select() - while provider.nextFeature( feat ): + fit = provider.getFeatures() + while fit.nextFeature( feat ): index.insertFeature( feat ) return index @@ -292,8 +274,7 @@ def addShapeToCanvas( shapefile_path ): # Return all unique values in field based on field index def getUniqueValues( provider, index ): - values = provider.uniqueValues( index ) - return values + return provider.uniqueValues( index ) # Generate a save file dialog with a dropdown box for choosing encoding style def saveDialog( parent, filtering="Shapefiles (*.shp *.SHP)"): @@ -348,29 +329,28 @@ def dirDialog( parent ): # Return field type from it's name def getFieldType(vlayer, fieldName): - fields = vlayer.dataProvider().fields() - for name, field in fields.iteritems(): + for field in vlayer.dataProvider().fields(): if field.name() == fieldName: return field.typeName() # return the number of unique values in field def getUniqueValuesCount( vlayer, fieldIndex, useSelection ): - vprovider = vlayer.dataProvider() - allAttrs = vprovider.attributeIndexes() - vprovider.select( allAttrs ) count = 0 values = [] if useSelection: selection = vlayer.selectedFeatures() for f in selection: - if f.attributeMap()[ fieldIndex ].toString() not in values: - values.append( f.attributeMap()[ fieldIndex ].toString() ) + v = f.attributes()[ fieldIndex ].toString() + if v not in values: + values.append( v ) count += 1 else: feat = QgsFeature() - while vprovider.nextFeature( feat ): - if feat.attributeMap()[ fieldIndex ].toString() not in values: - values.append( feat.attributeMap()[ fieldIndex ].toString() ) + fit = vlayer.dataProvider().getFeatures() + while fit.nextFeature( feat ): + v = feat.attributes()[ fieldIndex ].toString() + if v not in values: + values.append( v ) count += 1 return count