偶然看见有人在求什么西南区域,东北区域的shp,写一期不求人攻略。 前面写过怎么裁剪,这次讲讲怎么合并,实现区域shp自由
In [33]:
!pip install --upgrade geopandas -i https://pypi.mirrors.ustc.edu.cn/simple/
收藏
评论
In [35]:
import numpy as np
import geopandas as gpd
import matplotlib.pyplot as plt
# 读取全国地图数据
china_map = gpd.read_file('/home/mw/input/china1656/china_map/china_map/China_Province_2022.shp')
tj = china_map[china_map['省'] == '天津市']
tj = tj.rename(columns={'省': 'Province','省级码':'code','省类型':'type'})
tj.to_file('./tj.shp')
bj = china_map[china_map['省'] == '北京市']
bj =bj.rename(columns={'省': 'Province','省级码':'code','省类型':'type'})
bj.to_file('./bj.shp')
hb = china_map[china_map['省'] == '河北省']
hb =hb.rename(columns={'省': 'Province','省级码':'code','省类型':'type'})
hb.to_file('./hb.shp')
In [36]:
import geopandas as gpd
import pandas as pd
#Create geodataframes
bjs = gpd.read_file(filename = "/home/mw/project/bj.shp")
tjs = gpd.read_file(filename = "/home/mw/project/tj.shp")
hbs = gpd.read_file(filename = "/home/mw/project/hb.shp")
join = pd.concat([bjs,tjs,hbs])
join.plot()
Out[36]:
<AxesSubplot:>
ok,京津冀合并完成
In [41]:
new=gpd.overlay(bjs,hbs, how='union')
new.plot()
Out[41]:
<AxesSubplot:>
In [42]:
newnew=gpd.overlay(new,tjs, how='union')
newnew.plot()
Out[42
<AxesSubplot:>
好,相对来说还是pd.concat好用 当然arcgis软件估计容易实现