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.
I have polygons that go in opposite directions – and I’m getting a figure 8.
Can you send me a sample by email and I will try and fix it.
I have made a number of improvements that should resolve any figure 8 issues.
I couldn’t get it to work in IE or Firefox, but it works beautifully in Chrome.
Thank you for letting me know. I have fixed it and tested in Firefox, Internet Explorer and Edge.
I keep getting that I have the 7 points matched up, i.e., wrong number. I think I only have 2. ???
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.
Hi Timothy, I would like the latest code as it would be immensely helpful if it works. What is your email?
Thanks.
Susan
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.
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
I was trying to merge polygons in this KML file: https://gist.github.com/laggingreflex/699e8c97a321d6f7f3545a241d835496
It gives error: Too many polyons found!
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?
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!
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
thanks so much, this is great!
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
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.
It seems to be with Chrome, Internet Explorer 11 and Microsoft Edge. Basically all the browsers that I have.