Last active
October 30, 2021 16:40
-
-
Save iamgeoknight/15a9d9e8093aac2fc119c7af1d4686ba to your computer and use it in GitHub Desktop.
Shapefile Import using GeoPandas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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