3

I am making a model which requires creating a grid and clipping various layers to it. Using the Create grid function does not provide an ID column, instead it creates 2 columns: "longitude" and "latitude".

Because of this, I would like the Modeler to insert a new ID column using either Field Calculator or Advanced Python Field Calculator but I have no idea what the expression is.

I am using QGIS 2.2.0 Valmiera.

I have noticed this topic: Auto-incrementing in Python Script with ArcPy cursor?

If using the Advanced Python Field Calculator, would the python coding be inserted to the Global expression or to the Formula?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Joseph
  • 75,746
  • 7
  • 171
  • 282

1 Answers1

3

Assuming you don't need a true, database-style auto-incrementing field (which would only work in PostGIS or Spatialite or another db data format), you could simply add a calculation step to your model, calculating an ID column with the expression:

$rownum

… this will give a unique, incremented set of integer values.

Simbamangu
  • 14,773
  • 6
  • 59
  • 93