Wednesday 24 September 2008

Displaying KML/KMZ files in Google Maps

KML/KMZ files can be overlaid on Google Maps, either on the Google Maps website, or by using the GGeoXML class of the Google Maps API (see example).

Google Maps

Google Maps API

Google Earth

The KMZ file (download) displayed above was generated by the Thematic Mapping Engine. Only a subset of the KML standard is so far supported by Google Maps. The shaded plygons are properly displayed, but not the screen overlays (title and legend) and balloons. The different placement of the zoom bar in Google Maps and Google Earth makes it difficult to display the same KML/KMZ file in multiple viewers.

I'm impressed by the speed of Google Maps. The above KMZ file contains complex geometries of almost 200 countries of the world. Web browsers are not optimized for vector graphics, as illustrated on this page. To avoid this problem, Google seems to use its powerful servers to generate image map tiles on-the-fly from the KML geometries.

A bug in the map tile generator was discovered when displaying the World Borders dataset in Google Maps:


The polygon representing Russia is not displayed properly. The country is crossing the antimeridian at 180° longitude. To avoid a round trip of the Earth, the eastmost part of Russia is stored as a separate polygon. Russia is not displayed properly because 180° longitude is rendered as 0° longitude (the Prime Meridian). The problem was fixed by replacing all 180 coordinate values width 179.99. I won't correct this in the World Borders dataset, as I consider this to be a bug in Google Maps. If you don't want to change the orginal dataset, you can replace the longitude values when the KML document is generated, or by doing a search/replace in a text editor on the KML document.

Monday 15 September 2008

Thematic mapping in Norway

I'm about to recover from my workaholism after an extremely busy year in Edinburgh. I've spent the last weeks hiking and biking in the Norwegian mountains. The holidays are over, now it's back to work. This blog post shows how statistical data on a subnational level can be visualised with KML.

I could not find UK data due to lack of data access and restrictive licensing rules. Luckily, Statistics Norway considers official statistics as "a tool for democracy":
"Official statistics and analyses based on statistics shall provide the general public, businesses and the authorities with information about the structure and development of society. Such information strengthens democracy and forms the basis for a sustainable economic, social and environmental development.

To this end, official statistics must be produced on an impartial basis, be of a high quality and made available for the common good of society."

StatBank is an web based data service from Statistics Norway with a liberal licensing policy:
"Statistics Norway permits the material on these pages (text, statistical tables and figures) to freely be stored, printed, copied and circulated. The permission assumes that reference is to be given in direct connection with each table and figure that are used (Source: Statistics Norway)."



Population in municipalities of Norway 2007 from thematicmapping.org on Vimeo.


The above image and video (download KMZ) show the 2007 population in municipalities of Norway, visualised as a 3-D prism map in Google Earth. The boundaries were downloaded from the Second Administrative Level Boundaries (SALB) dataset, edited according to the latest consolidations, and simplified using MapShaper (the Douglas-Peucker algorithm returned the best result).

This video shows the population change 1951-2007:

Population in municipalities of Norway 1951-2007 from thematicmapping.org on Vimeo.


Norwegian municipalities are undergoing continuous consolidation and the boundaries in use only represent the current state. Historic boundaries are needed to display the population dataset properly.