3

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?

4
  • Which version of QGIS are you using? Commented Nov 28, 2016 at 3:12
  • QGIS version 2.18
    – DB9
    Commented Dec 1, 2016 at 13:28
  • worked for me on a single layer and as a batch. are you getting an error or something?
    – neuhausr
    Commented Dec 1, 2016 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
    Commented Dec 1, 2016 at 16:32

2 Answers 2

1

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.

-1

Did you try

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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