Created
November 29, 2012 08:13
-
-
Save oeon/4167521 to your computer and use it in GitHub Desktop.
source filename in shapefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
Hmm, I tried the first one and this is what I've: ERROR 1: Unsupported ALTER TABLE command : ALTER TABLE ADD COLUMN filename character(21)
shapefiles cannot handle field names longer than 10 characters
The alter command works.
maybe the error is coming when i pass the variable into the -sql ? Also, I must be sleepy ;) fieldnames cannot be longer than 10 - but contents can :P
Yes. That's what I suspected too. I hard coded the column name but it still throws a "syntax error":
ogrinfo file.shp -sql "UPDATE file SET filename_4='blah'"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i don't think shapefiles can handle columns that big - but i have tried this with (11) too. Always get
ERROR 1: SQL Expression Parsing Error: syntax error