Inside the KML Placemark
Projects
Written by Mike James   
Tuesday, 05 October 2010
Article Index
Inside the KML Placemark
LinearRing
Style
3D concerns
More than one geometry
Polygon generator in Javascript

 

Banner

LinearRing

A LinearRing works in the same way as a LineString. The difference is that the lines form a closed figure.

You might think that for this to work you could simply change the above example into a LinearRing and immediately get a closed LineString - this doesn't work.

To make a LinearRing the last point has to be the same as the first point in the set of points. For example, to close the figure given earlier you would need to write:

<Placemark>  
<LinearRing>
<coordinates>
0.0,0.0,0.0
1.0,15.0,0.0
5.0,15.0,0.0
5.0,0.0,0.0
0.0,0.0,0.0
</coordinates>    
</LinearRing>
</Placemark>

Notice that the last point 0.0,0.0,0.0 is the same as the first. If you don't repeat the first point nothing gets drawn.

line3

Polygon

A Polygon is simply a filled LinearRing - i.e. a solid LinearRing. Basically to turn a LinearRing into a Polygon you surround it by a Polygon tag.

Well it is almost this simple - a Polygon can have an inner and an outer boundary both of which are usually determined by a LinearRing. A Polygon that has an inner boundary has a hole in it. So let's start with the simplest possible case - a Polygon with only and outer boundary:

<Placemark>  
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
0.0,0.0,0.0
1.0,15.0,0.0
5.0,15.0,0.0
5.0,0.0,0.0
0.0,0.0,0.0
</coordinates>    
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>

You can see that all we have done is to surround the LinearRing defined earlier with a <Polygon> and a <outerBoundryIs> tag.

poly1

 

If you want to see a Polygon with an inner boundary all you have to do is include a pair of innerBoundaryIs tags surrounding another LinearRing. For example:

<Placemark>  
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
0.0,0.0,0.0
1.0,15.0,0.0
5.0,15.0,0.0
5.0,0.0,0.0
0.0,0.0,0.0
</coordinates>    
</LinearRing>
</outerBoundaryIs>
<innerBoundaryIs>
<LinearRing>
<coordinates>
0.5,0.5,0.0
2,14.0,0.0
4.5,14.0,0.0
4.0,0.5,0.0
0.5,0.5,0.0
</coordinates>    
</LinearRing>
</innerBoundaryIs>
</Polygon>
</Placemark>

You can see that things are starting to look complicated and there is plenty of scope for making mistakes.

 

poly2

 

There is one subtlety that has been glossed over for the moment. When you define a Polygon the order of the points in the LinearRing matters. The reason is that the Polygon has two sides, a front face and a back face, and only one of them is filled.

To identify the front face of the polygon we use the rule that the points that define it have to be clockwise as listed. That is if you read the list of co-ordinates and plot each point in turn you for this to be the front face you have to be going round the polygon in a clockwise direction. If you go round in an anticlockwise direction then the face isn't drawn. It can be difficult to get right!

Banner

<ASIN:0789743647>

<ASIN:1430218290>

<ASIN:0470515112>

<ASIN:0470236825>

<ASIN:1430216204>

<ASIN:0596008651>



Last Updated ( Tuesday, 05 October 2010 )