• 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

How it works: Classifying Placemarks by Region

March 3, 2016

We recently created a JavaScript tool for classifying placemarks by region. This post is about how it works.

The basic idea is actually quite simple. To determine whether or not a point is inside or outside a polygon, simply draw a line from the point in question to a point you know is outside the polygon and then count how many times it crosses the polygon. If the number is odd, the point is inside the polygon, if the number is even the point is outside. In our case, we assumed that the polygon being tested does not go around the North Pole, so we draw a line from the point to the North Pole and then count how many edges of the polygons it intersects.

Below is an example of a place in Japan being tested:


The green line is drawn from the point being tested to the North Pole. The red lines are edges that we identified as being crossed by the green line. The white diamonds are the intersections. There are fifteen intersections, therefore the point is inside the polygon.

To see it in Google Earth download this KML file.

To actually identify which vertices the line crosses, it is necessary to find the intersection between the great circle on which the edge lies and the great circle on which the line we are testing lies and then check whether the intersection lies between the two ends of the edge and also whether or not it lies between the two ends of the line being tested. All this is complicated by the fact that any two great circles actually have two intersections on opposite sides of the globe (the antipode). The original algorithm we had for finding intersections that we used for the circle drawing tool sometimes found the intersection we wanted and sometimes the antipode. We found that when it found the antipode it was not as accurate as when it finds the intersection we are interested in, so we had to improve the algorithm to try and ensure it finds only the intersection we want.

To improve performance we first check whether or not a point is in the same region of the globe as the polygon being tested and don’t actually bother with the above algorithm if they are in different parts of the globe.

The reason we were working on the code in the first place is that when we were working on this post about recent progress in 3D imagery we noticed a significant discrepancy between the total areas for the timeline vs total areas in the ‘sorted by country’ section. To easily identify mistakes we wanted to match up polygons from the two sections. To do this we needed to know whether any two polygons overlap. The way we achieve that is to test every point in every polygon and see if it is internal to another polygon. If it is, the two polygons overlap.

Filed Under: Site News Tagged With: KML

Mini-Google Earth application demo: imagery switcher

January 12, 2016

The Google Earth API is expected to be shut down at some point in the near future. As of this writing it is still working. We have been investigating what alternatives exist for those wishing to create applications that work with Google Earth. If you just wish to control the view in Google Earth then one possibility is via the Liquid Galaxy protocol. For more advanced applications it may be possible to take advantage of the fact that Google Earth has a built-in browser used to render its popups. We already demonstrated a mini-application that shows a Google Map in a popup and had a look at a more advanced application, OpenForis, that makes great use of popups.

Today we are taking our investigation a step further to see what can be done with popups in conjunction with network links. Very often when we are looking through historical imagery we wish to switch back and forth between two dates to compare the imagery. We have in the past created applications to animate historical imagery using the Google Earth API and also via Google Earth Tours created with JavaScript. We thought it might be useful to be able to do something similar from within Google Earth.

To try it out download this KML file. Switch to historical imagery and find an interesting location. You should see a popop at the bottom left of the screen. First check the Google Earth timeline toolbar to see what dates are available and choose two dates that you are interested in. Enter the two dates in the popup as well as the altitude in km. Use the same date format as shown on the timeline toolbar. For best results you can use the ‘eye altitude’ shown at the bottom right corner in Google Earth. Click the ‘Update’ button.

Next, move the view slightly, which will cause the network link to refresh. You should now see a tour in the network link. Play the tour. For best results set the tour to repeat .

Let us know in the comments if you encounter any bugs.

Our next task will be to work out how to estimate the correct eye altitude given a particular set of view coordinates.

Filed Under: Site News Tagged With: KML

Altitudes and polygons in Google Earth

December 22, 2015

