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
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.
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