我正在尝试通过执行以下操作来组合多个 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/