0

I've managed to pull out the root information from it. I just need to figure out how to get what wraps around it(the header) so I can break up that root data if there is too much data for one file. I could then take those smaller segments and make new, smaller files. I just need to figure out how to isolate the header so it can easily be moved around. Here is an example of how my kml is set up. I'm working in C#, so answers pertaining to that are appreciated.

<?xml version="1.0" encoding="UTF-8"?>

<kml xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>LoopLengthSpeedExport</name>

<Schema name="Part2" id="kml_schema_ft_Part2">
<SimpleField type="string" name="Download">
<displayName>Download</displayName>
</SimpleField>
<SimpleField type="string" name="Upload">
<displayName>Upload</displayName>
</SimpleField>
<SimpleField type="string" name="DataDSLAM">
<displayName>DataDSLAM</displayName>
</SimpleField>
<SimpleField type="string" name="MetaDSLAM">
<displayName>MetaDSLAM</displayName>
</SimpleField>
<SimpleField type="string" name="Service Type">
<displayName>Service Type</displayName>
</SimpleField>
</Schema>
<Folder>
<name>LoopLengthSpeedExport</name>
<Placemark>
<name>Towns 707-787</name>

<description><![CDATA[<center><table><tr bgcolor="#E3E3F3">
<th>Download</th>
<td>0</td>
</tr><tr bgcolor="">
<th>Upload</th>
<td>0</td>
</tr><tr bgcolor="#E3E3F3">
<th>DataDSLAM</th>
<td>LY7</td>
</tr><tr bgcolor="">
<th>MetaDSLAM</th>
<td>L7</td>
</tr><tr bgcolor="#E3E3F3">
<th>Service Type</th>
<td>DSL</td>
</tr></table></center>]]></description>
<Style>
<IconStyle>
<scale>0.8</scale>
</IconStyle>
<LabelStyle>
<scale>1.0</scale>
</LabelStyle>
<LineStyle>
<color>ffffffff</color>
<width>1.0</width>

</LineStyle>
<PolyStyle>
<color>663f3f3f</color>
</PolyStyle>
</Style>
<ExtendedData>
<SchemaData schemaUrl="#kml_schema_ft_Part2">
<SimpleData name="Download">0</SimpleData>
<SimpleData name="Upload">0</SimpleData>
<SimpleData name="DataDSLAM">07</SimpleData>
<SimpleData name="MetaDSLAM">07</SimpleData>
<SimpleData name="Service Type">DSL</SimpleData>
</SchemaData>
</ExtendedData>
<Polygon>
<extrude>0</extrude>
<tessellate>0</tessellate>
<outerBoundaryIs>
<LinearRing>
<coordinates>0.0</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
<Placemark id="kml_82">
<name>Other town 707-782</name>

<description><![CDATA[<center><table><tr bgcolor="#E3E3F3">
<th>Download</th>
<td>0</td>
</tr><tr bgcolor="">
<th>Upload</th>
<td>0</td>
</tr><tr bgcolor="#E3E3F3">
<th>DataDSLAM</th>
<td>MTTR.05</td>
</tr><tr bgcolor="">
<th>MetaDSLAM</th>
<td>P07</td>
</tr><tr bgcolor="#E3E3F3">
<th>Service Type</th>
<td>DSL</td>
</tr></table></center>]]></description>
<Style>
<IconStyle>
<scale>0.8</scale>
</IconStyle>
<LabelStyle>
<scale>1.0</scale>
</LabelStyle>
<LineStyle>
<color>ffffffff</color>
<width>1.0</width>

</LineStyle>
<PolyStyle>
<color>663f3f3f</color>
</PolyStyle>
</Style>
<ExtendedData>
<SchemaData schemaUrl="#kml_schema_ft_Part2">
<SimpleData name="Download">0</SimpleData>
<SimpleData name="Upload">0</SimpleData>
<SimpleData name="DataDSLAM">MTTR.E3888.05</SimpleData>
<SimpleData name="MetaDSLAM">888</SimpleData>
<SimpleData name="Service Type">DSL</SimpleData>
</SchemaData>
</ExtendedData>
<Polygon>
<extrude>0</extrude>
<tessellate>0</tessellate>
<outerBoundaryIs>
<LinearRing>
<coordinates>57554,0.0</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>

</Folder>
</Document></kml>
  • KML is an XML file. KML can be huge so you should read using XML Reader. I solve similar issue recently. See my solution here : https://stackoverflow.com/questions/73843365/c-sharp-how-xmlreader-read-attributes-element-value/73843968#comment130392157_73843968 I have no idea what you mean the header, – jdweng Sep 28 '22 at 23:14
  • Also see following : https://stackoverflow.com/questions/48595116/c-sharp-not-able-to-find-a-node-within-the-xmlnode – jdweng Sep 28 '22 at 23:21

1 Answers1

0

I would not try to parse KML manually. Unless you want to account for every single edge case use an existing library that just works. https://github.com/samcragg/sharpkml

Now loading and parsing KML becomes dead simple as:

KmlFile file = KmlFile.Load("YourKmlFile.kml");

Kml kml = file.Root as Kml;
if (kml != null)
{
    foreach (var placemark in kml.Flatten().OfType<Placemark>())
    {
        Console.WriteLine(placemark.Name);
    }
}

Since you can treat the placemarks/geometry as objects, you can focus on splitting and writing that data to smaller files.

Anthony G.
  • 452
  • 2
  • 7
  • Some other KML parsing & writing libraries include LibKML (https://github.com/libkml/, for C++ & has SWIG bindings for other languages) and PyKML (https://pythonhosted.org/pykml/). Good luck. – Christiaan Adams Sep 29 '22 at 16:01