Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining shapefiles in Python / GeoPandas

I have three polygon shapefiles which overlap each other. Let's call them:

  • file_one.shp (polygon Name is 1)
  • file_two.shp (polygon Name is 2)
  • file_three.shp (polygon Name is 3)

I want to combine them and keep the values like this.

enter image description here

How can I achieve the result (As shown in the figure) in Python, please?

Thanks!

like image 643
TheRealJimShady Avatar asked Sep 01 '26 22:09

TheRealJimShady


1 Answers

If you want to simply create one shapefile from files you've mentioned you can try following code (I assume that shapefiles has same columns).

import pandas as pd
import geopandas as gpd

gdf1 = gpd.read_file('file_one.shp')
gdf2 = gpd.read_file('file_two.shp')
gdf3 = gpd.read_file('file_three.shp')

gdf = gpd.GeoDataFrame(pd.concat([gdf1, gdf2, gdf3]))
like image 86
lukaszKielar Avatar answered Sep 04 '26 12:09

lukaszKielar