KML file not formatting a drawn line - kml

I am using the following code to generate a line in Google Earth, however the formatting of the line is not changing.
<Placemark>
<LineString>
<Style id="bendigo_line">
<LineStyle>
<width>3</width>
<color>64F0FF14</color>
</LineStyle>
</Style>
<coordinates>
-15,52,0
-20,53,0
-30,53,0
-40,53,0
-50,52,0
-53.233333,51.166667
</coordinates>
</LineString>
</Placemark>
I'm unsure of what I am doing wrong as this method has worked in the past and now doesn't change the line from the default thickness and colour.
Thanks

The <Style> element must appear outside the <LineString> element. KML requires elements in a particular order.
For the syntax of the Placemark refer to the KML Reference.
Try changing your KML to this order of elements:
<Placemark>
<Style>
<LineStyle>
<width>3</width>
<color>64F0FF14</color>
</LineStyle>
</Style>
<LineString>
<coordinates>
...
</coordinates>
</LineString>
</Placemark>
When there are problems with KML try first to validate it using the KML Validator.

Related

KML Layer Ordering

I have created KML files from esri Shapefiles to be used in google earth. The issue is when I bring in the two files bottom set of polygons will show the lines over the top polygons hiding a portion of the area.
I have seen people reference something about code but I was hoping someone could offer a different non-coding solution or explain better where this code would go and how it works.
Its not making sense to me.
I have tried changing the position of the two layers but any way doesn'f bring the smaller set of polygons to the top.
What I am looking for is the smaller set of polgyon lines to be completely visible while on top and the larger polygon set to be behind the first one
If you want one polygon to always be on top of another where both are clampedToGround then the gx:drawOrder property should be used.
Note the documentation (see below) only specifies LineStrings but also works for Lines, LinearRings, and Polygons. Anywhere "LineStrings" is mentioned below just replace it with Lines, Rings, and Polygons. The drawOrder support for Polygons is undocumented but is implemented in Google Earth nevertheless.
KML Documentation:
<gx:drawOrder>
"An integer value that specifies the order for drawing multiple line
strings (or polygons). LineStrings drawn first may be partially or fully
obscured by LineStrings with a later (or higher) draw order. This element may
be required in conjunction with the <gx:outerColor> and <gx:outerWidth>
elements in <LineStyle> when dual-colored lines cross each other."
In example below, the Red polygon is drawn over the blue polygon. To make the blue polygon draw over the red one change its drawOrder value to a higher number.
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<Document>
<Placemark>
<name>Red Polygon</name>
<description>gx:drawOrder=3</description>
<Style>
<LineStyle>
<color>ff000000</color>
</LineStyle>
<PolyStyle>
<color>ff0000ff</color>
</PolyStyle>
</Style>
<Polygon>
<gx:drawOrder>3</gx:drawOrder>
<tessellate>1</tessellate>
<outerBoundaryIs>
<LinearRing>
<coordinates>
14.456906,37.345497,0 14.949769,37.346531,0
14.960918,37.987563,0 14.45089,37.987521,0
14.456906,37.3455,0
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
<Placemark>
<name>Blue Polygon</name>
<description>gx:drawOrder=2</description>
<Style>
<LineStyle>
<color>ff000000</color>
</LineStyle>
<PolyStyle>
<color>ffff0000</color>
</PolyStyle>
</Style>
<Polygon>
<gx:drawOrder>2</gx:drawOrder>
<tessellate>1</tessellate>
<outerBoundaryIs>
<LinearRing>
<coordinates>
14.83626,38.016863,0 14.835535,37.645589,0
15.47025,37.589266,0 15.470457,38.019158,0
14.83626,38.016862,0
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</kml>

Google kml gx:drawOrder

