需要特别注意geopandas包的安装,可以参考博客:手把手教学如何安装geopandas
import geopandas as gpd
def getIntersec(shpfile1,shpfile2,outshp):
shp1 = gpd.read_file(shpfile1)
shp2 = gpd.read_file(shpfile2)
intersec = gpd.overlay(shp1,shp2,how="intersection")
intersec.to_file(outshp,encoding="utf-8")
if __name__ == "__main__":
shpfile1=r"D:/1.shp"
shpfile2=r"D:/2.shp"
outshp=r"D:/jiaoji.shp"
getIntersec(shpfile1,shpfile2,outshp)