我可以在Google Earth中看到多边形

发布于 2025-01-28 00:42:12 字数 1328 浏览 5 评论 0原文

这是我用来生成.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

临风闻羌笛 2025-02-04 00:42:12

文档的&lt; coordinates&gt;部分旨在包含逗号分隔的元组,每个元组与whitespace分开。因此,这样的:

-77.05788457660967,38.87253259892824,100
-77.05465973756702,38.87291016281703,100

或:

-77.05788457660967,38.87253259892824,100 -77.05465973756702,38.87291016281703,100

您的代码正在将空格插入坐标元组中间。给定的输入:

unknown column,lat,lon,ele
1,-77.05788457660967,38.87253259892824,100
2,-77.05465973756702,38.87291016281703,100
3,-77.05315536854791,38.87053267794386,100
4,-77.05552622493516,38.868757801256,100
5,-77.05844056290393,38.86996206506943,100
6,-77.05788457660967,38.87253259892824,100

您的代码生成以下&lt; coordinates&gt; e节:

<coordinates>
-77.05788457660967, 38.87253259892824
-77.05465973756702, 38.87291016281703
-77.05315536854791, 38.87053267794386
-77.05552622493516, 38.868757801256
-77.05844056290393, 38.86996206506943
-77.05788457660967, 38.87253259892824
</coordinates>

这不正确显示。但是,如果我们修改您的代码,以便
看起来这样:

    for row in data:
        f.write(str((row[1])) + "," + (str(row[2]))+"\n") 

或使用加入这样的:

    for row in data:
        f.write(",".join(str(x) for x in row[1:3]))
        f.write("\n")

我们得到:

<coordinates>
-77.05788457660967,38.87253259892824
-77.05465973756702,38.87291016281703
-77.05315536854791,38.87053267794386
-77.05552622493516,38.868757801256
-77.05844056290393,38.86996206506943
-77.05788457660967,38.87253259892824
</coordinates>

这在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:

-77.05788457660967,38.87253259892824,100
-77.05465973756702,38.87291016281703,100

Or:

-77.05788457660967,38.87253259892824,100 -77.05465973756702,38.87291016281703,100

Your code is inserting whitespace in the middle of a coordinate tuple. Given input like this:

unknown column,lat,lon,ele
1,-77.05788457660967,38.87253259892824,100
2,-77.05465973756702,38.87291016281703,100
3,-77.05315536854791,38.87053267794386,100
4,-77.05552622493516,38.868757801256,100
5,-77.05844056290393,38.86996206506943,100
6,-77.05788457660967,38.87253259892824,100

Your code generates the following <coordinates> section:

<coordinates>
-77.05788457660967, 38.87253259892824
-77.05465973756702, 38.87291016281703
-77.05315536854791, 38.87053267794386
-77.05552622493516, 38.868757801256
-77.05844056290393, 38.86996206506943
-77.05788457660967, 38.87253259892824
</coordinates>

This does not display correctly. But if we modify your code so that it
looks like this:

    for row in data:
        f.write(str((row[1])) + "," + (str(row[2]))+"\n") 

Or using join like this:

    for row in data:
        f.write(",".join(str(x) for x in row[1:3]))
        f.write("\n")

We get:

<coordinates>
-77.05788457660967,38.87253259892824
-77.05465973756702,38.87291016281703
-77.05315536854791,38.87053267794386
-77.05552622493516,38.868757801256
-77.05844056290393,38.86996206506943
-77.05788457660967,38.87253259892824
</coordinates>

This displays correctly in Google Earth.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文