Area-weighted calculation on an intersection

It turns out that I needed to add a WHERE ST_Intersects to my ST_Intersection Query, as follows:

SELECT sum(((st_area (st_intersection (p.the_geom,c.the_geom))/st_area(c.the_geom))*ci.pop2000)) AS Parcels_pop
FROM parcel_proj p, census_proj c, tgr39035sf1blk ci
WHERE ST_Intersects(p.the_geom,c.the_geom) and ci.stfid=c.stfid;

This may not matter for others who have more forgiving interfaces, but I was getting a POST / Proxy Error every time I tried st_intersection without testing if st_intersects, presumably because st_intersection needs to be constrained in order to function efficiently.


Are your parcels and census blocks in the same projection? If not you'll need to reproject one of them, or use ST_Transform to reproject one on the fly.

For the second part, especially if you have to reproject, I'd use a subquery. Join your blocks to the attribute data then use that dataset in the main intersection query.

If you want to display this data you can use QGIS and the DB Manager plugin to run the query and display the results.