<?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">
<Document>
<Style id="Line1">
<LineStyle>
<color>ffff0000</color>
<width>4</width>
</LineStyle>
</Style>
<Style id="Line2">
<LineStyle>
<color>ff00ff00</color>
<width>4</width>
</LineStyle>
</Style>
<Style id="Poly1">
<PolyStyle>
<color>ff0000ff</color>
</PolyStyle>
</Style>
<Style id="Poly2">
<PolyStyle>
<color>ffffffff</color>
</PolyStyle>
</Style>
<Placemark>
<name>Line 1</name>
<styleUrl>#Line1</styleUrl>
<LineString>
<coordinates>
-112.265654928602,36.09447672602546,2357
-112.2660384528238,36.09342608838671,2357
-112.2668139013453,36.09251058776881,2357
-112.2677826834445,36.09189827357996,2357
-112.2688557510952,36.0913137941187,2357
-112.2694810717219,36.0903677207521,2357
-112.2695268555611,36.08932171487285,2357
-112.2690144567276,36.08850916060472,2357
-112.2681528815339,36.08753813597956,2357
-112.2670588176031,36.08682685262568,2357
-112.2657374587321,36.08646312301303,2357
</coordinates>
<gx:drawOrder>2</gx:drawOrder>
</LineString>
</Placemark>
<Placemark>
<name>Polygon 1</name>
<styleUrl>#Poly1</styleUrl>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-112.265654928602,36.09447672602546,2357
-112.2660384528238,36.09342608838671,2357
-112.2668139013453,36.09251058776881,2357
-112.2677826834445,36.09189827357996,2357
-112.2688557510952,36.0913137941187,2357
-112.2694810717219,36.0903677207521,2357
-112.2695268555611,36.08932171487285,2357
-112.2690144567276,36.08850916060472,2357
-112.2681528815339,36.08753813597956,2357
-112.2670588176031,36.08682685262568,2357
-112.2657374587321,36.08646312301303,2357
</coordinates>
</LinearRing>
</outerBoundaryIs>
<gx:drawOrder>4</gx:drawOrder>
</Polygon>
</Placemark>
<Placemark>
<name>Line 2</name>
<styleUrl>#Line2</styleUrl>
<LineString>
<coordinates>
-112.265654928602,36.09447672602546,2357
-112.2660384528238,36.09342608838671,2357
-112.2668139013453,36.09251058776881,2357
-112.2677826834445,36.09189827357996,2357
-112.2688557510952,36.0913137941187,2357
-112.2694810717219,36.0903677207521,2357
-112.2695268555611,36.08932171487285,2357
-112.2690144567276,36.08850916060472,2357
-112.2681528815339,36.08753813597956,2357
-112.2670588176031,36.08682685262568,2357
-112.2657374587321,36.08646312301303,2357
</coordinates>
<gx:drawOrder>4</gx:drawOrder>
</LineString>
</Placemark>
<Placemark>
<name>Polygon 2</name>
<styleUrl>#Poly2</styleUrl>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-112.265654928602,36.09447672602546,2357
-112.2660384528238,36.09342608838671,2357
-112.2668139013453,36.09251058776881,2357
-112.2677826834445,36.09189827357996,2357
-112.2688557510952,36.0913137941187,2357
-112.2694810717219,36.0903677207521,2357
-112.2695268555611,36.08932171487285,2357
-112.2690144567276,36.08850916060472,2357
-112.2681528815339,36.08753813597956,2357
-112.2670588176031,36.08682685262568,2357
-112.2657374587321,36.08646312301303,2357
</coordinates>
</LinearRing>
</outerBoundaryIs>
<gx:drawOrder>8</gx:drawOrder>
</Polygon>
</Placemark>
</Document>
</kml>
So As you can see in the above kml I've tried to use the gx:drawOrder element to sort the line strings & the polygons into drawing layers. BUT... if you load this in the kml interactive sampler or even Google Earth (free desktop edition) the geometry primitives only z order sort among "like primitives". That is, the line strings are sorted only against other line strings and the polygons are only sorted against other polygons.
In this case you can see that both "line 1" and "line 2" have draw orders of < "Polygon 2" & I as such I was expecting "polygon 2" to draw over the top of everything. But that is NOT the case.
In the end I've had to use altitude values to implement the z order that I want, but it's quite an unsatisfactory solution as most people view kml geometry using an isometric projection & the altitude values cause my geometry to skew.
What I'd like to know is this:
Is this the expected behavior of gx:drawOrder? The document around the element is sparse & it even says that it's only applicable to the line string, but according to the xsd is should be applicable to all geometry primitives (which it appears to be... well at least to polygons as well anyway...)
Is there a way to get the gx:drawOrder to be applicable over all
geometry primitives?
Thanks in advance!
The KML documentation only mentions <gx:drawOrder> with respect to line strings not polygons nor does it mention the behavior of drawOrder across different geometries (lines, rings, and polygons). The drawOrder support for Polygons is undocumented but was reported as an issue in the bug tracker.
You would naturally expect the drawOrder to work the same over all geometry primitives, but looks like Google Earth draws the features in groups by type: polygons, then ground overlays, followed by lines and point data where drawOrder is applied only within a group. ScreenOverlays are drawn last so they are always on top.
This means that a polygon with drawOrder=2 overlapping a line with drawOrder=1 still shows the polygon under the line. Also, even if a polygon has a higher value drawOrder and overlaps a GroundOverlay (aka Image Overlay), the polygon is drawn first and hidden under the GroundOverlay.
gx:DrawOrder is not part of the OGC KML 2.2 standard. It's a Google KML Extension so Google defines how it works. Also means Google can change how it works.

