Python 3.x 在Python中用geopandas重叠两个shapefile
我有这两个形状文件。 [链接1上带有省份的第一个形状文件] [链接2上带地区的第二个形状文件] 我需要连接/合并这两个shapefile以返回一个映射,如下所示: [![莫桑比克地区如下图所示] moz_admin=: moz_admin_district=[2]: 到目前为止我所做的:Python 3.x 在Python中用geopandas重叠两个shapefile,python-3.x,merge,gis,shapefile,geopandas,Python 3.x,Merge,Gis,Shapefile,Geopandas,我有这两个形状文件。 [链接1上带有省份的第一个形状文件] [链接2上带地区的第二个形状文件] 我需要连接/合并这两个shapefile以返回一个映射,如下所示: [![莫桑比克地区如下图所示] moz_admin=: moz_admin_district=[2]: 到目前为止我所做的: import os import geopandas as gpd file = os.listdir(r'pathtofilefolder') path = [os.path.join(r'folder'
import os
import geopandas as gpd
file = os.listdir(r'pathtofilefolder')
path = [os.path.join(r'folder', i) for i in file if ".shp" in i]
gdf = gpd.GeoDataFrame(pd.concat([gpd.read_file(i) for i in path],
ignore_index=True), crs=gpd.read_file(path[0]).crs)
及
及
及
及
及
及
及
及
没有成功
#OVERLAP TWO SHAPEFILES INTO ONE
ax = moz_admin.plot(color='none', edgecolor='black', linewidths=1.5)
moz_admin_district.plot(ax=ax, color='none', edgecolor='grey', linewidths=0.5)
diffs = []
gdfs = [moz_admin, moz_admin_district]
for idx, gdf in enumerate(gdfs):
if idx < 2:
diffs.append(gdf.symmetric_difference(gdfs[idx+1]).iloc[0])
diffs.append(moz_admin_district.iloc[0].geometry)
gdf = gpd.GeoDataFrame(pd.concat([moz_admin, moz_admin_district]))
from shapely.geometry import Polygon
res_union = gpd.overlay(moz_admin, moz_admin_district, how='union')
so = moz_admin.merge(moz_admin_district, on='ADM1_PT', how='inner')
df = tab_df.merge(spatial_df, on='mukey', how='right')
sof = gpd.GeoDataFrame(so)
merged_master = gpd.GeoDataFrame(pd.merge(moz_admin, moz_admin_district, how='left', left_on="ADM1_PT", right_on="ADM1_PT"))
merged = merged_master[['ADM1_PT', 'ADM2_PT', 'geometry']]
so = gpd.GeoDataFrame(pd.concat([moz_admin, moz_admin_district], ignore_index=True))
sjoined_listings = gpd.sjoin(moz_admin_district, moz_admin, op='intersects')
merged=sjoin(moz_admin_district, moz_admin, how='left', op='intersects')
#OVERLAP TWO SHAPEFILES INTO ONE
ax = moz_admin.plot(color='none', edgecolor='black', linewidths=1.5)
moz_admin_district.plot(ax=ax, color='none', edgecolor='grey', linewidths=0.5)