views:

200

answers:

2

Greetings,

I want to write a script that handles simple http requests from Google Earth and sends back KML to display map tiles that are stored locally. I would LIKE to use Python but any language is fine. I have not ever done anything with CGI, but I think this is the simplest way to accomplish my task. This is what the Google KML docs use, is Python CGI scripts to talk to Google Earth. Is there a CGI server that I can download (and run on Windows 7, or if absolutely necessary I could build a VM running linux) that I can just drop my Python script onto and go?

Basically, as I move around the screen in Google Earth, it will send a request to my server, which will tell Google Earth what to show on the screen. Simple.

Background: I am doing a lot of driving with my laptop beside me, with a USB GPS receiver that updates my location in realtime on Google Earth. But, since I am OFFLINE, I cannot dynamically download map tiles from Google Maps so that I can see street names and such. I have been downloading the map tiles and patching them together as one big PNG to cover the city I will be driving in, and then importing those images as an Overlay in Google Earth, but I would like to build a server that runs locally, taps into a database of map tiles stored on the machine, and serves up the KML to display those tiles as an overlay instead of having to do all that work ahead of time each time I make a trip.

+1  A: 

If I were you I'd use MapServer and Tilecache to do exactly that (serving up georeferenced raster imagery over http / python mapscript bindings available).

If you want plain cgi you can probably use lighthttpd or nxginx or similar.

Also note that scraping the google map tiles is very likely infringing their terms of use.

ChristopheD
The lighttpd server doesn't have a mod_wsgi module. Using CGI as you suggest doesn't even need mod_wsgi anyway.
Graham Dumpleton
Good points, I'll update my answer ;-)
ChristopheD
+1  A: 

CGIHTTPServer in the standard library.

# current directory containing cgi-bin directory with scripts in
# subclass CGIHTTPRequestHandler and override cgi_directories to change this
#
os.chdir('/path/to/htdocs')

BaseHTTPServer.HTTPServer(('',80), CGIHTTPServer.CGIHTTPRequestHandler).serve_forever()

It ain't fast, it's pretty limited (you can't return anything but 200 OK responses, for one) and it probably ain't wholly secure, but for this sort of local job it's fine.

bobince