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– Germán Carrillo2016年11月28日 03:12:37 +00:00Commented Nov 28, 2016 at 3:12
-
QGIS version 2.18DB9– DB92016年12月01日 13:28:38 +00:00Commented 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– neuhausr2016年12月01日 15:01:36 +00:00Commented 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– DB92016年12月01日 16:32:11 +00:00Commented Dec 1, 2016 at 16:32
2 Answers 2
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"