我需要从800多个区域的数据框中创建一个.kml文件。 这是我到目前为止所做的:
1)使用PANDAS读取.csv文件(图1)
2)通过仅选择前三列(经度,纬度,高度)来创建新的数据框
3)从数据框中创建一个元组列表
4)创建一个.kml文件并进行一些样式设置(颜色)
只有在1个地区时,所有这些程序才有效。现在,我需要执行同样的操作,但要覆盖800多个地区。在图2中,显示了一个具有2个地区(actONO和AILSACRAIGO)的示例。
将数据框转换为元组列表时,如何使“ python”知道有很多区?
我相信这些行必须加以改进:
a)在这里,我需要一个元组列表(每个地区一个)
#Converting the dataframe to a list of tuples
tuples = [tuple(x) for x in df_modify.values]
b)在这里,每个元组的“边界”必须更改
pol = kml.newpolygon(name= 'actONO',description= 'acton County',outerboundaryis=tuples,extrude=extrude,altitudemode=altitudemode)
这是所有代码:
具有1个区域的.CSV的代码
import pandas
import simplekml
kml = simplekml.Kml()
#Using PANDAS to read .csv and chosing the first 3 columns
df = pandas.read_csv('C:\\Users\\disa_ONTshp.csv')
df_modify=df.iloc[:,[0,1,2]]
#Converting the dataframe to a list of tuples
tuples = [tuple(x) for x in df_modify.values]
#Creating a .kml file
extrude=1
altitudemode = simplekml.AltitudeMode.relativetoground
pol = kml.newpolygon(name= 'actONO',altitudemode=altitudemode)
#Styling colors
pol.style.linestyle.color = simplekml.Color.green
pol.style.linestyle.width = 5
pol.style.polystyle.color = simplekml.Color.changealphaint(100,simplekml.Color.green)
#Saving
kml.save("Polygon Styling.kml")
图1(1个区域)
图2(2个区域)