When creating the Santa Tracker we made use of some code we had previously written for creating arcs in Google Earth. As we noted in that post, however, the arcs use relative altitudes, but for smaller arcs there can be noticeable dips and bumps in line with the underlying terrain. The other alternative is to use absolute altitudes but this results in arcs that end at a fixed altitude either underground or up in the sky, depending on the altitude one sets and the altitude of the ground at the ends of each arc. Neither of these possibilities was satisfactory for the Santa Tracker as it often shows the arcs up close and Santa himself is shown following the arc and would bounce around alarmingly as he flies over mountains and rivers below.

The cause of the problem is simple. KML paths and polygons that are drawn in KML do not have any altitudes associated with each point. It is possible to set the whole path or polygon to either follow the terrain or be at a specific altitude, but you cannot adjust the altitude of individual points. KML does, however, support altitudes and KMLs derived from other sources, such as GPS’s, which include altitude, do correctly display the altitudes in Google Earth, and we actually used this feature when creating the arcs mentioned above.

To draw nice smooth arcs that end at ground level at each end we need to know what the absolute altitude of ground level is for each end of the arc – but this is not available in the KML file. So we did some investigation and discovered that Google provides an elevation API as part of the Google Maps API. So, to create our arcs we first obtain the altitudes of all the points along the path or polygon and then we can draw nice looking arcs and give Santa a smooth ride.

We also thought that maybe other people might find a use for code that takes a KML of a path or polygon and adds in the altitude data from the Google Maps Elevation API. So, here it is:

Simply select a KML containing paths or polygons and the script will add altitude data from the Google Maps Elevation Service. You probably won’t see any difference in the resulting KML file when loaded in Google Earth, as the paths or polygons will still be at ground level. However, if you check the properties of a path or polygon you will see that it now shows various altitudes instead of an altitude of zero. Its real use is in cases where you want to do further processing, as we did for creating arcs. If anyone finds this useful do let us know in the comments what application you found it useful for.

Note that the Elevation Service is not intended to be used to extract large quantities of elevation data, so don’t expect to be able to use it to copy whole areas of elevation information into other applications.

Filed Under: Site News Tagged With: altitude, KML, KML javascript utilities

Google Maps in Google Earth

December 14, 2015

Following on from our post on Google Earth’s internal browser we are exploring what can be done within placemarks in Google Earth.

A very underutilized feature of network links is the ability to send the location that the user is looking at as part of the URL. We thought it would be fun to demonstrate this capability by displaying a Google Map of the location you are looking at in a placemark. If you are a programmer wanting to learn more, see this tutorial from Google.

In order to make it work, the network link must point to a server that takes the URL parameters and dynamically returns a KML file that takes into account the location the user is looking at. This means this effect cannot be achieved without an application server. This might explain why the feature is so rarely used.

We set up a free cloud based server on OpenShift using an application called Node.js, which lets you run JavaScript on the server. Although it took a little time to get right, the result is only about 10 lines of code (beyond the provided template) on the server and a few more in the KML file.

To try it out, simply download this KML file and open it in Google Earth. Whenever you move the view it will move the placemark to approximately the centre of the Screen and show you a Google Map of the area.

Note that it is a fully working embedded Google Map, including the ability to zoom in and out, switch to satellite imagery or use Street View.

Filed Under: Site News Tagged With: google maps, KML

Numbering the points on a Path or Polygon with KML

October 13, 2015

We have recently been spending some time improving our JavaScript for combining polygons. In order to debug it, we found it useful to number the points for display in Google Earth. We thought that others may find the feature useful, and just for fun, we added the option to display the distances along the segments. Distance is calculated using the Haversine formula, which, is the same method we believe the Google Maps API uses for calculating distance. We compared our measurements with Google Earth’s measuring tool and they did not match, so it appears Google Earth uses a different formula, which is probably more accurate. Google Earth’s measuring tool is also capable of optionally taking altitude into account.

[ Update: We have added the option to use the Haversine formula for the distance measurements as it is more accurate.]

Polygons or Paths:

Colour for point labels:

Label Size:

Include distances:

Distance formula:

Distance units:

Colour for distance labels:

Filed Under: Site News Tagged With: KML, KML javascript utilities, measure

  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to page 4
  • Go to Next Page »


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.