Skip to content
Advertisement

Calculate Density based on Lat/Lon

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).

JavaScript

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.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement