gpt4 book ai didi

python-2.7 - 将 GeoDataFrame 多边形转换为 kml 文件

转载 作者:行者123 更新时间:2023-12-03 23:46:31 25 4
gpt4 key购买 nike

我有一个带有各种多边形和颜色的 geopandas GeoDataFrame,我用它来绘制气象数据(我问的另一个问题 here):

        color   geometry
0 #fbfdd1 (POLYGON ((-97.12191717810094 32.569, -97.1194...
1 #f3fabf (POLYGON ((-97.12442748846019 32.569, -97.1219...
2 #ebf7b1 (POLYGON ((-97.12944810917861 32.569, -97.1269...
3 #daf0b2 (POLYGON ((-97.18969555780023 32.569, -97.1879...
4 #cbeab3 (POLYGON ((-97.18969555780023 32.5710632999095...
5 #afdfb6 (POLYGON ((-97.18467493708175 32.569, -97.1821...
6 #92d4b9 (POLYGON ((-97.17463369564484 32.5730575804109...
7 #74c9bc (POLYGON ((-97.17714400600408 32.5764063816167...
8 #5bbfc0 (POLYGON ((-97.17714400600408 32.5790959050363...
9 #40b5c3 (POLYGON ((-97.17463369564484 32.5814268890055...
10 #31a6c2 (POLYGON ((-97.17714400600408 32.5852716913413...
11 #2397c0 (POLYGON ((-97.17714400600408 32.5878055733984...
12 #1e83b9 (POLYGON ((-97.17714400600408 32.5895482376014...
13 #206eaf (POLYGON ((-97.17714400600408 32.5911487379959...
14 #2259a5 (POLYGON ((-97.17714400600408 32.5927834911588...
15 #23479d POLYGON ((-97.17463369564484 32.59421434681196...
16 #243594 POLYGON ((-97.17463369564484 32.5962866795434,...
17 #1a2b7d POLYGON ((-97.1721233852856 32.59996829071199,...

我想将其转换为 kml/kmz 文件,但我以前从未使用过该文件类型,所以我不确定如何继续。我试过使用 this脚本,但它需要一些我没有的高度字段。在 python 中是否有一个好的/简单的方法来做到这一点?如果可能,我想避免使用在线转换器工具。

最佳答案

fionageopandas 包裹的库支持非官方的 KML 驱动程序,您必须手动启用。

import geopandas as gpd
import fiona

fiona.supported_drivers['KML'] = 'rw'

gdf = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
gdf.to_file('test.kml', driver='KML')

请注意,它也可以读取 KML 文件,但在“嵌套”kml 文件上效果不佳,请参阅此 gist更多细节

关于python-2.7 - 将 GeoDataFrame 多边形转换为 kml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36222857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com