English 中文(简体)
Liteweight CGI Server to use on local machine to serve KML to Google Earth via Python or similar?
原标题:

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.

最佳回答

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.

问题回答

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.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签