Re: [gdal-dev] Creating new column with filename, scripting shapefiles
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 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@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@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] Creating new column with filename, scripting shapefiles
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 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 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@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@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] Creating new column with filename, scripting shapefiles
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'" ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] Creating new column with filename, scripting shapefiles
On Thu, Nov 29, 2012 at 3:54 PM, Chaitanya kumar CH 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 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@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@lists.osgeo.org > http://lists.osgeo.org/mailman/listinfo/gdal-dev ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] Creating new column with filename, scripting shapefiles
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 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'" ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev