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

Etienne Tourigny etourigny.dev at gmail.com
Thu Nov 29 11:27:43 PST 2012


On Thu, Nov 29, 2012 at 3:54 PM, 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.
>

or use the ogr-sqlite interface that is present in gdal 1.10 - it
supposedly works with all ogr data sources

http://www.gdal.org/ogr/ogr_sql_sqlite.html

>
> 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
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev


More information about the gdal-dev mailing list