TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
 Specialized Dev Zones Research Center eBook Library .NET Java C++ Web Dev Architecture Database Security Open Source Enterprise Mobile Special Reports 10-Minute Solutions DevXtra Blogs Slideshow

# Give Your Applications Mapping Capabilities, Part 2  : Page 2

## Learn to write applications that render static and real-time data positional data with Google Earth.

 by Bruno Zambetti
 Oct 30, 2007
 Page 2 of 4

### WEBINAR:On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning

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):

<Placemark> <name>A line</name> <LineString> <extrude>0</extrude> <tessellate>1</tessellate> <altitudeMode>clampToGround</altitudeMode> <coordinates> 9.576918333333341,45.629865,213.8 9.57692833333333,45.6299466666667,215 9.576956666666669,45.63006,214 9.576985000000002,45.63015833333331,213 9.577021666666671,45.63027500000001,212 9.57706333333333,45.63040333333331,211 9.577108333333342,45.6305383333333,211 9.577159999999999,45.6306766666667,210 9.577206666666671,45.63081833333331,210 9.577235,45.63089,209 9.57726166666667,45.63096333333331,209 9.577286666666669,45.63103833333331,209 9.577318333333331,45.631115,208 9.577353333333329,45.6311933333333,208 ... </coordinates> </LineString> </Placemark>

Figure 1 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).

The <extrude> and <tessellate> 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 to 0 and tessellate to 1.

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:

<Placemark> <name>A polygon</name> <Polygon> <extrude>1</extrude> <altitudeMode>relativeToGround</altitudeMode> <outerBoundaryIs> <LinearRing> <coordinates> -77.05788457660967,38.87253259892824,100 -77.05465973756702,38.87291016281703,100 -77.05315536854791,38.87053267794386,100 -77.05552622493516,38.868757801256,100 -77.05844056290393,38.86996206506943,100 -77.05788457660967,38.87253259892824,100 </coordinates> </LinearRing> </outerBoundaryIs> <innerBoundaryIs> <LinearRing> <coordinates> -77.05668055019126,38.87154239798456,100 -77.05542625960818,38.87167890344077,100 -77.05485125901024,38.87076535397792,100 -77.05577677433152,38.87008686581446,100 -77.05691162017543,38.87054446963351,100 -77.05668055019126,38.87154239798456,100 </coordinates>

 Figure 2. Polygons in GE: The Pentagon is a good example of nested polygons with inner and outer boundaries.
</LinearRing> </innerBoundaryIs> </Polygon> </Placemark>
The <outerBoundaryIs> and <innerBoundaryIs> 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.