Skip to content
  • Posts
  • Join the Spatial Lab
  • Learn Modern GIS
  • Sponsor
  • Coaching
  • Podcast

Get the newsletter

Join 71,000+ geospatial experts growing their skills and careers. Get updates on the most cutting edge updates in modern GIS and geospatial every week.

  • LinkedIn
  • YouTube
Tutorial

PostGIS and GeoPandas in Jupyter in 4 minutes

January 15, 2022 Matt Forrest Comments Off on PostGIS and GeoPandas in Jupyter in 4 minutes
PostGIS and Geopandas

Take advantage of the speed of PostGIS along with the flexibility of Geopandas and Python in 4 minutes! Take a look at the video and follow along with these steps!

The Spatial SQL Book – Available now!

Check out my new book on Spatial SQL with 500+ pages to help you go from SQL novice to spatial SQL pro.

Buy now!

First, install your libaries

You will need to install Geopandas and psycopg2 (you can also use SQLAlchemy) in your Jupyter notebook environment. If you are using a local version of PostGIS make sure you are also running your notebook locally!

You can use the following command:

!pip install geopandas psycopg2

Import your libraries

You next need to import your libraries. You can also use an alias so you don’t have to type them each time.

Establish your database connection

Next you can connect your database using your database host and other parameters. Check the docs for more detials.

Use Geopandas to query against your database

You are ready to query your database and create a GeoDataFrame! It is super easy because Geopandas has a built-in function for this called from_postgis. Just pass in a query and your database connection variable, and go!

Now give it a shot with some other queries! You can also check out my guides and resources for spatial SQL (over 40 resources) and geospatial Python (over 75 resources)!

  • Python
  • Spatial SQL
Matt Forrest

Post navigation

Previous
Next

Search

Categories

  • Article (29)
  • Essay (1)
  • Podcast (5)
  • Tutorial (7)

Recent posts

  • Convert a Shapefile to GeoParquet (Python, DuckDB, Sedona)
    Convert a Shapefile to GeoParquet (Python, DuckDB, Sedona)
  • I Gave Claude AI Full Control of QGIS: What Happened
    I Gave Claude AI Full Control of QGIS: What Happened
  • AI for GIS: 5 Prompts That Replace Hours of Work
    AI for GIS: 5 Prompts That Replace Hours of Work

Tags

aggregations Apache Airflow Apache Iceberg Apache Sedona ArcGIS bigquery Cloud-Native Geospatial Cloud GIS Cloud Optimized GeoTIFF duckdb Esri geoparquet geospatial gis GISP Modern GIS postgis Python snowflake Spatial SQL sql Wherobots zip codes

Related posts

Convert a Shapefile to GeoParquet (Python, DuckDB, Sedona)
Tutorial

Convert a Shapefile to GeoParquet (Python, DuckDB, Sedona)

October 28, 2026 Matt Forrest No comments yet

I took a real Shapefile with almost 1.1 million polygons and converted it to GeoParquet three different ways. The file went from over 1.4 GB of source data down to 246 MB, opened cleanly in QGIS, and ran spatial queries in seconds instead of minutes. The dataset was the New York City building footprints. Every […]

Podcast

Breaking the GIS Silo: Why GeoParquet and Iceberg are the key to Spatial Analytics at Scale

July 3, 2025 Matt Forrest Comments Off on Breaking the GIS Silo: Why GeoParquet and Iceberg are the key to Spatial Analytics at Scale

For decades, GIS has lived in a world of its own. Specialized software. Obscure formats. A profession that, despite being critical to everything from climate modeling to logistics, has remained siloed from the rest of the data world. But that’s finally starting to change. In the latest episode of the Spatial Stack podcast, I sat […]

Article

Scaling GIS Workflows with COGs, Airflow, and Apache Iceberg

April 25, 2025 Matt Forrest Comments Off on Scaling GIS Workflows with COGs, Airflow, and Apache Iceberg

TOP OF THE STACK What we need to do with COGs COGs (Cloud-Optimized GeoTIFFs) are one of the most promising tools we have for making raster data truly cloud-native. They let you stream just the pieces you need, work remotely, and plug into modern geospatial systems without downloading giant files. But after working closely with […]

Spatial Lab
  • Join the Spatial Lab community
Policies
  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Cookie Policy
Spatial SQL
  • Get the Spatial SQL book today
Join Us

© Matt Forrest 2024. All Rights Reserved.

Manage Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
View preferences
  • {title}
  • {title}
  • {title}