如何将多个 Geopandas 地理数据框导出到一个 KMZ 文件

问题描述

I asked this on GIS Stack Exchange,但它没有获得多少浏览量和回复;所以我在这里尝试(如果不允许,请告诉我)。

我有两个 Geopandas 地理数据框,我想将它们导出到具有嵌套文件夹结构的 KMZ 文件。下面是创建地理数据框的独立代码,以及我希望 KMZ 结构外观的屏幕截图。

我想在没有 ArcGIS 或 QGIS 的情况下执行此操作。使用 Python 3.7。

###############################################
### load libraries
###############################################
import matplotlib.pyplot as plt
%matplotlib inline
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point
from shapely.geometry import Linestring

###############################################
### Build Stand-Alone Geodataframes
### 'p' is a points-type gdf
### 'pl' is a polyline-type gdf
###############################################

pname = ['Project1'] * 5
id1 = [1,2,3,4,5]
lat = [36.42,36.4,36.32,36.28,36.08]
long = [-118.11,-118.12,-118.07,-117.95,-117.95]
cat = ['X','X','Y','Y']
id2 = ['A','A','B','B']
df = pd.DataFrame(list(zip(pname,id1,lat,long,cat,id2)),columns =['pname','id1','lat','long','cat','id2']) 
df.reset_index(drop=True,inplace=True)


p = gpd.GeoDataFrame(df,geometry=gpd.points_from_xy(df['long'],df['lat']))
p = p.set_crs(epsg=4326)
display(p.style)


pl = p.groupby(['pname','id2'])['geometry'].apply(lambda x: Linestring(x.tolist()))
pl = gpd.GeoDataFrame(pl,geometry='geometry').reset_index()
pl = pl.set_crs(epsg=4326)
display(pl.style)


fig,(ax1,ax2) = plt.subplots(1,sharex=True,sharey=True)
p.plot(ax=ax1)
pl.plot(ax=ax2)
ax1.set_aspect('equal')

enter image description here

所需的文件夹结构

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...