2

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
pkpto39
  • 545
  • 4
  • 11
  • I would suggest using Census boundaries. While far from perfect, they are smallish areas that people will recognize as valid designations of land area. Zip Codes could also work or cities. Otherwise you can make a grid of lat/lon points of any width you want, for example a sequence of lattitudes/longitudes increasing by .5 –  Jun 01 '21 at 21:31
  • Could you provide a sample of the data & data format that you are working with, using data descriptors in place of the actual data so we can get a better understanding of the specific data structures that you're working with? – WickedMongoose Jun 01 '21 at 21:34
  • @WickedMongoose, toy data added. – pkpto39 Jun 01 '21 at 21:52
  • Each row is a person? – WickedMongoose Jun 01 '21 at 22:04
  • For the purposes of this, yes. This is toy data, so it might not be actual people, but it is based on real addresses. – pkpto39 Jun 01 '21 at 22:05
  • Are you calculating density for each zipcode as a flat value, or wanting to plot the data to show the density as a heat map? Getting the area from your dataset alone will be a bit error prone, but you can calculate the borders of your people and interpolate boundaries between different zip codes, or leave it with boundaries shrink wrapped to your population. – WickedMongoose Jun 01 '21 at 22:10
  • I won't be doing a vizualization. Basically I'm using the zip (and other geos not listed) as a flat value, and they want me try figuring out how dense each one. I suggested doing this as points per sq mile, but it doesn't have to be done this way. I just need to be able to create categories to say high density/mid-density/low-density. It's a bit relative, but I basically need to assign this score to each geographic type. – pkpto39 Jun 01 '21 at 22:23

1 Answers1

2

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.

WickedMongoose
  • 101
  • 1
  • 10