I am using only free, open source tools. I have two shapefiles: a shapefile of voting precincts and a shapefile of census tracts. I want to know: which voting precincts fit inside which census tracts? What is the mapping vocabulary describing what I am trying to answer?

I am trying to know which polygons from the precinct shapefile are bounded by which polygons from the census shapefile? Is that right? How do I answer that question programmatically? What tools would I use? I have a vague sense that I could do this in PostGIS -- but don't really know. Also, is it possible in QGIS?


You can achieve this using PostGIS spatial functions.

St_Within will return True if geom A is totally within geom B. There are other similar functions you can use if this isn’t suitable, check the docs.

SELECT census_tracts.col1, voting_precincts.col1
FROM census_tracts, voting_precincts
WHERE st_within(census_tracts.geom, voting_precincts.geom);

What you are looking for is ST_Contains and ST_Within functions. Your use case is pretty basic, so I recommend reading through the docs. Once you bump into a problem you can't solve yourself even after reading it, ask here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.