0% found this document useful (0 votes)
56 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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 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
We take content rights seriously. If you suspect this is your content, claim it here.
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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy