python - 通过 geopandas 连接多个 shapefile

标签 python geopandas

我正在尝试通过执行以下操作来组合多个 shapefile:

import geopandas as gpd
import pandas as pd

for i in range(10,56):
    interesting_files = "/Users/m3105/Downloads/area/tl_2015_{}_arealm.shp".format(i)
    gdf_list = []
    for filename in sorted(interesting_files):
        gdf_list.append(gpd.read_file((filename)))
        full_gdf = pd.concat(gdf_list)

在目录/Users/m3105/Downloads/area 中有几个形状文件,例如tl_2015_01_arealm.shp, tl_2015_02_arealm.shp all一直到 tl_2015_56_arealm.shp。我想合并所有这些 shapefile 并避免重复它们的标题。但是,每当我尝试使用上面的代码连接文件时,我都会收到以下错误:

ValueError:空层:u''

通常,我知道如何将 csv 文件连接在一起,但我知道如何连接 shapefile。我将不胜感激任何帮助

最佳答案

我无法测试这个,因为我没有你的数据,但你想要这样的东西(假设是 python 3):

from pathlib import Path
import pandas
import geopandas

folder = Path("/Users/m3105/Downloads/area")
shapefiles = folder.glob("tl_2015_*_arealm.shp")
gdf = pandas.concat([
    geopandas.read_file(shp)
    for shp in shapefiles
]).pipe(geopandas.GeoDataFrame)
gdf.to_file(folder / 'compiled.shp')

关于python - 通过 geopandas 连接多个 shapefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48874113/

相关文章:

python - 非标准可选参数默认值

python - 旋转 Geoplot 多重图

python-3.x - 使用Geopandas,如何通过采样方法在每个多边形中随机选择5个点

python - 为什么在使用 imshow 显示时使用 np.hstack 对图像进行零填充会使图像变白?

python - Django 无效语法错误

python - Python Agent如何使用ElasticAPM跟踪各种计数器/值随时间的演变?

python - 使用增量文本创建 X 文本文件的脚本

python - 为什么我在 cmd 中安装任何 python 模块时收到这些错误 "WARNING: Ignoring invalid distribution -yproj "

python - 查找单个地理数据框中所有多边形中包含的重叠区域

python - Geopandas 上的颜色条