help ! KML + CGI + Python + localhost = cannot work

87 views
Skip to first unread message

ccfenix

unread,
Sep 27, 2007, 5:28:34 AM9/27/07
to KML Developer Support - Advanced Support
I am testing embeding some python script in the KML code so that I can
pass data for GE visualization in real time.

I tested the very naive sample code from KML tutorial. however, i do
NOT have a server, so i run it on my local windows machine.

here is the KML script, the only thing i have changed is

<href>file:///g:/kml/cgi-bin/test.py</href>

==========================
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Folder>
<name>Network Links</name>
<visibility>0</visibility>
<open>0</open>
<description>Network link example 2</description>
<NetworkLink>
<name>View Centered Placemark</name>
<visibility>0</visibility>
<open>0</open>
<description>The view-based refresh allows the remote server to
calculate
the center of your screen and return a placemark.</
description>
<refreshVisibility>0</refreshVisibility>
<flyToView>0</flyToView>
<Link>
<href>file:///g:/kml/cgi-bin/test.py</href>
<refreshInterval>2</refreshInterval>
<viewRefreshMode>onStop</viewRefreshMode>
<viewRefreshTime>1</viewRefreshTime>
</Link>
</NetworkLink>
</Folder>
</kml>
=============================

and here is my python script, the only thing i have changed is

#!c:/Python25/python.exe -u
=================================

#!c:/Python25/python.exe -u

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://earth.google.com/kml/2.1">\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 question will be : can i run my python code locally like this? I
cannot see where is the problem.

hoping gurus here could help !

thanks

Message has been deleted

bryce

unread,
Sep 27, 2007, 10:00:54 AM9/27/07
to KML Developer Support - Advanced Support
Hi,

I haven't done such things but my guess is you can't.
GE couldn't kick Python interpreter.

Think about the server's CGI. It runs codes because it's configured to
do so. No such mechanism exists locally, doesn't it?

I would be surprised if you can.
But I might be wrong... So wait until others respond.

Thanks.

Jonathan van Tuijl

unread,
Sep 27, 2007, 1:00:11 PM9/27/07
to KML Developer Support - Advanced Support
bryce wrote:
> I haven't done such things but my guess is you can't.
> GE couldn't kick Python interpreter.
>
> Think about the server's CGI. It runs codes because it's configured to
> do so. No such mechanism exists locally, doesn't it?
>
> I would be surprised if you can.
> But I might be wrong... So wait until others respond.

I would also be really surprised. Just run a script that regularly
replaces a KML file that's read by GE (by first writing it elsewhere
and then renaming over the file GE reads, so GE won't encounter
incomplete files).

Note: you won't be using HTTP locally, but when you do use HTTP header
lines should be terminated with \r\n, and the header itself with a
blank line. The result would look like "Content-Type: ...\r\n\r\n".

Jonathan

ManoM

unread,
Sep 28, 2007, 2:14:53 PM9/28/07
to KML Developer Support - Advanced Support
It is also pretty easy to set-up a low-end local http server on your
machine, or over a network, to allow you access to the view based
refresh parameters in CGI programming.

ManoM

Reply all
Reply to author
Forward
0 new messages