thanksgiving-fun-with-kml
“I borrowed this code from NASA.” That comment received quite a laugh during one of my presentations. The comment was intended to be an acknowledgment that I did not create this code along with crediting the agency that did. Judging from the reaction, that is not how the line hit. At any rate, the irony of the statement is in how simple the code truly is. To me, coding fits well within the definition of geography I was taught…, “observe and analyze anything distributed across Earth’s space.” Learning to read and write KML is observing and analyzing spatial distributions. Granted the distribution is pixels on a screen and not Earth’s space, but the mental task is the same. Therefore, spatial reasoning, Google Earth, and NASA were part of the initial stepping stones in the creation of geteach.com.
Keyhole Markup language (KML) is an open standard language used to display geographic data. KML is what Google Earth reads to show raster files (collocations of pixel that create an image…common form jpeg, png files. These images are often not geo-referenced with latitude and longitude coordinates) and vector files (points , lines, polygons, and multigeometry that are often geo-referenced). KML is a variant of XML (Extensible Markup Language) that includes geo-spatial language. Sorry for the jargon. that entire paragraph is just a fancy way of saying that kml is based off of a ubiquitous language that is easy to read and write.
The easiest way to write KML is through Google Earth. Whenever you add a placemark, line, polygon, or overlay Google Earth is writing code. However, sometimes you might want more precise control over these points, lines, polygons, and images. This is when you might want to edit your KML via any text editor. As a Windows user, I prefer Notepad++. Mac users can use TextWrangler, but I believe the company is moving users to BBEdit. If you are looking to collaborate on kml in the cloud you can use Google Drive and XML Editey. I taught my 8 year old html and css via Editey.
While KMLs can get extremely complicated, the aforementioned NASA code is about as simple as it gets. NASA Earth Observations is a great site to get environmental data about Earth. If you have visited geteach.com you will notice many of the datasets I use comes from NASA Earth Observations because it is free (make sure to pay your taxes) and open to use. Clicking around in NASA Earth Observations you will find out you can download Google Earth (KML) files of these datasets. Initially, these Google Earth files download as KMZ files. KMZ is a .zip version of a KML. Opening a .kmz in Google Earth and then saving the file as a .kml is equivalent to unzipping a .zip file. Basically, what the user downloads from NASA Earth Observations is a 3600 x 1800 image and a .kml file that wraps the image around the Earth. Fortunately for users, NASA uses the same map projection (WGS84) as Google Earth and Google Maps. Otherwise the locations of the image would not align with Google Earth.
Enough geo-spatial technology talk…it is time to impress your family and friends for 5 minutes after Thanksgiving dinner.
Step 1: Take a family picture (If you are using a phone make sure you are shooting in landscape not portrait)
Step 2: Upload image to Google Drive and share “Anyone with a link can view” (This is going to complicate the code, but I prefer hosting images online)
Step 3: Code KML
Step 4: Save
Below is the breakdown of the code. Each snippet is highlighted followed by a brief description of how the code is being read. Feel free to copy/paste this kml code into your text editor of choice
<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> <Document> <name>Learning to Use 3D Printer</name> <LookAt> <longitude>0</longitude> <latitude>0</latitude> <altitude>0</altitude> <heading>0</heading> <tilt>0</tilt> <range>20770075.42761702</range> </LookAt> <GroundOverlay> <name>Learning to Use 3D Printer</name> <Icon> <href>https://drive.google.com/uc?view&id=0B1eALoRda8FTdDlfTnVRSWpSclU</href> </Icon> <LatLonBox> <north>90</north> <south>-90</south> <east>180</east> <west>-180</west> </LatLonBox> </GroundOverlay> </Document> </kml>
Line 1 tells Google Earth that this is an xml file with UTF-8 characters. This is similar to telling your browser which html version to use in reading the file.
<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> <Document> <name>Learning to Use 3D Printer</name> <LookAt> <longitude>0</longitude> <latitude>0</latitude> <altitude>0</altitude> <heading>0</heading> <tilt>0</tilt> <range>20770075.42761702</range> </LookAt> <GroundOverlay> <name>Learning to Use 3D Printer</name> <Icon> <href>https://drive.google.com/uc?view&id=0B1eALoRda8FTdDlfTnVRSWpSclU</href> </Icon> <LatLonBox> <north>90</north> <south>-90</south> <east>180</east> <west>-180</west> </LatLonBox> </GroundOverlay> </Document> </kml>
The highlights show an open (line 2) and closed (line 26) tag. Every open tag, with the exception of line 1, has to have a close tag. Notice the indented spacing of the file. Code is written like a Russian nested doll. Google Earth reads this as all tags between lines 2 and 26 will use the kml 2.2 standard.
<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> <Document> <name>Learning to Use 3D Printer</name> <LookAt> <longitude>0</longitude> <latitude>0</latitude> <altitude>0</altitude> <heading>0</heading> <tilt>0</tilt> <range>20770075.42761702</range> </LookAt> <GroundOverlay> <name>Learning to Use 3D Printer</name> <Icon> <href>https://drive.google.com/uc?view&id=0B1eALoRda8FTdDlfTnVRSWpSclU</href> </Icon> <LatLonBox> <north>90</north> <south>-90</south> <east>180</east> <west>-180</west> </LatLonBox> </GroundOverlay> </Document> </kml>
Lines 3 and 25 are the start and end of the visualization instructions…The container of the document.
<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> <Document> <name>Learning to Use 3D Printer</name> <LookAt> <longitude>0</longitude> <latitude>0</latitude> <altitude>0</altitude> <heading>0</heading> <tilt>0</tilt> <range>20770075.42761702</range> </LookAt> <GroundOverlay> <name>Learning to Use 3D Printer</name> <Icon> <href>https://drive.google.com/uc?view&id=0B1eALoRda8FTdDlfTnVRSWpSclU</href> </Icon> <LatLonBox> <north>90</north> <south>-90</south> <east>180</east> <west>-180</west> </LatLonBox> </GroundOverlay> </Document> </kml>
Line 4 is the name of the Google Earth file.
<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> <Document> <name>Learning to Use 3D Printer</name> <LookAt> <longitude>0</longitude> <latitude>0</latitude> <altitude>0</altitude> <heading>0</heading> <tilt>0</tilt> <range>20770075.42761702</range> </LookAt> <GroundOverlay> <name>Learning to Use 3D Printer</name> <Icon> <href>https://drive.google.com/uc?view&id=0B1eALoRda8FTdDlfTnVRSWpSclU</href> </Icon> <LatLonBox> <north>90</north> <south>-90</south> <east>180</east> <west>-180</west> </LatLonBox> </GroundOverlay> </Document> </kml>
Lines 5 through 12 are where the camera (Point of view) is pointed. Camera is pointed at 0° Longitude, 0° Latitude, 0 altitude (looks at the ground and not above ground), heading and tilt are are set to 0 (look straight down to the ground), and a range of 20770075.42761702 (camera’s distance from the ground)
<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> <Document> <name>Learning to Use 3D Printer</name> <LookAt> <longitude>0</longitude> <latitude>0</latitude> <altitude>0</altitude> <heading>0</heading> <tilt>0</tilt> <range>20770075.42761702</range> </LookAt> <GroundOverlay> <name>Learning to Use 3D Printer</name> <Icon> <href>https://drive.google.com/uc?view&id=0B1eALoRda8FTdDlfTnVRSWpSclU</href> </Icon> <LatLonBox> <north>90</north> <south>-90</south> <east>180</east> <west>-180</west> </LatLonBox> </GroundOverlay> </Document> </kml>
Between lines 13 and 24 <GroundOverlay> are the instructions on loading and positioning the image
<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> <Document> <name>Learning to Use 3D Printer</name> <LookAt> <longitude>0</longitude> <latitude>0</latitude> <altitude>0</altitude> <heading>0</heading> <tilt>0</tilt> <range>20770075.42761702</range> </LookAt> <GroundOverlay> <name>Learning to Use 3D Printer</name> <Icon> <href>https://drive.google.com/uc?view&id=0B1eALoRda8FTdDlfTnVRSWpSclU</href> </Icon> <LatLonBox> <north>90</north> <south>-90</south> <east>180</east> <west>-180</west> </LatLonBox> </GroundOverlay> </Document> </kml>
Line 14: The name of the image layer
<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> <Document> <name>Learning to Use 3D Printer</name> <LookAt> <longitude>0</longitude> <latitude>0</latitude> <altitude>0</altitude> <heading>0</heading> <tilt>0</tilt> <range>20770075.42761702</range> </LookAt> <GroundOverlay> <name>Learning to Use 3D Printer</name> <Icon> <href>https://drive.google.com/uc?view&id=0B1eALoRda8FTdDlfTnVRSWpSclU</href> </Icon> <LatLonBox> <north>90</north> <south>-90</south> <east>180</east> <west>-180</west> </LatLonBox> </GroundOverlay> </Document> </kml>
Between lines 15 and 17 <Icon> is the url for the image that you want to wrap around the Earth. <href> translates to file path or in this case…url. Replacing the url between the <href> tag with you own image and save will change your Earth. You can use a local file and save as a kmz later. Again, I am using the direct download link from Google Drive. This is different then the shared link. Explanation to how to get this link will follow.
<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> <Document> <name>Learning to Use 3D Printer</name> <LookAt> <longitude>0</longitude> <latitude>0</latitude> <altitude>0</altitude> <heading>0</heading> <tilt>0</tilt> <range>20770075.42761702</range> </LookAt> <GroundOverlay> <name>Learning to Use 3D Printer</name> <Icon> <href>https://drive.google.com/uc?view&id=0B1eALoRda8FTdDlfTnVRSWpSclU</href> </Icon> <LatLonBox> <north>90</north> <south>-90</south> <east>180</east> <west>-180</west> </LatLonBox> </GroundOverlay> </Document> </kml>
<LatLonBox> positions the image. The top of the image will be positioned at 90° north, the bottom 90° south, right side will be 180° east and left side will be positioned -180° west.
Again, if you would like to create your own picture Earth copy and paste the code below into your text editor and replace the name of the Google Earth file (line 4), the name of the images layer (line 14), and the url between <href> tags with your own image (line 16). If your image and kml are in the same folder on your PC you can just enter the file name (ex.image.jpg). Make sure to save as a kml in your text editor then open the file in Google Earth then save as a .kmz file before sharing. This will pack/zip the image and kml together. Uncheck all the layers in the lower left frame in Google Earth to turn off boundaries etc.
<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> <Document> <name>Learning to Use 3D Printer</name> <LookAt> <longitude>0</longitude> <latitude>0</latitude> <altitude>0</altitude> <heading>0</heading> <tilt>0</tilt> <range>20770075.42761702</range> </LookAt> <GroundOverlay> <name>Learning to Use 3D Printer</name> <Icon> <href>https://drive.google.com/uc?view&id=0B1eALoRda8FTdDlfTnVRSWpSclU</href> </Icon> <LatLonBox> <north>90</north> <south>-90</south> <east>180</east> <west>-180</west> </LatLonBox> </GroundOverlay> </Document> </kml>
How to use Google Drive to host your Google Earth images.
I am not sure how long this will work. Google has a habit of changing/discontinuing these things, but for now you can get a direct link to your uploaded files by modifying the shared url. All you do is take the Google Drive’s file ID and add it to this url: https://drive.google.com/uc?view&id=
Example:
Google Drive’s shared url: https://drive.google.com/open?id=0B1eALoRda8FTYnBGa1NfY1ZQa1E and/or https://drive.google.com/file/d/0B1eALoRda8FTYnBGa1NfY1ZQa1E/view?usp=sharing (this depends on which shared url you prefer to use)
Direct link: https://drive.google.com/uc?view&id=0B1eALoRda8FTYnBGa1NfY1ZQa1E
**Important** Because Google Earth uses xml, the “&” sign after “view” needs to be replaced by xml equivalent “&”
Therefore the direct image link when coding kml via text editor is:https://drive.google.com/uc?view&id=0B1eALoRda8FTYnBGa1NfY1ZQa1E (same url as above direct link replacing the “&” with “&”)
Feel free to use this url converter created for my students if you have a number of images to convert (You will still have to manually replace “&” with “&”)
http://geteach.com/staticstreet
Google Chrome Extension here: Link
ROYALTY FREE MUSIC by BENSOUND