Quirks of Shapefiles
Don’t count on shapefiles from different sources playing nicely together.
Following the passage of a county council expansion ballot question in 2024, Baltimore County established a commission to redraw the councilmanic districts. The commission’s final proposal was released a few weeks ago along with the shapefile. Here is a plot of the proposed nine new new districts (currently there are seven).
I was hoping to do some analysis on this plan and got some block-level shapefile and demographic data from the 2020 census. I tried to assign each block to one of the districts by checking which district polygon contains each block polygon. However, geopandas was unable to assign 722 of the 9125 blocks. The commission may have decided to split a census block into two separate districts. But the plot below of the unassigned blocks seems the suggest that this is a data issue.
The unassigned blocks seem to follow the boundaries of the districts (or they contain water features). I randomly selected one of the unassigned blocks (geoid: 240054036023003). This block (red) seems like it should have been assigned to the district 3 (blue).
Zooming in a little bit, you can see the presumably straight boundary between the Baltimore County and Baltimore City is not actually so…
…and zooming in a little more…
…you can see that the edge of the district polygon actually cuts through the very bottom of this block. This is why the GeoPandas.contains function was unable to assign this block to a district. Since the district map was drawn by the commission (presumably using County data) and the block data was taken from a federal agency, I presume that each entity has their own methods and error tolerances, resulting in misalignment. To get a 1-1 assignment of blocks to districts, I ended up using the maup package. It computes the area of each blocks intersection with each of the districts and assigns to the one with most.