我可以在Google Earth中看到多边形
这是我用来生成.kml文件的代码:
def kmlForLab2():
#XYpoints1_wgs84
#XYpoints1_wgs84.csv
#Input the file name."JoeDupes3_forearth"
fname = input("Enter file name WITHOUT extension: ")
data = csv.reader(open(fname + '.csv'), delimiter = ',')
#Skip the 1st header row.
#data.next()
#Open the file to be written.
f = open('Buffered_kml.kml', 'w')
#Writing the kml file.
f.write("<?xml version='1.0' encoding='UTF-8'?>\n")
f.write("<kml xmlns='http://earth.google.com/kml/2.0'>\n")
f.write("<Document>\n")
f.write("<!-- first buffer -->")
f.write("<Placemark>\n")
f.write(" <name>" + fname + '.kml' +"</name>\n")
f.write(" <Polygon> <outerBoundaryIs> <LinearRing>\n")
f.write(" <coordinates>\n" )
next(data)
for row in data:
f.write(str((row[1])) + "," + " "+ (str(row[2]))+"\n")
f.write(" </coordinates>\n" )
f.write(" </LinearRing> </outerBoundaryIs> </Polygon> \n")
f.write("</Placemark>\n")
f.write("</Document>\n")
f.write("</kml>\n")
f.close()
print ("File Created. ")
print ("Press ENTER to exit. ")
它生成.kml文件,但它没有放大NZ内的多边形。发生了什么事?
Here is the code I'm using to generate .kml file:
def kmlForLab2():
#XYpoints1_wgs84
#XYpoints1_wgs84.csv
#Input the file name."JoeDupes3_forearth"
fname = input("Enter file name WITHOUT extension: ")
data = csv.reader(open(fname + '.csv'), delimiter = ',')
#Skip the 1st header row.
#data.next()
#Open the file to be written.
f = open('Buffered_kml.kml', 'w')
#Writing the kml file.
f.write("<?xml version='1.0' encoding='UTF-8'?>\n")
f.write("<kml xmlns='http://earth.google.com/kml/2.0'>\n")
f.write("<Document>\n")
f.write("<!-- first buffer -->")
f.write("<Placemark>\n")
f.write(" <name>" + fname + '.kml' +"</name>\n")
f.write(" <Polygon> <outerBoundaryIs> <LinearRing>\n")
f.write(" <coordinates>\n" )
next(data)
for row in data:
f.write(str((row[1])) + "," + " "+ (str(row[2]))+"\n")
f.write(" </coordinates>\n" )
f.write(" </LinearRing> </outerBoundaryIs> </Polygon> \n")
f.write("</Placemark>\n")
f.write("</Document>\n")
f.write("</kml>\n")
f.close()
print ("File Created. ")
print ("Press ENTER to exit. ")
It generates .kml file but it dosen't zoom into the polygon within NZ. Whats happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文档的
&lt; coordinates&gt;
部分旨在包含逗号分隔的元组,每个元组与whitespace分开。因此,这样的:或:
您的代码正在将空格插入坐标元组中间。给定的输入:
您的代码生成以下
&lt; coordinates&gt;
e节:这不正确显示。但是,如果我们修改您的代码,以便
看起来这样:
或使用
加入
这样的:我们得到:
这在Google Earth中正确显示。
The
<coordinates>
section of your document is meant to contain comma separated tuples, with each tuple separated from the next by whitespace. So like this:Or:
Your code is inserting whitespace in the middle of a coordinate tuple. Given input like this:
Your code generates the following
<coordinates>
section:This does not display correctly. But if we modify your code so that it
looks like this:
Or using
join
like this:We get:
This displays correctly in Google Earth.