Tuesday, 29 April 2008

Drawing regular polygons in KML

The second hack for making proportional symbols in KML, is to use regular polygons (see the first hack here and here). Unfortunately, KML has no build-in support for regular polygons so you have to do it the hard way: by calculating the longitude/latitude for each vertex or corner point of the polygon. Since I'm not a math genius, I was happy do find this PHP function by TJ which I could modify for this purpose. This is the result:

By changing the bearing or angle 30 times from 0 to 360, the function returns a circle (KMZ).

Reduce the number of iterations to 4, and you'll get a square (KMZ). Not the easiest way to draw a square, but it works.

These files are also viewable in Google Maps and Microsoft Live Maps (Virtual Earth), even though the circles are not so regular any more.


rené said...

Is it possible to see the code that generates the KML-files?

alitalib said...

could you please post the link to the php function by TJ