David Smith

David Smith

  • NA
  • 2k
  • 0

XmlDocument KML Placemark Polygon Coodinates

Sep 30 2016 8:27 AM

I have a simple kml file where I select a specify node and replace the coordinates in the placemark xPath, However I need to add the polygon to the kml placemark path. So there will be two identical polygons in the same polygon file. Review kml data below. I am trying to figure out how to add the second polygon in the file.

I have both polygon coodinates in memory ready to add to the polygon section, but I havent thought of robust way to add the second polygon to placemark xpath. This is what I am doing currently with a template file.

KmlObjectString = geoFileStringBuilder.ToString();

var xmlNode = kmlDoc.SelectSingleNode("kml/Document/Placemark/MultiGeometry/Polygon/outerBoundaryIs/LinearRing/coordinates");
if (xmlNode != null)
{
xmlNode.InnerText = KmlObjectString.ToString();
string[] nameArray = browseFile.SafeFileName.Split('.');
kmlDoc.Save(@"C:\temp\KML\" + nameArray[0] + ".kml");
}


START WITH:

<Placemark>
<name>Volume</name>
<styleUrl>#default0</styleUrl>
<MultiGeometry>
<Polygon>
<!-- top -->
<tessellate>1</tessellate>
<altitudeMode>absolute</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>-118.805245304129,34.2582332081979,1490
-118.796790853877,34.2497094883196,1490
-118.778939913084,34.2512370401627,1490
-118.778024543953,34.2582326065422,1490
-118.77893786207,34.2652282224139,1490
-118.796792544255,34.2667579688469,1490
-118.805245304129,34.2582332081979,1490
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>
</Document>

EXPECTED OUTPUT BELOW

<Placemark>
<name>Volume</name>
<styleUrl>#default0</styleUrl>
<MultiGeometry>
<Polygon>
<!-- top -->
<tessellate>1</tessellate>
<altitudeMode>absolute</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>-118.805245304129,34.2582332081979,1490
-118.796790853877,34.2497094883196,1490
-118.778939913084,34.2512370401627,1490
-118.778024543953,34.2582326065422,1490
-118.77893786207,34.2652282224139,1490
-118.796792544255,34.2667579688469,1490
-118.805245304129,34.2582332081979,1490
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
<Polygon>
<!-- bottom-->
<tessellate>1</tessellate>
<altitudeMode>absolute</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>-118.805245304129,34.2582332081979,1300
-118.796790853877,34.2497094883196,1300
-118.778939913084,34.2512370401627,1300
-118.778024543953,34.2582326065422,1300
-118.77893786207,34.2652282224139,1300
-118.796792544255,34.2667579688469,1300
-118.805245304129,34.2582332081979,1300
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>
</Document>


Answers (4)