In redistricting, contiguous is a fancy word meaning the district is one lump without any loose flakes floating around. If a district includes part of a county, I see no reason for that district to have little pieces of that county that are unconnected with the main part of the district. This assumes that the county was contiguous. Consider a city that is not contiguous, since it has small unconnected parcels of land. If a district includes part of that city, then perhaps that district has a valid excuse to not be contiguous if that district includes some of those small unconnected parcels of land.
For sandboxwalls to keep districts contiguous, before adding a particular census block to the district, it must confirm that the particular census block is adjacent to the district. This could be done by checking a contiguous blocks table with records as follows:
The first integer identifies the particular census block. The next integers identify the census blocks adjacent to the particular census block. In the rest of the record the integers are padded with a zero. Every census block would have a record, and the records would be in a searchable order. Such a table would allow the software to verify that no district has unconnected fragments.
Such a table could I presume be constructed from data in the census TIGER files. I looked at the following website.
188.8.131.52 All Lines Shapefile Record Layout
The shapefile name is: tl_2008__edges.shp
The shapefile is county-based.
The following is the shapefile’s attribute table layout:
Field Length Type Description
STATEFP 2 String Current state FIPS code
COUNTYFP 3 String Current county FIPS code
TLID 10 Integer Permanent edge ID
TFIDL 10 Integer Permanent face ID on the left of the edge
TFIDR 10 Integer Permanent face ID on the right of the edge
When they say they edge, I presume they mean a segment of the polygon that is the perimeter of a census block. I have no idea how to take the Permanent face ID and get a latitude and longitude of that census block. The census files are usually massive and are geared for use by States and large companies, not hobbyists. I have not attempted to download any of them. It is important enough to me to have such a table. If desperate I could create a fake table that had a certain number of the nearest districts, even if they weren’t adjacent. Nearest could be determined by using latitude and longitude of the census blocks. Hopefully someone can give me clues on how to construct an Adjacent Blocks Table.
To find the distance from a district center to the census block, do the following:
Subtract the longitude of the district center from the longitude of the census block to get horizontal distance X. Next, subtract the latitude of the district center from the latitude of the census block to get the vertical distance Y. Since X and Y are on planet Earth instead of a flat surface, they must be multiplied by correction factors. To save computation time, sandboxwalls does not calculate the correction factors for every distance. That requires cosines. Instead, the correction factors are calculated for each district center and those are used repeatedly as an approximation. Now take the corrected X and Y and use the Pythagorean theorem. The hypotenuse is equal to the square root of the sum of the squares of X and Y.
Unfortunately, that means to find every distance requires a square root function. To save computation time, in my next blog I try a sloppy but fast way to find square root.