如何使用简单的 kml python 创建多个多边形?

How to create several polygons with simple kml python?

我正在尝试创建一个程序来在 python 中使用 simpleKML 在 kml 中绘制多边形,我的想法是发送一个坐标列表以在不同区域创建多边形,但它对我不起作用, 你能告诉我我做错了什么吗...

这是我的代码:

def Draw(Coordenate):
for cor in Coordenate:
    print(cor[0][0], cor[0][1])
    pol = kmlA.newpolygon(name=str(cor[0]))
    pol.outerboundaryis =[  (float(cor[0][0]), float(cor[0][1])), 
                            (float(cor[1][0]), float(cor[1][1])), 
                            (float(cor[2][0]), float(cor[2][1])), 
                            (float(cor[3][0]), float(cor[3][1])), 
                            (float(cor[4][0]), float(cor[4][1])),  
                        ]
    pol.style.polystyle.color='990000ff'
    pol.style.polystyle.outline = 0
    pnt = kmlA.newpoint(name="Kirstenbosch StyleMap", coords=[cor[0]])
kmlA.save("C:/test2.kml")   

列表“cordenate”具有这种形式

如果 Draw() 函数的参数是一个多边形坐标列表,那么当您迭代该列表时,只需要将坐标列表作为新多边形的外边界。

注意在坐标元组中经度坐标必须出现在纬度之前。

import simplekml

def Draw(Coordenate):
    for cor in Coordenate:
        pol = kml.newpolygon(name=str(cor[0]))
        pol.outerboundaryis = cor
        pol.style.polystyle.color = '990000ff'
        pol.style.polystyle.outline = 0
        pnt = kml.newpoint(name="Kirstenbosch StyleMap", coords=[cor[0]])

kml = simplekml.Kml()

# example coordinates for 2 polygons
x1 = -77.039430
y1 = 38.895441
x2 = -77.033689
y2 = 38.892156

xx1 = -77.035526
yy1 = 38.889736
xx2 = -77.034781
yy2 = 38.889165

Draw([[(x1, y1),(x2, y1), (x2, y2), (x1, y2), (x1, y1)],
      [(xx1, yy1), (xx2, yy1), (xx2, yy2), (xx1, yy2), (xx1, yy1)]])
kml.save("test2.kml")