PostGIS is capable of just about any GIS operation you're used to doing in a desktop GIS. Here we cover typical points-in-polygon queries in PostGIS.
If you're new to joins in SQL, you'll notice a few things about the queries here. First, we select from multiple tables and give each a unique name (so instead of FROM nycc
you'll tend to use FROM nycc cc, listings l
if your query is over nycc
and listings
. Second, you'll be grouping the polygons by a unique id. As I'm using CartoDB here, I will group by cartodb_id
.
If we have a table called nycc
of City Council districts and a table called listings
of Airbnb listings, we can find the average price by city council district like so:
SELECT cc.*, AVG(l.price) AS avg_price