0

I am attempting to generate a KML overlay. I have a grid I am mapping over an area, with colored squares. When I have the altitude mode as 'clampToGround' everything about the polygons I am generating, including their color, works as expected. However, it's not desirable to have the grid deform to map to the ground. When I change the altitude mode such that the overlay hovers a few meters off the ground, the shape of the grid sections is correct, but the color information is discarded and the grid sections are colored black.

Here is a testable excerpt of my KML code. Here is shows the colors correct but the grid deformed to the ground. Changing the value of altitudeMode to: absolute produces the other behavior.

Is there a way to have this at the correct altitude AND with the correct color at the same time?

<?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 id="1">
        <Document id="2">
            <Style id="10">
                <PolyStyle id="10">
                    <color>0xFF0000FF</color>
                    <colorMode>normal</colorMode>
                    <fill>1</fill>
                    <outline>1</outline>
                </PolyStyle>
            </Style>
            <name>Antenna Data</name>
            <Camera>
                <longitude>-122.30201334502573</longitude>
                <latitude>37.87244901754293</latitude>
                <altitude>200</altitude>
            </Camera>
            <Placemark id="5">
                <name>region</name>
                <styleUrl>#10</styleUrl>
                <Polygon id="4">
                    <altitudeMode>clampToGround</altitudeMode>
                    <outerBoundaryIs>
                        <LinearRing id="8">
                            <coordinates>-122.30243999999999,37.871973499999996,10 -122.30243999999999,37.8719265,10 -122.30238,37.8719265,10 -122.30238,37.871973499999996,10</coordinates>
                        </LinearRing>
                    </outerBoundaryIs>
                </Polygon>
            </Placemark>
        </Document>
    </Document>
</kml>
geocodezip
  • 158,664
  • 13
  • 220
  • 245
Kevin John
  • 71
  • 8

2 Answers2

1

Your KML has several issues.

The polygon is missing the closing vertex. In order to be a valid KML polygon, the first coordinate set (lon,lat,alt) must be repeated as the last coordinate set, so that the polygon closes itself. For your example of a square, you would need 5 coordinate sets, with the first and the last being the same.

Try fixing that first, and if you still see coloring issues, try making sure that the vertex winding direction is correct (anti-clockwise). If it's backwards, then the darker "bottom" of the polygon will be facing upwards, and might appear dark/black. Yours appears correct from looking at the coordinates, but I could be mistaken.

Also, your color is not a valid KML color, as it appears to have an extra "0x" in front. A valid KML color needs four two-character values (each between 00 and ff), representing Alpha, Blue, Green, Red (AABBGGRR, and yes, it's backwards from HTML colors). A solid red would be: FF0000FF.

Below is an updated copy of your KML sample with altitudeMode = absolute, the closing vertex added, and the color corrected... this works for me in Earth Pro.

<?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 id="1">
        <Document id="2">
            <Style id="10">
                <PolyStyle id="10">
                    <color>FF0000FF</color>
                    <colorMode>normal</colorMode>
                    <fill>1</fill>
                    <outline>1</outline>
                </PolyStyle>
            </Style>
            <name>Antenna Data</name>
            <Camera>
                <longitude>-122.30201334502573</longitude>
                <latitude>37.87244901754293</latitude>
                <altitude>200</altitude>
            </Camera>
            <Placemark id="5">
                <name>region</name>
                <styleUrl>#10</styleUrl>
                <Polygon id="4">
                    <altitudeMode>absolute</altitudeMode>
                    <outerBoundaryIs>
                        <LinearRing id="8">
                            <coordinates>-122.30243999999999,37.871973499999996,10 -122.30243999999999,37.8719265,10 -122.30238,37.8719265,10 -122.30238,37.871973499999996,10 -122.30243999999999,37.871973499999996,10</coordinates>
                        </LinearRing>
                    </outerBoundaryIs>
                </Polygon>
            </Placemark>
        </Document>
    </Document>
</kml>
geocodezip
  • 158,664
  • 13
  • 220
  • 245
Christiaan Adams
  • 1,257
  • 1
  • 7
  • 13
0

The solution I came across was that I could simple de-activate terrain in Google Earth. This seems to work now.

Kevin John
  • 71
  • 8