I am trying to create a polygon in KML above ground level. When the polygon size is small it works fine, but when the polygon is large it looks weird due to Z-fighting. I tried tessellation too, but the results are same.
<?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" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
<name>KmlFile</name>
<StyleMap id="TS">
<Pair>
<key>normal</key>
<styleUrl>#TS0</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#TS1</styleUrl>
</Pair>
</StyleMap>
<Style id="TS0">
<LineStyle id="TSLine">
<color>7f0000c0</color>
<width>2</width>
</LineStyle>
<PolyStyle id="TSPoly">
<color>7f0000c0</color>
</PolyStyle>
</Style>
<Style id="TS1">
<LineStyle id="TSLine">
<color>7f0000c0</color>
<width>2</width>
</LineStyle>
<PolyStyle id="TSPoly">
<color>7f0000c0</color>
</PolyStyle>
</Style>
<Placemark>
<name>Z-fighting issue with polygon</name>
<description>
Tessellation not working
</description>
<styleUrl>#TS</styleUrl>
<Polygon>
<tessellate>1</tessellate>
<altitudeMode>relativeToGround</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>
108.71,17.38,785 106.74,16.93,785 106.69,16.52,785 107.66,16.06,785 107.29,15.82,785 107.71,15.46,785 107.45,14.4,785 107.84,13.24,785 107.57,12.34,785 105.82,11.51,785 106.15,10.83,785 105.39,10.85,785 104.56,10.3,785 103.96,10.53,785 102.71,8.880000000000001,785 103.02,7.04,785 105.56,7.04,785 108.04,7.04,785 111.22,8.9,785 114.02,10.47,785 114.02,12.72,785 113.98,14.53,785 112.24,14.41,785 110.23,16.06,785 108.71,17.38,785
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</kml>
Any resolution for this issue?
Problem is that the earth is curved and a polygon in KML using altitudeMode of absolute or relativeToGround does NOT follow the earth's curvature and cuts through the surface of the earth as shown in the diagram below. This causes the polygon to be on a plane that when it intersects with the earth to have the edges at the appropriate altitude but the center cutting through the ocean surface.
Second issue is that tessellation is only enabled if the value for <altitudeMode>
is be clampToGround or clampToSeaFloor. Tesselation is ignored for absolute and relative altitudes.
If you change altitudeMode to clampToGround then the entire polygon will follow the curvature of the ground/ocean and the polygon will be over the ocean. Only then is tessellation enabled.
However, to represent the polygon over the ground the only workaround is creating smaller polygon regions whose size is small enough not to be affected by the curvature of the earth. Try with subdividing your polygon in to 4 smaller polygons. If that doesn't work then subdivide each of those into 4 polygons.
Details of this can be found in the OGC KML 2.2 spec in section 6.3.3.