Changing map styles in google earth

I'm adding a chloropleth US county map in Google Earth. I've made the map in qgis and exported as a KML, but the county borders become extremely thick when I open it in Google Earth. When I try to change it, it makes all of the borders and the county values uniform, and takes away the chloropleth. How can I change individual styles such as borders in Google Earth?
Here is a representative KML:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>geo_county_ma</name>
<Style id="style3">
<LineStyle>
<color>40000000</color>
<width>3</width>
</LineStyle>
<PolyStyle>
<color>ffe7d1af</color>
</PolyStyle>
</Style>
<Style id="style2">
<LineStyle>
<color>40000000</color>
<width>3</width>
</LineStyle>
<PolyStyle>
<color>fff4e6d7</color>
</PolyStyle>
</Style>
<Placemark>
<styleUrl>#style3</styleUrl>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-122.4361217223626,37.80089762963801 -122.431353047545,37.80152776851571 -122.4317440301943,37.80336276723568 -122.436466590289,37.80271696430888 -122.4361217223626,37.80089762963801
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
<Placemark>
<styleUrl>#style2</styleUrl>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-122.436124895585,37.80088925120538 -122.4313590833908,37.80150407165125 -122.4310083235047,37.79963224033016 -122.435667004224,37.79900507682146 -122.436124895585,37.80088925120538
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</kml>
If the lines/borders of polygons are too thick try changing the width value for LineStyle to 1 (or 2) whichever works best visually:
<LineStyle>
<color>40000000</color>
<width>1</width>
</LineStyle>
You can right-mouse click on each Placemark and manually change the style line width in Google Earth but suggest you change the KML in a text editor and globally replace <width>3</width> with <width>1</width>.

Can Draw Order of Polygons Be Controlled in KML?

