jeudi 2 avril 2015

Why is my code coming up with this error object of type 'float' has no len() when trying to create a KML

I am trying to get a KML file created from long and lat taken from SQLite database however it keeps coming up with error object of type 'float' has no len() any advice would be much appreciated.



import sqlite3
from time import strftime
from datetime import datetime
import simplekml


db = sqlite3.connect('da_destination_history')
cursor = db.cursor()
cursor.execute('''SELECT time, dest_lat, dest_lng, source_lat, source_lng FROM destination_history''')
all_rows = cursor.fetchall()
kml = simplekml.Kml()
for row in all_rows:
# row[0] returns the first column in the query (time), row[1] returns dest_lat column etc....
print('{0} : {1}, {2}'.format(row[0], float(row[1])/1000000, float(row[2])/1000000))
# puts time into a variable
ttime = row[0]
lat = (float(row[1])/1000000)
long = (float(row[2])/1000000)
# converts the milisecond epoch time into human readable time (divive by 1000 is there
# as it is miliseconds
contime = datetime.fromtimestamp(int(ttime)/1000).strftime('%Y-%m-%d %H:%M:%S')
print(contime)
print (lat)
print (long)
for row in all_rows:
kml.newpoint(name="Kirstenbosch Start", coords=[(lat),(long)])

kml.save("andriod.kml")

Aucun commentaire:

Enregistrer un commentaire