Wednesday 25 January 2012

How To Generate Weighted Centroids in Alteryx

Just before Christmas I received a query from a colleague I used to work with at Experian UK who now works for Experian Norway.  He knew he could find the centroid of a polygon in Alteryx using the spatial info tool, but wanted to be able to calculate the Population Weighted Centroid of a polygon.  Well, off the top of my head I didn't know how to do that, but a quick ask around the office yeilded a fairly simple algorithm for the calculation and now a few weeks later I have packaged that algorithm up into a simple to use macro.  So here it is:

http://downloads.chaosreignswithin.com/macros/6.0/SpatialWeightedAverage.yxzp


The module is actually fairly simple and works by taking a weighted average on the x and y co-ordinates of the spatial points.  To test it out I took the US Census Data 2010 Population estimates at Block Group level for the states of Colorado, Wyoming and Utah and calculated the Population Weighted Centroids  for those states.  The results of which you can see below:

The blue diamonds are the spatial centers of the state and the red stars are the population weighted centroids as generated by my macro.  I was very pleased with the results, in each case you can see how the population centroid is "pulled" towards the state capital.




No comments:

Post a Comment