Made a little shell-script solving this earlier question of mine. Maybe someone else will need this as well....

patrick


###INIT:make copy of file (name "short" is used as indicator)
g.copy vect=myfile,myfile_short --o


###iterate through all columns, all files and check double column-name

###for all files of name *_short
for z in $(g.mlist type=vect pattern='*_short')
do
    for i in $(db.columns table=${z})
    do
        col=$(echo ${i} |cut -b 1-10)
        ###rename if longer then 10char
        if [ "$i" != "$col" ]
            then
                ###check if new columnname already exists, e.g. name=>nam1
                list=$(db.columns table=${z})
                if [[ "$list" == *" $col "* ]]
                    then
                    x=    #no value for first iteration
                    while [[ "$list" == *" $col "* ]]
                    do
echo "WARNING: columns is already existing => renaming"
                        col=$(echo ${col} |cut -b 1-9)
                        col=$(echo ${col}${x})
                        echo "new name $col"
                        x=$(( $x + 1 ))
                    done
                fi
                v.db.renamecol map=${z} col="${i},${col}"
echo "WARNING: file ${z} => Column ${i} is renamed to ${col}"
        fi

    done
done


On 05/08/2013 10:33 AM, [email protected] wrote:
Message: 5
Date: Wed, 08 May 2013 09:28:06 +0200
From: "Patrick S."<[email protected]>
To: grass mailing list<[email protected]>
Subject: [GRASS-user] truncate column names for export?
Message-ID:<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Dear all,

Is there an option to automatically truncate column-names (sqlite) to
fit for export format in v.in.ogr?

Export to shapefile, creates errors as soon as the column-names are
longer then the dbf-format can handle. It would be great to have an
option to automatically truncate and give out a warning instead of an
error. In case of same column-names (after truncating), last letter
could be replaced by a number.

However I don't see that this is implemented yet - or did I miss something?

_______________________________________________
grass-user mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-user

Reply via email to