Center of gravity calculator in Google Earth

Readers of will remember a discussion a week back about where in the world the highest concentration of Starbucks coffee shops might be. One blogger was inspired to calculate the exact center of gravity of all Starbucks in New York, and mapped it. It was a hard slog, and it got him some press.

That was then. this is now.

Blogger “Brammeleman” writes in Dutch (so I’ll translate loosely) that his family is discussing where to have the next family reunion. It must be a nerdy family, as everyone immediately agreed it should be at the family’s center of gravity. The only question remaining is, what determines the weighting of each individual family member?

While the rest of the family argues it out (age? generation? marital status?), our blogger has gone off and produced a center of gravity calculator for Google Earth. In the true political tradition of the Dutch, the calculator assigns everyone an equal weighting.

Here’s how it works: In Google Earth, make a new folder (Command-Shift N). Then, make a new placemark at the location of each family member and add it to the folder. Finally, save the folder to your desktop as a KML file. Now import it into our pseudonymous blogger’s web app, and you instantly get a KML file back with a placemark added at the center of gravity.

coggeens.jpg(I tried it. My immediate family is all over the place — London, Switzerland and me here in Stockholm, yet the center of gravity for us is in tiny Belgium, near Li√Æge. As we’re Belgian, that’s rather spooky.)

The script makes one major simplifying assumption — that the Earth is flat. The PHP script won’t get tripped up by the dateline, but be sure not to live too spread out, or around a pole.

[Geeky postscript: That’s a fun programming question: “Given a set of arbitrary points on the surface of a sphere referenced by latitude and longitude, write a program to determine the point on the sphere closest to the three-dimensional center of gravity of the points, in terms of latitude and longitude.” Brammeleman’s script is practically there. Just his final latitude calculation is off for most sets of widely spread points. Instead of:

$lat = rad2deg(asin($meanz));

it needs to read:

$meanx = $sumx / $placemark_count;

$meany = $sumy / $placemark_count;

$lat = rad2deg(atan($meanz/(sqrt($meanx^2+$meany^2))));

…I believe, hoping for no divisions by zero. But I’m often wrong:-)]

5 thoughts on “Center of gravity calculator in Google Earth”

  1. I’d be interested for the opposite; given a set of points on a sphere, what point lies the _farthest_ from all of them?

  2. Shame the family centre of gravity is in Luik…woul dn’t have minded a reunion somewhere tropical! Freeky though that it is in Belgium.

  3. Sugarsmax, that’d be the point at the opposite end of the Earth to the center of gravity… Just change the signs of the coordinates.

  4. Ever since the initial wave of Keyhole buzz, GIS professionals have shot down Keyhole/GE as useless glitz. With further advances in server-side analysis tools with some clever scripting, GE could theoretically become a powerful GIS program.

  5. Cool Stuff, & nice that Brammeleman is politically correct with his family and asigns everyone the same weight (=1). But I really want to know how do I apply weights to the various points. I have 5 destinations in the Balkan Region where I ship product to. However, only two of them occassionally order enough to fill a full truckload (which is the most economical). I am considering to consolidate the freight for all 5 destinations and deliver to one point. The customers would pick-up at that point. I have been able to find the geographical center of gravity, that was easy. But now I want to weigh the 5 destinations by: freight cost; volume shipped; sales revenue; etc. How can I apply these weights???

    Can anyone help?? I would appreciate it!!

Comments are closed.