Run Python script on Apache!

216 views
Skip to first unread message

Hermes Trismegistus

unread,
Nov 6, 2010, 2:44:34 PM11/6/10
to google-earth-...@googlegroups.com
I am trying to run the following Google provided python script locally on Apache (calling it from Google Earth), and have followed instructions on how to set up Apache so that it runs python scripts. In fact, I have successfully run a simple 'hello world' script, which means that Apache is running py scripts. However, calling a python script from the cgi-bin from a network link from Google Earth does not work. The scrip is called center.py, and it has the following code:


GOOGLE PROVIDED CODE:

#!/usr/bin/python

import cgi

url = cgi.FieldStorage()
bbox = url['BBOX'].value
bbox = bbox.split(',')
west = float(bbox[0])
south = float(bbox[1])
east = float(bbox[2])
north = float(bbox[3])

center_lng = ((east - west) / 2) + west
center_lat = ((north - south) / 2) + south

kml = ( 
   '<?xml version="1.0" encoding="UTF-8"?>\n'
   '<kml xmlns="http://www.opengis.net/kml/2.2">\n'
   '<Placemark>\n'
   '<name>View-centered placemark</name>\n'
   '<Point>\n'
   '<coordinates>%.6f,%.6f</coordinates>\n'
   '</Point>\n'
   '</Placemark>\n'
   '</kml>'
   ) %(center_lng, center_lat)

print 'Content-Type: application/vnd.google-earth.kml+xml\n'
print kml


MY MODIFIED VERSION:


#!c:\Python27\python.exe

import cgi

url = cgi.FieldStorage()
bbox = url['BBOX'].value
bbox = bbox.split(',')
west = float(bbox[0])
south = float(bbox[1])
east = float(bbox[2])
north = float(bbox[3])

center_lng = ((east - west) / 2) + west
center_lat = ((north - south) / 2) + south

kml = ( 
   '<?xml version="1.0" encoding="UTF-8"?>\n'
   '<kml xmlns="http://www.opengis.net/kml/2.2">\n'
   '<Placemark>\n'
   '<name>View-centered placemark</name>\n'
   '<Point>\n'
   '<coordinates>%.6f,%.6f</coordinates>\n'
   '</Point>\n'
   '</Placemark>\n'
   '</kml>'
   ) %(center_lng, center_lat)

print 'Content-Type: application/vnd.google-earth.kml+xml\n'
print kml



I feel that there is something odd with the url = cgi.FieldStorage() running locally. Would there be an alternative for this piece running locally on Apache? Or is this not the problem?

Thanks!

Hermes Trismegistus

unread,
Nov 6, 2010, 3:22:43 PM11/6/10
to KML Developer Support - Google Earth Plug-in
By the way, I found out that Apache starts running the center.py
python script, but stops because there is no value in the url
variable:

Traceback (most recent call last):
File "C:\xampp\cgi-bin\center.py", line 6, in <module>
bbox = url['BBOX'].value
File "C:\Python27\lib\cgi.py", line 541, in __getitem__
raise KeyError, key
KeyError: 'BBOX'

What I am trying to do is to get the center point from the bounding
box from Google Earth, but do so without having to send the
information to a server. I want to run it locally on Apache.
Therefore, there is no url....what would be a way to address this?

JKurtock

unread,
Nov 6, 2010, 9:01:15 PM11/6/10
to KML Developer Support - Google Earth Plug-in

Hermes Trismegistus

unread,
Nov 6, 2010, 9:50:05 PM11/6/10
to KML Developer Support - Google Earth Plug-in
I found out what the problem was...it was that BBOX was being exported
out as Bbox...and what is funny is that Bbox is the way it is most
suggested in books. I actually ended up using a similar code, but in
PHP, and it is starting to look promising. I get a model to show up in
the middle of the screen (roughly) whenever I call the PHP code. The
coordinates are also now recognized, after I turned all Bbox to BBOX
in the file calling the php. I am sure that would also solve the
problem in the python code. I will check it out when I get a chance.

Thanks!

On Nov 6, 9:01 pm, JKurtock wrote:
> Is your <Link> set correctly?
>
> https://code.google.com/intl/en/apis/kml/documentation/kmlreference.h...
Reply all
Reply to author
Forward
0 new messages