Created
June 1, 2021 18:38
-
-
Save zacdezgeo/ca49eaea85ecc8cb526d879ccd8405ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import create_engine | |
import psycopg2 | |
conn = psycopg2.connect("postgres://postgres:mypassword@db:5432/postgres") | |
sql = """with q as ( | |
select q.id, q.Q_socio, st_setsrid(q.wkb_geometry, 4326) geom from quartiers_sociologiques q | |
), p as ( | |
select st_setsrid(wkb_geometry, 4326) geom, price from sqfeet_properties as p | |
) | |
select q.id, q.Q_socio, q.geom, sum(p.price) sum_price from q, p | |
where q.geom && p.geom and st_intersects(q.geom, p.geom) | |
group by q.id, q.Q_socio, q.geom | |
""" | |
df = geopandas.GeoDataFrame.from_postgis(sql, conn, geom_col="geom") | |
df.plot("sum_price", legend="True") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment