PostGIS and Geopandas

PostGIS and GeoPandas in Jupyter in 4 minutes

2 min. read

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!

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)!