I’m very sorry to say that I do not have any sample code for this question. The reason being, I’ve been looking for a way to do this and I’ve got no ideas. I’m not looking for specific code help, more like some general guidance on where to start.
I have lat/lon for people living around California. Based on the geographic groupings of this data (county, city, zip, etc) I’m supposed to figure out a density score. Basically, how many points per square mile, or something along those lines. I have been looking for ways to do this, and unfortunately I haven’t found anything that seems right. I have lat/lon/geographic boundary columns in my data, so I can group by the various geographic types, but I’d like to rely on the lat/lon for the density scoring.
Again, I’m sorry that I don’t have any specific code to share. Any suggestions on packages or tools for this problem would be greatly appreciated!
I’m comfortable with both R and Python, but my colleagues would prefer python driven solutions.
Below is some sample data using zip codes and lon/lat (in this order).
Zip Longitude Latitude 95223 -120.045063 38.467308 95223 -120.040889 38.465436 95223 -120.072499 38.454202 95223 -120.049251 38.462058 95223 -120.041697 38.462194 95223 -120.045757 38.470637 96120 -119.959615 38.703965 96120 -119.937276 38.741337 96120 -119.9382 38.739344 96120 -119.901794 38.776584 96120 -119.936094 38.741865 96120 -119.957587 38.707533 96120 -119.93456 38.74194 95646 -120.072087 38.687061 95646 -120.066752 38.684097 95646 -120.069591 38.684193 95646 -120.071754 38.699738 95646 -120.066111 38.685164 95646 -120.067082 38.683881 95646 -120.070923 38.696049 95646 -120.068004 38.683615 95646 -120.07161 38.699309 95646 -120.07385 38.690719 95646 -120.066131 38.685019 95646 -120.071263 38.686228
Advertisement
Answer
From the Pyviz Examples page for census mapping here: Example code for mapping population density: https://examples.pyviz.org/census/census.html
Creating your boundaries: The answer to this question covers this quite well, giving a list of boundary detection algorithms: https://gis.stackexchange.com/questions/5426/finding-boundary-co-ordinates-from-given-set-of-point-co-ordinates
Finding the area of your polygon(AreaOfZipcode): How to calculate the area of a polygon on the earth’s surface using python?
Calculate Zipcode Populations with an accumulator algorithm.
Then: PopDensity = PopOfZipcode/AreaOfZipcode
Define your high density/mid-density/low-density boundaries and then assign your zipcodes to each bucket.