[gdal-dev] Creating new column with filename, scripting shapefiles

Joe Larson joe at joelarson.com
Thu Nov 29 11:52:10 PST 2012


Even- your guidance and correction was the solution that worked for me. Thank you! _ joe

On Nov 29, 2012, at 11:00:47AM, Even Rouault <even.rouault at mines-paris.org> wrote:

> Le jeudi 29 novembre 2012 16:28:33, Joe Larson a écrit :
>> I have tried these three methods to add a filename column while scripting a
>> folder of shapefiles, with a Bash script - which results in `Warning 6:
>> Normalized/laundered field name` & `ERROR 1: SQL Expression Parsing Error:
>> syntax error` messages and NULL values in the created column :
>> 
>> #1
>> 
>> for f in *.shp;
>> 
>> do
>> 
>> name=${f%.shp}
>> 
>> ogrinfo $f -sql "ALTER TABLE $name ADD COLUMN filename character(10)"
>> ogrinfo $f -sql "UPDATE TABLE $name filename = '$f'"
> 
> --> UPDATE syntax is not supported by OGR SQL dialect. See 
> http://gdal.org/ogr/ogr_sql.html
> 
> If you use the development version of GDAL (GDAL 1.10dev), you could however 
> use the SQLite dialect to do UPDATEs : http://gdal.org/ogr/ogr_sql_sqlite.html
> 
> Actually your SQL is incorrect. The correct syntax would be :
> 
> ogrinfo $f -dialect SQLite -sql "UPDATE $name SET filename = '$f'"



More information about the gdal-dev mailing list