Python動態重新整理kml

來源:互聯網
上載者:User

      以下小段代碼達到的效果是kml利用networklink不斷去執行伺服器上的phython代碼,動態改變點的經緯度座標。

首先在Internet資訊服務下預設網站下建立虛擬目錄,然後在該目錄下的“虛擬目錄”選項卡中建立應用程式,再點擊“配置”,進入“應用程式配置”,點擊添加(如),最後確定。

 

 

在該目錄的資源管理員下建立randomPlacemark.py檔案,代碼如下:

 

#!C:/Python25/python.exe#!以上更改為自己的python安裝路徑

import random

latitude = random.randrange(-90, 90)
longitude = 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>'
) %(longitude, latitude)
print 'Content-Type: application/vnd.google-earth.kml+xml\n'
print kml

 

然後建立檔案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/虛擬目錄名/randomPlacemark.py</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>5</refreshInterval>
<viewRefreshMode>onStart</viewRefreshMode>
<viewRefreshTime>4</viewRefreshTime>
</Link>
</NetworkLink>
</Folder>
</kml>

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.