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

Joe Larson joe at joelarson.com
Thu Nov 29 10:13:47 PST 2012


Chaitanya - I believe the normalized/laundered message is a non-issue at this point. I only get that message when I repeatedly run my Bash script against the folder of shapefiles - so it's changing the 'filename' column to 'filename_1' when creating a new column.

I really like your idea of sqlite and will give this a try. Thank you very much _ joe

On Nov 29, 2012, at 9:54:49AM, Chaitanya kumar CH <chaitanya.ch at gmail.com> wrote:

> Joe,
> 
> What was the full warning message about the normalized/laundered field name? Field name is modified when the name is longer than 10 characters or when a field with same name exists.
> Check the name of the newly created field.
> 
> As per the update command, I don't think the update command is implemented in the ogr sql yet. You can do it in the sqlite format, among other rdbms formats. Use ogr2ogr to convert it to sqlite. update it. convert it back to shapefile.
> 
> 
> On Thu, Nov 29, 2012 at 8:58 PM, Joe Larson <joe at joelarson.com> wrote:
> 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 at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
> 
> 
> 
> -- 
> Best regards,
> Chaitanya kumar CH.
> 
> +91-9494447584
> 17.2416N 80.1426E

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20121129/b15814d3/attachment.html>


More information about the gdal-dev mailing list