My Google Map Blog

Making KML files smaller by reducing precision

by Timothy Whitehead on Mar.15, 2016, under 3D Models, Argentina, Australia, Brazil, California, Denmark, England, Germany, Google Earth News, Google Earth Tips, Google Sky, Google maps, Hawaii, Indonesia, Ireland, Italy, Japan, Kenya, Mexico, Natural Landmarks, Netherlands, Sightseeing, Street Views, USA

Our KML map of 3D areas has been steadily growing in size as new areas are added. We have considered converting it to KMZ format, which is the compressed version of KML files. KMZ uses standard ZIP compression and in many cases provides significant compression ratios. In our case it would shrink our KML file by over 60%. We have held back because this would mean changing the link to the file and as most users access it via a network linked KML we would also have to notify them to re-download the original KML with a new link. There are workarounds to this problem, so it might be worth doing. The other downside is that it adds an extra step to the process of updating the file as we would have to convert it to a KMZ file before uploading it.

Because of the above complications we have been giving some thought to other methods of making the file smaller. One thing we have noticed is that Google Earth saves KML files with an unnecessary amount of precision for latitudes and longitudes. It typically saves latitudes and longitudes using 16 significant digits. If you configure Google Earth to use decimal degrees then edit a placemark in Google Earth, it only actually shows 5 decimal places.

So how many decimal places are actually needed? We calculated that rounding to five decimal places results in a maximum error of just under a metre. Rounding to six decimal places gives an error of less than 10 centimetres. 14 decimal places gives an accuracy of less than a nanometre. Given that most Google Earth data such as altitude data or even image alignment can be off by many metres, having nanometre resolution in your KMLs is just wasting space. For our KML file five decimal places should be more than enough.

As you can see below, the results were quite impressive. Simply discarding unnecessary decimal places reduces the file size by almost half. We also show the effects of using the KMZ format.

We thought that other people with large KML files might find the idea useful. So, below is a JavaScript tool that will take a KML file and reduce the precision of the latitudes and longitudes.

Notes:

  • The current version only reduces precision in placemarks, polygons and lines, it does not affect some other KML elements that include latitudes and longitudes.

  • To achieve the reduction of precision the code parses the KML and recreates it using our in-development KML library, so we can’t guarantee that it will properly handle unusual KML elements. If you use it, double-check that the resulting file still has everything in it that you require, and let us know in the comments if you encounter any bugs.

  • Unnecessary white-space is also removed which makes the file smaller but less human-readable.


Precision: (decimal places)

 

The post Making KML files smaller by reducing precision appeared first on Google Earth Blog.

:,

Comments are closed.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...