Hi all,
just wanted to share some scripts I used.
The first one is for converting a list of points out of a kml file to a poi
sqlite3 database which tangogps can read, and the other one is for doing the
reverse operation : getting the pois of the tango gps db and creating a kml
file.
It might need some tweaking, as some things are hard coded.
Note that I also extracted the points of the kml file with my favorite
"excel like" program into a plain file listing all points.
Hoping that it will save someone's time,
Thomas
#!/usr/bin/python
# -*- coding: UTF-8 -*-


import os.path
import sqlite3
import time

file = '/home/root/myfile.txt'
database = sqlite3.connect('/home/root/.tangogps/poi.db', isolation_level=None)

FILE = open(file,'r')

for line in FILE:
	coords = line.split(',')
	print "Coordonnees : lat = %s, lon = %s" % (coords[0], coords[1])
	current_time = time.time()
	db_call = "INSERT INTO poi (idmd5, lat, lon, visibility, cat, subcat, keywords, desc, price_range, extended_open) VALUES (?,?,?,?,?,?,?,?,?,?) "
	print database.execute(db_call, ('%s' % current_time, coords[1], coords[0], 1, 1, 0, '', '', 3, 0)).rowcount > 0

FILE.close()

database.close()

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os.path
import sqlite3
import time

my_category = 0

database = sqlite3.connect('/home/root/.tangogps/poi.db')
pois = database.execute("SELECT * FROM POI WHERE cat=?", (my_category,) ).fetchall()
database.close()

file = '/home/root/myfile.kml'
FILE = open(file,'w')
FILE.truncate(0)

FILE.write('<?xml version="1.0" encoding="iso-8859-1"?>\n')
FILE.write('<kml xmlns="http://earth.google.com/kml/2.0";>\n')
FILE.write('<Document>\n')
FILE.write('<Folder>\n')
FILE.write('<name>Point Features</name>\n')
FILE.write('<description>Point Features</description>\n')

i = 1
for poi in pois:
	print '%s : %f, %f' % (poi, poi[2],poi[1],)
	FILE.write('<Placemark>\n')
	FILE.write('<name><![CDATA[%i]]></name>\n' % i)
	FILE.write('<description><![CDATA[Lat: %f <br> Lon: %f<br>]]></description>\n' % (poi[1],poi[2]) )
	FILE.write('<Point>\n')
	FILE.write('<coordinates>%f,%f,0</coordinates>\n' % (poi[2],poi[1],))
	FILE.write('</Point>\n')
	FILE.write('</Placemark>\n')
	i = i + 1

FILE.write('</Folder>\n')
FILE.write('</Document>\n')
FILE.write('</kml>\n')
FILE.close()


#	db_call = "INSERT INTO poi (idmd5, lat, lon, visibility, cat, subcat, keywords, desc, price_range, extended_open) VALUES (?,?,?,?,?,?,?,?,?,?) "


_______________________________________________
Openmoko community mailing list
[email protected]
http://lists.openmoko.org/mailman/listinfo/community

Reply via email to