Skip to content

Instantly share code, notes, and snippets.

@rchardptrsn
Last active March 31, 2022 04:09
Show Gist options
  • Save rchardptrsn/bc32a536e114b85d1cc41312759bc7f5 to your computer and use it in GitHub Desktop.
Save rchardptrsn/bc32a536e114b85d1cc41312759bc7f5 to your computer and use it in GitHub Desktop.
import geopandas as gpd
from sqlalchemy import create_engine
# create the sqlalchemy connection engine
db_connection_url = "postgresql://user:password@localhost:5432/gis_db"
con = create_engine(db_connection_url)
# read in the data
gdf = gpd.read_file('shapefile/holc_ad_data.shp')
# Drop nulls in the geometry column
print('Dropping ' + str(gdf.geometry.isna().sum()) + ' nulls.')
gdf = gdf.dropna(subset=['geometry'])
# Push the geodataframe to postgresql
gdf.to_postgis("redlining", con, index=False, if_exists='replace')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment