• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Google Earth Blog

The amazing things about Google Earth

  • Home
  • About
  • Basics
  • Links
  • Tips
  • 3D Models
  • Sightseeing
  • Videos

KML Polygon merger

October 7, 2015

We have recently got a bit behind on updating our 3D imagery KML file. Part of the reason for this is the complexity of dealing with new areas that are extensions of already existing imagery.


Columbus, Ohio, got expanded 3D imagery (2). What you see above is what we want to appear in the timeline.


For the ‘Sorted by country’ section, we want to combine the new outline with the old outline, removing the shared border.

We already have the outline of the old extent of the 3D imagery (region 1) and we need two new outlines, one of just the newly covered area (region 2) that we use in the timeline and one showing the total area now covered that is used for the ‘Sorted by country’ section. So we want two new Polygons, one using segments 3 and 4 and another using segments 3 and 5.

It is possible to draw one of the new Polygons by starting with the existing polygon (1) and deleting the points in either segment 4 or 5 and then drawing segment 3. However, it still means that at least one segment of an outline needs to be redrawn. What would be ideal is to take a segment of the already existing outline and combine it with segments of the newly covered area outline. However, Google Earth has no easy way to do this. So we have written a bit of JavaScript to accomplish the task and we thought that it might be something that other people who work with KML regions might find useful, so we decided to share it.

To use our merger utility, first make sure you have two Polygon outlines that share a common border. Remove all points from the common border except the two at the ends of the shared border for each Polygon. Save the two polygons either in two separate KML files or a single KML file. Upload them below, then click the ‘Download merged Polygon’ button. Open the downloaded file in Google Earth.

It has not yet been tested very thoroughly so if you find any bugs please let us know in the comments. One problem that we encountered is that Google Earth Polygons may go clockwise or counter clockwise, so when combining two polygons by simply concatenating the list of points, it is possible to get a figure 8. We have tried to check for this and automatically correct it.

About Timothy Whitehead

Timothy has been using Google Earth since 2004 when it was still called Keyhole before it was renamed Google Earth in 2005 and has been a huge fan ever since. He is a programmer working for Red Wing Aerobatx and lives in Cape Town, South Africa.

  • More Posts(754)

Filed Under: Site News Tagged With: 3d imagery, KML, KML javascript utilities

Reader Interactions






PLEASE NOTE: Google Earth Blog is no longer writing regular posts. As a result, we are not accepting new comments or questions about Google Earth. If you have a question, use the official Google Earth and Maps Forums or the Google Earth Community Forums.

Comments

  1. jebster says

    October 7, 2015 at 10:34 pm

    I have polygons that go in opposite directions – and I’m getting a figure 8.

    • Timothy Whitehead says

      October 8, 2015 at 8:46 am

      Can you send me a sample by email and I will try and fix it.

  2. Timothy Whitehead says

    October 10, 2015 at 6:44 am

    I have made a number of improvements that should resolve any figure 8 issues.

  3. jebster says

    October 11, 2015 at 5:33 pm

    I couldn’t get it to work in IE or Firefox, but it works beautifully in Chrome.

    • Timothy Whitehead says

      October 12, 2015 at 11:29 am

      Thank you for letting me know. I have fixed it and tested in Firefox, Internet Explorer and Edge.

  4. Susan says

    January 27, 2016 at 10:20 pm

    I keep getting that I have the 7 points matched up, i.e., wrong number. I think I only have 2. ???

    • Timothy Whitehead says

      January 28, 2016 at 6:10 am

      I have been working on the script for my own use and have made many improvements since this post. I will try and update the post at some point in the future when I think I have perfected the code. If you need a better version now then email me directly and I can send you the latest code.

      • Susan says

        February 2, 2016 at 7:05 pm

        Hi Timothy, I would like the latest code as it would be immensely helpful if it works. What is your email?

        Thanks.

        Susan

  5. Simon says

    February 3, 2016 at 12:46 pm

    Hi! I do not manage to have the tool work as I would like it to.
    Would it be possible to have access to the latest version? Would be highly helpful.

    Thanks in advance,

    Simon.

  6. Neus GirĂ³ Canet says

    May 10, 2016 at 1:47 pm

    Hi I’m trying to merge kml layers with one polygon in only one kml layer with all the polygons. I thought there wasn’t a solution until I found this post. I would be so helpful to have acces to the latest version.

    Thank you very much in advance,

    Neus

  7. lr says

    June 3, 2016 at 8:04 am

    I was trying to merge polygons in this KML file: https://gist.github.com/laggingreflex/699e8c97a321d6f7f3545a241d835496

    It gives error: Too many polyons found!

    • Timothy Whitehead says

      June 5, 2016 at 1:02 pm

      The code is currently designed to join together two polygons that touch at two points. Your file has lots of polygons with many points in common. What sort of output do you want? The outline of the whole area?

  8. MATHEUS CAYRES DE MELLO says

    January 26, 2017 at 7:27 am

    It’s a very nice program, I was joining many polygons by myself (point by point, it’s insane now), till I found your code. You made it easier, thanks!

  9. Shane Talley says

    February 24, 2017 at 12:20 pm

    Mr. Whitehead,
    Thank you for developing and sharing this tool!! It has been extremely helpful for work and play. Again thank you so much.

    Shane

  10. Merav says

    April 21, 2017 at 5:32 pm

    thanks so much, this is great!

  11. Ben says

    April 25, 2017 at 8:49 am

    What am I doing wrong? I want to merge these polygons but the download button doesn’t seem to be working at all, Like nothing is happening. Thanks

    • Timothy Whitehead says

      April 26, 2017 at 3:53 am

      It is most likely related to browser compatibility. Which browser are you using? I’ll have a look and see if I can improve the compatibility of the code.

      • Ben says

        May 13, 2017 at 12:42 am

        It seems to be with Chrome, Internet Explorer 11 and Microsoft Edge. Basically all the browsers that I have.



PLEASE NOTE: Google Earth Blog is no longer writing regular posts. As a result, we are not accepting new comments or questions about Google Earth. If you have a question, use the official Google Earth and Maps Forums or the Google Earth Community Forums.

Primary Sidebar

RSS
Follow by Email
Facebook
Twitter




Categories

  • 3D Models (792)
  • Applications (708)
  • Business (288)
  • Environment (353)
  • Flying (208)
  • GE Plugin (282)
  • Google Earth News (1,764)
  • Google Earth Tips (592)
  • GPS (136)
  • Navigation (227)
  • Network Links (214)
  • Sailing (121)
  • Science (499)
  • Sightseeing (1,903)
  • Site News (587)
  • Sky (67)
  • Sports (154)
  • Street View (50)
  • Tours (117)
  • Video (421)
  • Weather (180)

Get new posts by email

Get new posts by email:

Google Earth Satellites

Copyright 2005-© 2023 Frank Taylor. All Rights Reserved.

This blog and its author are not an official source of information from Google that produces and owns Google Earth Google and Google Earth are trademarks of Google Inc.. All image screenshots from Google Earth are Copyright Google. All other trademarks appearing here are the trademarks of their respective owners.