I have adjacent polygons (clampToGround) where a portion of the boundaries overlap. I would like to be able to control which one appears on top. The only method I've found to work thus far is to list the polygon placemarks in stack order (last on list appears on top). However, I'd like to organize the placemarks based on other logic and would like a coding method to specify which polygon is on top.
Note, I've also tried using relativeToGround and small elevation differences, but that leads to potions of the polygons fill to disappear beneath the topography.
You can specify <gx:drawOrder> element (which is a Google Earth KML extension) to order polygons as well as lines and rings in your KML.
Note the documentation (see below) only specifies LineStrings but also works for Lines, LinearRings, and Polygons. Anywhere "LineStrings" is mentioned below just replace it with Lines, Rings, and Polygons. The drawOrder support for Polygons is undocumented but was reported as an issue.
KML Documentation:
<gx:drawOrder>
"An integer value that specifies the order for drawing multiple line
strings. LineStrings drawn first may be partially or fully obscured by LineStrings with a later (or higher) draw order. This element may be required in
conjunction with the <gx:outerColor> and <gx:outerWidth> elements in
<LineStyle> when dual-colored lines cross each other."
Note this will only work in clients that support the Google Earth KML extensions.
In example below, the Red polygon is drawn over the blue polygon. To make the blue polygon draw over the red one change its drawOrder value to a higher number.
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<Document>
<Placemark>
<name>Red Polygon</name>
<description>gx:drawOrder=3</description>
<Style>
<LineStyle>
<color>ff000000</color>
</LineStyle>
<PolyStyle>
<color>ff0000ff</color>
</PolyStyle>
</Style>
<Polygon>
<gx:drawOrder>3</gx:drawOrder>
<tessellate>1</tessellate>
<outerBoundaryIs>
<LinearRing>
<coordinates>
14.456906,37.345497,0 14.949769,37.346531,0
14.960918,37.987563,0 14.45089,37.987521,0
14.456906,37.3455,0
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
<Placemark>
<name>Blue Polygon</name>
<description>gx:drawOrder=2</description>
<Style>
<LineStyle>
<color>ff000000</color>
</LineStyle>
<PolyStyle>
<color>ffff0000</color>
</PolyStyle>
</Style>
<Polygon>
<gx:drawOrder>2</gx:drawOrder>
<tessellate>1</tessellate>
<outerBoundaryIs>
<LinearRing>
<coordinates>
14.83626,38.016863,0 14.835535,37.645589,0
15.47025,37.589266,0 15.470457,38.019158,0
14.83626,38.016862,0
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</kml>

Getting lines to work on Google Earth

So I've been sifting through GE's documentation, and found how to do LineStyle and LineString to style and display a line, but in practice I cannot actually make it work. Here's my KML:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"><Document><Style id="thisStyle">
<LineStyle>
<color>500078F0</color>
<colorMode>Normal</colorMode>
<width>5</width>
</LineStyle>
</Style>
<Placemark>
<name>502-2012-11-19 05:27:03</name>
<description>Speed:0</description>
<Point>
<coordinates>-76.0513,42.0894,247</coordinates>
</Point>
</Placemark>
<Placemark>
<name>502-2012-11-19 05:26:46</name>
<description>Speed:0</description>
<Point>
<coordinates>-76.0517,42.0886,287</coordinates>
</Point>
</Placemark>
....
<Placemark>
<name>525-2012-11-19 04:38:25</name>
<description>Speed:0</description>
<Point>
<coordinates>-76.0512,42.0894,178</coordinates>
</Point>
</Placemark>
<styleUrl>#thisStyle</styleUrl>
<LineString>
<tessellate>1</tessellate>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>
-76.0513,42.0894,247
-76.0517,42.0886,287
....
-76.0512,42.0894,178
</coordinates></LineString></Document></kml>
Note: The above places where "..." appears there are about 50 more coordinate sets, I removed them for the sake of brevity, but since all coordinates are produced by a script if one works I know they all will. Can anyone nudge me in the right direction as to why my placemarks all show up, but no lines?
A LineString element is only valid inside a Placemark (or a MultiGeometry inside a Placemark):
<Placemark>
<LineString>
<tessellate>1</tessellate>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>
-76.0513,42.0894,247
-76.0517,42.0886,287
-76.0512,42.0894,178
</coordinates>
</LineString>
</Placemark>
Example on Google Maps with your KML
Example on Google Maps with a Placemark containing the Linestring
You must either inline Style in the Placemark or reference the style in the Placemark using styleUrl element.
The last Placemark in your example needs to be rewritten like this:
<Placemark>
<name>525-2012-11-19 04:38:25</name>
<description>Speed:0</description>
<styleUrl>#thisStyle</styleUrl>
<LineString>
<tessellate>1</tessellate>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>
-76.0513,42.0894,247
-76.0517,42.0886,287
...
-76.0512,42.0894,178
</coordinates>
</LineString>
</Placemark>
If your KML doesn't view correctly then it usually helps to validate the KML. You can use the KML Validator.

Resources