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'"
done;

#2

for f in *.shp;

do

name=`echo "$f"|sed 's/\.shp$//g'`

ogrinfo $f -sql "ALTER TABLE $name ADD COLUMN filename character(10)"
ogrinfo $f -sql "UPDATE TABLE $name filename = '$f'"
done;

#3

for f in *.shp;

do

name=`basename $f .shp`

ogrinfo $f -sql "ALTER TABLE $name ADD COLUMN filename character(10)"
ogrinfo $f -sql "UPDATE TABLE $name filename = '$f'"
done;


There's an example here http://trac.osgeo.org/gdal/wiki/FAQVector called "How 
do I include the source filename in a field when merging hundreds of shapefiles 
(Windows)?" I also cannot get this to work - getting "unrecognized fieldname" 
message.

Perhaps my variable does not work in the Bash SQL statement. I'm not sure 
what's going on in the Windows example.

Regards,
Joe Larson
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to