View Single Post
rcull's Avatar
Posts: 299 | Thanked: 168 times | Joined on Jun 2006 @ Wales UK
#6
Tobler
I have a small shell script /awk prog to do this. I have downloaded sqlite 2.8.17 ( sqlite3 does not read Maemo Mappers poi.db! ) to my Linux box. I copy poi.db( probably unnecessary) and csv file to the sqlite folder and run :-
./csv2sql WiFi.csv | ./sqlite poi.db 13
where 13 is a category either added or allready there within MM.
The script is as follows :-

Code:
cat "$1"| tr -d "\r" | awk -v Categ="$2" '
BEGIN { FS="," }
{
 Inv="\x27"
 Lat=$2
 Lon=$1
 Label=$3
 Desc=$4
 Sql="INSERT INTO poi(lat,lon,label,desc,cat_id) VALUES("
 Close=");"
 Label = Inv Label Inv
 if ( Desc == "" ) {
   Desc = Inv Inv
 } else {
   Desc = Inv Desc Inv
 }
 printf("%s%s,%s,%s,%s,%s%s \n",Sql,Lat,Lon,Label,Desc,Categ,Close)
}'
The
Code:
tr -d "\r"
is there to remove a troublesome ^M from the original file ( Transferring an MS file to Linux ). The script is only expecting 4 columns of which the last may be blank. It does not correctly handle columns like addresses seperated with commas ie "14 St Johns St, Banbury" but as we have the lat long anyway and accurate Google maps I have not bothered to play with it. In fact I usually just remove the forth column and leave a "," .
As usual 'Use at your oun risk'

Edit: The csv files I have are all in the order "Lon,Lat,Label,Desc" hence the swap of $2 $1. If the other way round make it Lat=$1,Lon=$2

Last edited by rcull; 2007-02-01 at 21:33.