Convert KML Placemarks to SVG Polygons
April 11, 2017
Being easily confused by basic geometry, I tend to stick to 2D whevener possible.
Unfortunately, (in France at least) publicly available data on administrative divisions often comes in various geographic coordinates systems which, while convenient if you need to georeference something, make everything complicated when you just want to display a nice SVG map.
If we abstract I/O, the whole process can be summarized to two steps: projection and simplification.
In order to convert KML placemark “polygons” to actual SVG Polygons, one must convert each points of said polygons.
Converting points from 3D space, such as a geographical coordinates system, to a 2D plane is called a projection.
Of course, there are many different projections and of course, if you listen to the internet, ALL of them are terrible for one reason or another.
We have our polygons properly flattened, but we can’t yet ship them to our users.
As the source KML files are too precise for our needs, so are our KML files.
Fortunately, the field of geometry is full of interesting algorithms ready to solve our problems, so picking a simplification algorithm was as easy as 2 google searches: