Skip to content

Instantly share code, notes, and snippets.

@iamgeoknight
Last active October 30, 2021 16:40
Show Gist options
  • Save iamgeoknight/15a9d9e8093aac2fc119c7af1d4686ba to your computer and use it in GitHub Desktop.
Save iamgeoknight/15a9d9e8093aac2fc119c7af1d4686ba to your computer and use it in GitHub Desktop.
Shapefile Import using GeoPandas
from sqlalchemy import create_engine
import geopandas as gpd
user = "postgres"
password = "admin"
host = "localhost"
port = 5432
database = "postgis_in_action"
conn = f"postgresql://{user}:{password}@{host}:{port}/{database}"
engine = create_engine(conn)
#Read shapefile using GeoPandas
gdf = gpd.read_file("boundary_shp/boundary.shp")
#Import shapefile to databse
gdf.to_postgis(name="boundary", con=engine, schema="public")
print("success")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment