diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2011-06-24 02:45:39 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2011-06-24 02:45:39 -0400 |
commit | 3839bfe9a3d3c9015260b9500bff597fbfe5595b (patch) | |
tree | cc6a5d45f3909c4b87ecb862dafb5b784cd0843c | |
parent | ba3def7de3c110a7901c40921cca51f8700bc8d3 (diff) | |
download | gpsd-3839bfe9a3d3c9015260b9500bff597fbfe5595b.tar.gz |
Live-feed support for Google Earth.
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | SConstruct | 3 | ||||
-rw-r--r-- | gegps | 101 | ||||
-rw-r--r-- | gps.xml | 29 |
4 files changed, 130 insertions, 6 deletions
@@ -12,7 +12,8 @@ an scons build recipe. Direct support for activation of gpsd from Mac OS/X systemd. gpsdecode can now filter reports by RTCM2, RTCM3, or AIS message type. NMEA HEHDT is implemented. Remote gpsd instances - ca now be used as data sources via a gpsd:// URL. + can now be used as data sources via a gpsd:// URL. There is a client + for live-feeding GPSD data to Google Earth. * Mon Mar 21 2011 Eric S. Raymond <esr@snark.thyrsus.com> - 2.96 Bumped maximum channel count to 32 to accommodate GPS+GLONASS devices. @@ -738,7 +738,7 @@ if cxx and env["libgpsmm"]: testprogs.append(test_gpsmm) # Python programs -python_progs = ["gpscat", "gpsfake", "gpsprof", "xgps", "xgpsspeed"] +python_progs = ["gpscat", "gpsfake", "gpsprof", "xgps", "xgpsspeed", "gegps"] python_modules = Glob('gps/*.py') # Build Python binding @@ -884,6 +884,7 @@ python_manpages = { "gpscat.1" : "gpscat.xml", "xgpsspeed.1" : "gps.xml", "xgps.1" : "gps.xml", + "gegps.1" : "gps.xml", } manpage_targets = [] @@ -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 <weichen302@aol.com> 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 = '''\ +<?xml version="1.0" encoding="UTF-8"?> +<kml xmlns="http://earth.google.com/kml/2.2"> +<NetworkLink> + <name>Realtime GPS</name> + <open>1</open> + <Link> + <href>Realtime_GPS.kml</href> + <refreshMode>onInterval</refreshMode> + </Link> +</NetworkLink> +</kml> +''' + +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 """<?xml version="1.0" encoding="UTF-8"?> +<kml xmlns="http://earth.google.com/kml/2.0"> +<Placemark> + <name>%s km/h,heading %s</name> + <description>Realtime GPS feeding</description> + <LookAt> + <longitude>%s</longitude> + <latitude>%s</latitude> + </LookAt> + <Point> + <coordinates>%s,%s,%s</coordinates> + </Point> +</Placemark> +</kml>""" % (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 @@ -89,9 +89,6 @@ BSD terms apply: see the file COPYING in the distribution root for details. </group> </cmdsynopsis> <cmdsynopsis> - <command>gpxlogger</command> -</cmdsynopsis> -<cmdsynopsis> <command>gpxlogger</command> <arg choice='opt'>-D <replaceable>debug-level</replaceable></arg> <arg choice='opt'>-d </arg> @@ -110,6 +107,11 @@ BSD terms apply: see the file COPYING in the distribution root for details. </group> </group> </cmdsynopsis> +<cmdsynopsis> + <command>gegps</command> + <arg choice='opt'>-d <replaceable>directory</replaceable></arg> + <arg choice='opt'>-i </arg> +</cmdsynopsis> </refsynopsisdiv> <refsect1 id='description'><title>DESCRIPTION</title> @@ -299,6 +301,24 @@ defaulted to, you may give a server-port-device specification as arguments.</para> </refsect2> +<refsect2><title>gegps</title> + +<para>This program collects fixes from <application>gpsd</application> +and feeds them to a running instance of Google Earth for live location +tracking.</para> + +<para>The <option>-d</option> argument is the location of the Google +Earth installation directory. If not specified, it defaults to the +current directory.</para> + +<para>If you have the free (non-subscription) version, start by +running with the <option>-i</option> 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...). Run <application>gpsd</application> in the normal way +after that.</para> + +</refsect2> </refsect1> <refsect1 id='see_also'><title>SEE ALSO</title> <para> @@ -320,7 +340,8 @@ arguments.</para> Remco Treffcorn, Derrick Brashear, Russ Nelson & Eric S. Raymond, Jeff Francis (cgps). Amaury Jacquot <email>sxpert@sxpert.org</email> & Petter Reinholdtsen <email>pere@hungry.com</email> (gpxlogger). -Chris Kuethe <email>chris.kuethe@gmail.com</email> (gpxlogger). +Chris Kuethe <email>chris.kuethe@gmail.com</email> (gpxlogger), Chen +Wei <email>weichen302@aol.com</email> (gegps). </para> <para>This manual page by Eric S. Raymond <email>esr@thyrsus.com</email>. |