Working with Lines
To show a line, you simply use a collection of points contained within a <LineString>
tag. The points define a connected set of line segments. GE will connect every pair of points with a direct line segment, so anything except a straight line will always require a sequence of linear segments. There's no concept of curves—in other words, GE doesn't provide a way to draw a "real curved line," but you can approximate curved lines with close-set points. The more points you use, the better the approximation.
Here's an example of the KML for a line (some points were removed for space reasons; you can find the complete sample in the downloadable code
shows the output.
|Figure 1. KML Line: If you load the KML line example in GE, you'll see this line, which is drawn using the complete list of points.|
The simplest part—the coordinates—are defined in the <coordinates>
node as a string with a sequence of comma-separated longitude, latitude, and altitude values. The <altitudeMode>
tag specifies how you want GE to interpret altitude values. Absolute
means that you will provide exact altitude values, but other options are clampToGround
, to make GE ignore altitude values, or relativeToGround
, meaning GE should interpret the altitude values you provide as "meters over the ground in that point." Typically, you'll use the absolute
whenever your point data includes accurate altitude values and clampToGround
if you didn't collect or don't have accurate altitude values (for example, if you're working from a database containing only 2D data).
nodes are Boolean values that determine whether your line is connected to the ground (extrude
), or whether the line will follow the terrain and cannot be underground (tessellate
). For most applications you will always set extrude
Working with Polygons
To define a solid polygon—for example, an area in GE—you use the <Polygon>
tag inside the standard <Placemark>
tag. A polygon is a closed figure with a boundary that defines an area. By default, polygons are filled areas, but you can nest them to create unfilled inner areas; in other words, you can nest two polygons. In such cases the enclosing polygon's area
consists of the area not enclosed by inner boundaries.
For example, here's the KML for a polygon with inner and outer boundaries:
|Figure 2. Polygons in GE: The Pentagon is a good example of nested polygons with inner and outer boundaries.|
nodes define the external and the internal boundary of this polygon. Both polygons boundaries are defined with <coordinates>
child nodes; containing the sequence of points that define the boundary. The coordinate syntax is the same used with points and lines tags. Note that the <outerBoundaryIs>
tag is mandatory, but <innerBoundaryIs>
is optional; if you don't provide it, GE will design a filled area. As an example, look at the Pentagon overlay in Figure 2
, which is a polygon with a nested inner polygon.