I have a large number of files whose attribute fields are named consistently, but incorrectly. I would ordinarily use ogr2ogr.exe to fix this from the command line using something like:

ogr2ogr "C:\Temp1\OutDataSet.shp" "C:\Temp1\asdf\InDataSet.shp" -sql "SELECT End AS LineEnd, begin AS Begin FROM InDataSet"

This creates a new .shp file, renames attribute fields from End to LineEnd and from begin to Begin , also drops many unwanted attribute fields from the original shapefile.

I was hoping that I could achieve the same thing from QGIS 2.18 processing toolbox > [OGR] Miscellaneous > Execute SQL, as It is easy to set up a batch by using the QGIS forms. Has anyone had any success with this tool for this task?

  • Which version of QGIS are you using? – Germán Carrillo Nov 28 '16 at 3:12
  • QGIS version 2.18 – DB9 Dec 1 '16 at 13:28
  • worked for me on a single layer and as a batch. are you getting an error or something? – neuhausr Dec 1 '16 at 15:01
  • Yes, it throws up an error for me! neuhausr if you get a sec, please post up a screen grab of your snyntax, maybe I'm doing something stupid! Thanks! – DB9 Dec 1 '16 at 16:32

I'd use ogrinfo instead of ogr2ogr updating the input shapefile without creating a new one:

ogrinfo "C:\Temp1\asdf\InDataSet.shp" -sql "ALTER TABLE InDataSet RENAME COLUMN oldcolumnname TO newcolumnname"

But Execute SQL of the Processing toolbox is based only on ogr2ogr command, so it's convenient to execute a loop over your based on ogrinfo in the OSGeo4W Shell.


Did you try

ogr2ogr "C:\Temp1\OutDataSet.shp" "C:\Temp1\asdf\InDataSet.shp" -sql "SELECT *, End AS LineEnd, begin AS Begin FROM InDataSet"

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

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.