I want to add the fid to the attribute table using ogrinfo in OSGeo4W Shell.

Here is my code:

ogrinfo layer.shp -sql "ALTER TABLE layer ADD COLUMN ID integer" 
ogrinfo layer.shp -dialect SQLite -sql "UPDATE layer SET ID = FID"

The GDAL:OGR SQL help https://www.gdal.org/ogr_sql.html points out that sometimes it is necessary to add the fid as a column, as it is the case for me.

Does anyone has a clue how to solve this? Maybe by iterating a rownumber?


I found a simple way to add a rownumber with ogr

ogrinfo layer.shp -dialect SQLite -sql "UPDATE layer set ID = rowid+1"

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.