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>
Related
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>
<?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.
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.
I'd like to display spatial data in Google Earth and I think the best way to do it is with polygons. I'd like both the height of a polygon as well as its color to both represent the data. The height is no problem, but I can't figure out how to force the polygon to have a constant color and/or shading. If I set a polygon's color to blue (FFFF0000), it appears light blue when viewed from one direction, but dark blue from another. For example, in the code below I have two polygons at 90 degrees to each other. Both of them should be the same color. However, when viewed in Google Earth, they clearly have a different color (or perhaps just different shading because they are at a different angle with respect to the viewer). Presumably this is by design, but I'd like to make polygons that have a constant color (or shading), irrespective of viewing angle. Does anybody know if this can be done?
Thanks
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2">
<Document>
<name>kml toolbox tests</name>
<Folder>
<name>kml.poly3</name>
<id>kml.poly3</id>
<Placemark id="kml_poly3tpfc275749_9c60_474d_b419_d29a903da8be">
<name>30</name>
<visibility>1</visibility>
<description/>
<Style>
<LineStyle>
<color>FFFFFFFF</color>
<width>5</width>
</LineStyle>
<PolyStyle>
<color>FFFF0000</color>
</PolyStyle>
</Style>
<Polygon id="Polygon_kml_poly3tpfc275749_9c60_474d_b419_d29a903da8be">
<extrude>0</extrude>
<tesselate>1</tesselate>
<altitudeMode>relativeToGround</altitudeMode>
<outerBoundaryIs>
<LinearRing id="LinearRing_kml_poly3tpfc275749_9c60_474d_b419_d29a903da8be">
<coordinates>-111.98,40.6,0
-111.97,40.6,0
-111.97,40.6,1500
-111.99,40.6,1500
-111.99,40.6,0 </coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
<Placemark id="kml_poly3tpb12d0de1_b554_45ed_b9fd_63d120582f23">
<name>31</name>
<visibility>1</visibility>
<description/>
<Style>
<LineStyle>
<color>FFFFFFFF</color>
<width>5</width>
</LineStyle>
<PolyStyle>
<color>FFFF0000</color>
</PolyStyle>
</Style>
<Polygon id="Polygon_kml_poly3tpb12d0de1_b554_45ed_b9fd_63d120582f23">
<extrude>0</extrude>
<tesselate>1</tesselate>
<altitudeMode>relativeToGround</altitudeMode>
<outerBoundaryIs>
<LinearRing id="LinearRing_kml_poly3tpb12d0de1_b554_45ed_b9fd_63d120582f23">
<coordinates>-111.97,40.6,0
-111.97,40.62,0
-111.97,40.62,2000
-111.97,40.6,2000
-111.97,40.6,0 </coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
<Camera id="ID">
<TimePrimitive>...</TimePrimitive>
<gx:ViewerOptions>
<option> name="camera" type="boolean"></option>
</gx:ViewerOptions>
<longitude>-111.94</longitude> <!-- kml:angle180 -->
<latitude>40.53</latitude> <!-- kml:angle90 -->
<altitude>7500</altitude> <!-- double -->
<heading>340</heading> <!-- kml:angle360 -->
<tilt>60</tilt> <!-- kml:anglepos180 -->
<roll>0</roll> <!-- kml:angle180 -->
<altitudeMode>absolute</altitudeMode>
</Camera>
</Folder>
</Document>
</kml>
This polygon shading issue is much worse on more recent versions of Google Earth. In recent versions a comment was added saying that now only one side of polygons is rendered so my next step will be to place polygons back to back with opposite point order rotation. This way, all polygons viewed from the sun angle direction can appear constantly shaded at least.
The KML standard as well as Google Earth doesn't allow you to specify advanced rendering options such shading options. The current Google Earth KML extensions do not allow this to be changed and setting slightly transparent color also has no effect.
If the viewing angle and the face of polygon are perpendicular to each other then the color is at maximum but as you the angle tilts and angle approaches 0 degrees then the color blackens. At less than 5-10 degrees the color is nearly completely black.
Only get uniform coloring if polygons are on the ground and view is looking straight down. That allows you to create heat map visualizations.
To request a new feature you can try the following steps:
Click "Send Feedback" under the Help menu and fill out a detailed
response to Google.
Start a discussion of the feature in the Google Earth forum.
Submit feature request via https://code.google.com/p/earth-issues/issues/list
I have asked to keep polygon, name of the polygon and the corresponding icon in the places panel.
Can any suggest me how to do this in kml?
By default you only see the name label if your placemark has a Point geometry so for lines and polygons the name is not shown.
You can however create a MultiGeometry with both a Polygon and a Point (typically the center point or where you want to label to appear near). If you don't want the default yellow pushpin to appear just add a Style with an empty IconStyle href element to the Placemark.
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>polygon</name>
<Style>
<IconStyle>
<Icon/>
</IconStyle>
</Style>
<MultiGeometry>
<Point>
<coordinates>-122.4317195,37.801848</coordinates>
</Point>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-122.43193945401,37.801983684521
-122.431564131101,37.8020327731402
-122.431499536494,37.801715236748
-122.43187136387,37.8016634915437
-122.43193945401,37.801983684521
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>
</kml>
This multi-geometry method can be HIGHLY tedious if you have a couple hundred polygons (say, a grid/index) and you want to show their names.
My preference is to use something like QGIS/Arc, where I create a new vector file of polygon centroids (point file) that has the polygon attributes (including name/description). I save the new point file as a point KML and import into Google Earth. From their, I set a shared style for the point file, with the icon set to 0% opacity.
Example of Google Earth Polygons with Labels using above method