0% found this document useful (0 votes)
40 views

How To Connect and Use A Geospatial Database in Python

This code connects to a PostgreSQL database and extracts listing data including name, host name, room type, price, reviews per month, neighborhood, and geom location. It creates an engine to connect to the specified database using SQLAlchemy and queries the listings table. Then it loads the results into a GeoPandas GeoDataFrame and previews the first few rows.

Uploaded by

ante mitar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

How To Connect and Use A Geospatial Database in Python

This code connects to a PostgreSQL database and extracts listing data including name, host name, room type, price, reviews per month, neighborhood, and geom location. It creates an engine to connect to the specified database using SQLAlchemy and queries the listings table. Then it loads the results into a GeoPandas GeoDataFrame and previews the first few rows.

Uploaded by

ante mitar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

import geopandas as gpd

from sqlalchemy import create_engine

# Create a connection
# Create Connector engine
engine = create_engine(f'postgresql://USER:PASWORD@ADDRESS:PORT
/DATABASE?gssencmode=disable')

# Create SQL Query


sql = “SELECT name, host_name, room_type, price,
reviews_per_month, neighbourhood, geom FROM public.listings”

# Read the data with Geopandas


listings = gpd.GeoDataFrame.from_postgis(sql, engine,
geom_col=’geom’ )
listings.head()

You might also like