Python生成KML但未正确显示在Google地球网络链接中

时间:2012-04-29 11:57:04

标签: sql python-3.x kml google-earth pyodbc

如果光标有很多行,生成的kml不会显示在google earth中,但生成的代码可以通过python shell看到..如果行数较少(7或8),则此脚本可以轻松生成网络链接对于google earth中的kml文件..感谢您的帮助

import pyodbc
kml = ('<?xml version="1.0" encoding="UTF-8"?>\n'
'<kml xmlns="http://www.opengis.net/kml/2.2"xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">\n'
'<Document>\n'
'<name>documentname</name>\n'
'<StyleMap id="default">\n'
'<Pair>\n'
'<key>normal</key>\n'
'<styleUrl>#default0</styleUrl>\n'
'</Pair>\n'
'<Pair>\n'
'<key>highlight</key>\n'
'<styleUrl>#hl</styleUrl>\n'
'</Pair>\n'
'</StyleMap>\n'
'<Style id="hl">\n'
'<IconStyle>\n'
'<scale>1.2</scale>\n'
'</IconStyle>\n'
'</Style>\n'
'<Style id="default0">\n'
'</Style>\n'
'<Folder>\n'
'<name>foldername</name>')

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


def placemarkize(rowdata):
 placemark = (
 '<Placemark>\n'
 '<name>%s</name>\n'
 '<Point>\n'
 '<coordinates>%f,%f</coordinates>\n'
 '</Point>\n'
 '</Placemark>'
 ) %(rowdata[1],rowdata[11],rowdata[10])
 print(placemark)
 return ()


conn = pyodbc.connect('Driver={SQL Server};server=research;database=database;uid=;pwd=')
cur=conn.cursor()
cur.execute("select * from tbltvet where district like 'kas%'")
while 1:
row = cur.fetchone()
if not row:
    break
placemarkize(row)


kml = ('</Folder>\n</Document>\n</kml>')

print (kml)
conn.close()

0 个答案:

没有答案