> I am trying to convert a multi column text file[*] into a table
> which I can then connect to a (5.7) vector map. I can't quite see
> how to do this. Any ideas?
> This is for a script, so "use OpenOffice & save as DBF" won't work.
>
> [*] say .csv file; col1=cat col2=attr, etc.
How about the PostgreSQL copy command?
[yes, that is the command I was looking for]
I'm still having problems:
NAME=vector_map
ATTR_FILE="${TMP}.route_atts" # includes absolute path
ATTR_COLS='cat int, route_id int, name varchar(20), start_wpt varchar(10)'
# check that 'db.connect -p' exists
# create attr database
echo "CREATE TABLE $NAME ($ATTR_COLS)" | db.execute
# next populate it
echo "COPY $NAME FROM '$ATTR_FILE'" | db.execute
# finally connect it to existing vector map
v.db.connect map="$NAME" table="$NAME"
The COPY step gives an error though:
($GISDBASE/$LOCATION/$MAPSET/.tmp/$HOSTNAME/ shortened to /tmp here)
[...]
v.in.ascii: line vector "test_rte" successfully created
D2/5: add_table(): table = test_rte name = test_rte.dbf
D3/5: sql: COPY test_rte FROM '/tmp/23569.0.route_atts'
DBMI-DBF driver error:
SQL parser error in statement:
COPY test_rte FROM '/tmp/23569.0.route_atts'
Error in db_execute_immediate()
WARNING: Error while executing: "COPY test_rte FROM
'/tmp/23569.0.route_atts'
"
I don't see the parser error.
I could probably do "INSERT INTO table VALUES (values, ..)" line by
line, but that seems wasteful and slow.
Hamish