Python Dynamic Refresh kml

Source: Internet
Author: User

The effect of the following code is that kml uses networklink to continuously execute phython code on the server and dynamically change the longitude and latitude coordinates of points.

First, create a new virtual directory under the default website under Internet information service, and then create an application on the "virtual directory" tab under the directory, and then click "Configure ", go to "application configuration", click Add (for example), and click "OK.

 

 

Create the randomplacemark. py file in the resource manager of this directory. The Code is as follows:

 

 #! C:/python25/python.exe #! The above changes to your own Python installation path

Import random

Latitude = random. randrange (-90, 90)
Longpolling = random. randrange (-180,180)
Kml = (
'<? XML version = "1.0" encoding = "UTF-8"?> \ N'
'<Kml xmlns = "http://www.opengis.net/kml/2.2"> \ N'
'<Placemark> \ N'
'<Name> random placemark </Name> \ N'
'<Point> \ N'
'<Coordinates> % d, % d </coordinates> \ N'
'</Point> \ N'
'</Placemark> \ N'
'</Kml>'
) % (Longpolling, latitude)
Print 'content-type: Application/vnd. google-earth.kml + XML \ N'
Print kml

 

Create a new file named test. kml.

 <? XML version = "1.0" encoding = "UTF-8"?>
<Kml xmlns = "http://www.opengis.net/kml/2.2">
<Folder>
<Name> network links </Name>
<Visibility> 1 </visibility>
<Open> 0 </Open>
<Description> network link Example 1 </description>
<Networklink>
<Name> random placemark </Name>
<Visibility> 1 </visibility>
<Refreshvisibility> 1 </refreshvisibility>
<Open> 0 </Open>
<Description> A simple server-side script that generates a new random
Placemark on each call </description>
<Refreshvisibility> 0 </refreshvisibility>
<Flytoview> 1 </flytoview>
<Link>
<Href> http: // computername/virtual directory name/randomplacemark. py <Refreshmode> oninterval </refreshmode>
<Refreshinterval> 5 </refreshinterval>
<Viewrefreshmode> onstart </viewrefreshmode>
<Viewrefreshtime> 4 </viewrefreshtime>
</Link>
</Networklink>
</Folder>
</Kml>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.