Draw Simple Shapes in Google Earth

Google Earth is a magnificent tool useful for both GIS amateurs as well as for professionals.

In this post we'll cover how we can generate basic shapes such as squares and circles for Google Earth using python & KML.

KML:

KML (Keyhole Markup Language) is Google Earths XML based file format for describing geographic data. A KML document can contain different kinds of "features" such as:

  • Placemarks
  • Paths
  • Polygons

Drawing a square in KML:

To draw a square shape in Google Earth using KML you can for example use KMLs polygon feature like this:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Style id="examplePolyStyle">
<PolyStyle>
<color>ff0000cc</color>
</PolyStyle>
</Style>
<Placemark>
<name>hollow box</name>
<styleUrl>#examplePolyStyle</styleUrl>
<Polygon>
<extrude>1</extrude>
<altitudeMode>clampToGround</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-74.0432344372,40.6914504354,0
-74.0432345372,40.6882717489,0
-74.0474265739,40.6882717489,0
-74.0474266739,40.6914504354,0
-74.0432344372,40.6914504354,0
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</kml>


This KML defines a red square around liberty island in NY

NB: In KML a point is specified as (lon, lat, alt), note lon comes before lat.

Next, do it with python (part 2):

No comments: