From 3839bfe9a3d3c9015260b9500bff597fbfe5595b Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 24 Jun 2011 02:45:39 -0400 Subject: Live-feed support for Google Earth. --- gegps | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 gegps (limited to 'gegps') diff --git a/gegps b/gegps new file mode 100644 index 00000000..725568ef --- /dev/null +++ b/gegps @@ -0,0 +1,101 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# usage: gegps [-i] [-d kmldir] +# +# Feed location data from a running GPSD to a Google Earth instance. +# The -d argument is the location of the Google Earth installation +# directory. If not specified, it defaults to the current directory. +# +# If you have the free (non-subscription) version, start by running with +# the -i option to drop a clue in the Google Earth installation directory, +# as 'Open_in_Google_Earth_RT_GPS.kml', then open that file in Places +# (File > Open...), +# +# The basic recipe is here: +# http://tjworld.net/wiki/Linux/Ubuntu/GoogleEarthPlusRealTimeGPS +# +# This code originally by Jaroslaw Zachwieja and a guy referring +# to himself/herself as TJ(http://tjworld.net) +# Modified by Chen Wei for use with gpsd +# Cleaned up and adapted for the GPSD project by Eric S. Raymond. + +import time, os, gps, getopt +import sys + +KML_OPEN_IN_GE = '''\ + + + + Realtime GPS + 1 + + Realtime_GPS.kml + onInterval + + + +''' + +def kmlize(tpv): + '''http://code.google.com/apis/kml/documentation/kmlreference.html + for official kml document''' + latitude = tpv['lat'] + longitude = tpv['lon'] + speed_in = tpv['speed'] # meter/second + speed = speed_in * gps.MPS_TO_KPH # Km/h + heading = int(round(tpv['track'], 0)) + altitude = tpv['alt'] + + if speed < 1: + heading = 0 + + return """ + + + %s km/h,heading %s + Realtime GPS feeding + + %s + %s + + + %s,%s,%s + + +""" % (speed,heading,longitude,latitude,longitude,latitude,altitude) + + +if __name__ == "__main__": + session = gps.gps() + # must include gps.WATCH_NEWSTYLE on my system(debian squeeze), otherwise + # there is no TPV report + session.stream(gps.WATCH_ENABLE|gps.WATCH_NEWSTYLE) + + kmldir = "." + initialize = False + (options, arguments) = getopt.getopt(sys.argv[1:], "d:i") + for (opt, arg) in options: + if opt == '-d': + kmldir = arg + elif opt == '-i': + initialize = True + + if initialize: + f = open(os.path.join(kmldir, 'Open_in_Google_Earth_RT_GPS.kml'), 'w') + f.write(KML_OPEN_IN_GE) + f.close() + else: + try: + while True: + report = session.next() + if report['class'] == 'TPV': + f = open(os.path.join(kmldir, 'Realtime_GPS.kml'), 'w') + f.write(kmlize(report)) + f.close() + except StopIteration: + pass + except KeyboardInterrupt: + print 'gegpsd stopped ' + +# end -- cgit v1.2.1