[QGIS-Developer] RES: QgsFeatureRequest SortByOrder

Jorge Almerio jorgealmerio at yahoo.com.br
Mon Jun 4 04:35:27 PDT 2018


Hi Matthias,

Thank you very much!

Regards, Jorge

-----Mensagem original-----
De: QGIS-Developer [mailto:qgis-developer-bounces at lists.osgeo.org] Em nome de Matthias Kuhn
Enviada em: segunda-feira, 4 de junho de 2018 04:14
Para: qgis-developer at lists.osgeo.org
Assunto: Re: [QGIS-Developer] QgsFeatureRequest SortByOrder

Hi Jorge,

There are two possibilities, one is to use the full-blown API with
OrderBy class etc. And then there is a shorthand for this, called
QgsFeatureRequest.addOrderBy which is enough in 90% of the cases.

Short version:

  request = QgsFeatureRequest()
  request.addOrderBy('field_name')

https://qgis.org/pyqgis/master/core/Feature/QgsFeatureRequest.html#qgis.core.QgsFeatureRequest.addOrderBy

Long version:

  clause = QgsFeatureRequest.OrderByClause('field_name')
  orderBy = QgsFeatureRequest.OrderBy([clause])
  request = QgsFeatureRequest()
  request.setOrderBy(orderBy)

https://qgis.org/pyqgis/master/core/Feature/QgsFeatureRequest.html#qgis.core.QgsFeatureRequest.setOrderBy

Regards Matthias

On 06/01/2018 06:15 PM, Jorge Almerio wrote:
> Can anyone help me how to iterate through features using a Field as a
> sort order?
> 
>  
> 
> I saw that there is a function setOrderBy
> <https://qgis.org/api/classQgsFeatureRequest.html#ad9c11d4c88185fcfb0a54f8703699717>on
> QgsFeatureRequest, by it seems to request a OrderBy Class argument, but
> I could not get how to use it.
> 
>  
> 
> Simple example:
> 
> "
> 
> lyr = iface.activeLayer()
> 
> prov = lyr.dataProvider()
> 
> for feature in prov.getFeatures(QgsFeatureRequest()):
> 
>     print feature.id()
> 
> "
> 
>  
> 
> Thank you
> 
> 
> 
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 
_______________________________________________
QGIS-Developer mailing list
QGIS-Developer at lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer



More information about the QGIS-Developer mailing list