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?

asked Nov 26, 2016 at 11:56
4
  • Which version of QGIS are you using? Commented Nov 28, 2016 at 3:12
  • QGIS version 2.18 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? 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! 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.

answered Apr 14, 2017 at 16:56
-1

Did you try

ogr2ogr "C:\Temp1\OutDataSet.shp" "C:\Temp1\asdf\InDataSet.shp" -sql "SELECT *, End AS LineEnd, begin AS Begin FROM InDataSet"
answered Mar 22, 2017 at 8:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.