GeoPandas is one of the most famous python GIS library that can automate your GIS workflows. GeoPandas provides good functionality and features to create really good geoprocessing tools like geospatial analysis, reading/writing from/to postgis database, transforming GIS data between different formats etc.
Import Shapefile to PostgreSQL/PostGIS database using GeoPandas/Python – Spatial Dev Guru
Use GeoPandas to import shapefile to PostgreSQL/PostGIS databse
In this tutorial, we will learn how to merge multiple shapefiles into one shapefiles using geopandas. We will follow following steps to achieve this task.
- Import geopandas library.
- Read shapefiles using geopandas that you want to merge. At line number 4 and 5, we are reading multiple shapefiles. You can read as many as you want.
- Bring all those shapefiles into one common coordinate system. In this example, we converting the shapefiles into 4326 coordinate system. There may be a chance the shapefiles you are trying to merge are in different coordinate system.
- Use gpd.pd.concat method in line number 12 in below code snippet to concat multiple shapefiles into one. This particular magic line of code will get job done for us.
- Export the merged geodataframe into shapefile.
- Hurray, you have successfully merge multiple shapefiles into one.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import geopandas as gpd # Read shapefiles north_carolina = gpd.read_file('north_carolina/north_carolina.shp') south_carolina = gpd.read_file('south_carolina/south_carolina.shp') # Bring the shapefiles into common cordinate system north_carolina = north_carolina.to_crs('EPSG:4326') south_carolina = south_carolina.to_crs('EPSG:4326') # Merge/Combine multiple shapefiles into one north_south_carolina = gpd.pd.concat([north_carolina, south_carolina]) #Export merged geodataframe into shapefile north_south_carolina.to_file("north_south_carolina.shp") |
You don’t have to worry about any column difference between shapefiles. This method will automatically insert null values for shapefile which does not have common column.