[Qgis-developer] I: Re: Re: R: Re: attributeMap()

francescoboccacci at libero.it francescoboccacci at libero.it
Mon Feb 4 00:26:11 PST 2013



>----Messaggio originale----
>Da: francescoboccacci at libero.it
>Data: 04/02/2013 9.20
>A: <wonder.sk at gmail.com>
>Ogg: R: Re: Re: [Qgis-developer] R: Re: attributeMap()
>
>Hi Martin,
>this is my code:
>
>           vproviderA = vlayerA.dataProvider()
>            
>            allAttrsA = vproviderA.attributeIndexes() #vettore contente 
tutti 
>gli indici dei campi
>            
>            try:
>                vproviderA.select(allAttrsA)
>            except:
>                vproviderA.getFeatures()
>            inFeat = QgsFeature()
>            outFeat = QgsFeature()
>            inGeom = QgsGeometry()
>            outGeom = QgsGeometry()
>            index = vproviderA.fieldNameIndex(field)#this works
>            features = QGisLayers.features(vlayerA)#from SEXTANTE
>            nFeat = len(features)
>            #vettore contenente valori unici del campo scelto
>            unique = ftools_utils.getUniqueValues(vproviderA, 
index)          
>            progress_perc=100/nFeat
>            n = 0
>            outID = 0
>            for i in unique:
>                  nElement=0
>                  xPoints = []
>                  yPoints = []
>                  first = True
>                  
>                  features = QGisLayers.features(vlayerA)
>                  for inFeat in features:
>                    try:
>                        atMap = inFeat.attributeMap()
>                        idVar = atMap[ index ]
>                    except:
>                        idVar = inFeat [ index ]
>
>What am i wrong?
>Thanks
>
>Francesco
>                 
>
>>----Messaggio originale----
>>Da: wonder.sk at gmail.com
>>Data: 04/02/2013 9.05
>>A: "francescoboccacci at libero.it"<francescoboccacci at libero.it>
>>Cc: "Nathan Woodrow"<madmanwoo at gmail.com>, "qgis-developer at lists.osgeo.org"
><qgis-developer at lists.osgeo.org>
>>Ogg: Re: Re: [Qgis-developer] R: Re: attributeMap()
>>
>>On Sun, Feb 3, 2013 at 9:40 PM, francescoboccacci at libero.it
>><francescoboccacci at libero.it> wrote:
>>> Hi Nathan,
>>>
>>> i tired with the name of the field:
>>>
>>> idVar = inFeat[field]
>>> KeyError: 'type'
>>>
>>> field is the name of field (in this case 'type').
>>
>>Both access by index and by field name should work - if not, the
>>attribute is probably not loaded. How do you get the feature - what is
>>the select() / getFeatures() command?
>>
>>Martin
>>
>
>




More information about the Qgis-developer mailing list