QGIS Road to Nerdvana Episode 18: Introduction to PostgreSQL and PostGIS
Channel: Kartoza
Date: 02/03/2021

This is a walk-through showing how PostgreSQL and PostGIS can be used as a geospatial data store and then the data in that store be consumed and created by geopandas.


Here is the python demo.py created in the video


import geopandas as gpd
import psycopg2  # (if it is Postgres/PostGIS)
from sqlalchemy import create_engine

con = psycopg2.connect(
    database="demo",
    user="demo",
    password="demo",
    host="localhost")

sql = "select * from vw_clusters;"

df = gpd.GeoDataFrame.from_postgis(sql, con, geom_col='geom' )
print(df.head())

engine = create_engine("postgres://demo:demo@localhost:5432/demo")
df.to_postgis("test", engine)