I would like to select some lines in the layer that match this condition :

the attribut A have to be the same as the value of the "for" loop where the selection is realised.

(After fixing that issue, I would like then to compare an other attribute value of the layer with the value in an other "for" loop above the previous "for" loop) I dont know how to do that. Here is my stard code but not optimised...

valeuruniqueC2 is an array of value

for value2 in valeuruniqueC2 :
  ecart = 0
  iter1 = macouche.getFeatures(QgsFeatureRequest().setFilterExpression (u' "%s"= '+str(value2) %feature['ATT1']))
  macouche.setSelectedFeatures( [ f.id() for f in iter1 ] )
  selection = macouche.selectedFeatures()

  for feature in selection:

additional informations :

I did a script that's working but produce at this end the comparison beetween each value (of the considered attribute) of the layer while I am looking for doing comparison beetween lines where the condition (value of the attribute is egal to the value of the loop) is verified... so I started to do an other way but without succeed for now.

for value2 in valeuruniqueC2 : ecart = 0 iter1 = macouche.getFeatures() for feature in iter1: attri1=feature.attributes() if attri1[0] == value2: datetime.datetime.strptime(feature['DATE3'],'%d/%m/%Y %H:%M') datetime.datetime.strptime(value1,'%d/%m/%Y %H:%M') ecart= datetime.datetime.strptime(value1,'%d/%m/%Y %H:%M') - datetime.datetime.strptime(feature['DATE3'],'%d/%m/%Y %H:%M') zero= datetime.datetime.strptime('01/01/1900 01:00','%d/%m/%Y %H:%M') - datetime.datetime.strptime('01/01/1900 01:00','%d/%m/%Y %H:%M')

 if ecart < zero: 
  ecart= datetime.datetime.strptime(feature['DATE3'],'%d/%m/%Y %H:%M') - datetime.datetime.strptime(value1,'%d/%m/%Y %H:%M') 
  if ecart_minN > ecart : 
   ecart_minN=ecart DHn=feature['DATE3'] 
 else: if ecart_minP>ecart : 
  ecart_minP=ecart DHp=feature1['DATE3'] 


  • Are you able to select the features and you just want to know how to compare them? Or are you also asking how to select the features too? – Joseph Jul 28 '16 at 11:13
  • I am not able to select correctly yet – LoGISpace Jul 28 '16 at 12:13
  • Is 'ATT1' your field name? – Joseph Jul 28 '16 at 12:39
  • Yes, this is the value of the field I would like to compare with the value of the loop (value2) – LoGISpace Jul 28 '16 at 12:46
  • Welcome to gis.stackexchange! Please edit the title of your question to include enough information for future visitors to be able to find this thread when looking for the same problem. – underdark Jul 28 '16 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.