# C1.WPF.Maps.KmlReader

## Content

<div class="doc-site-dotnet-api-container">



  <h1 id="C1_WPF_Maps_KmlReader" data-uid="C1.WPF.Maps.KmlReader" class="text-break">KmlReader Class
</h1>
  <div class="markdown level0 summary"><p>Contains methods for importing KML and KMZ files.</p>
</div>
  <div class="markdown level0 conceptual"></div>
  <div class="inheritance">
    <h5>Inheritance</h5>
    <div class="level0"><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></div>
    <div class="level1"><span class="xref">KmlReader</span></div>
  </div>
  <h6><strong>Namespace</strong>: <a class="xref" href="C1.WPF.Maps.html">C1.WPF.Maps</a></h6>
  <h6><strong>Assembly</strong>: C1.WPF.Maps.dll</h6>
  <h5 id="C1_WPF_Maps_KmlReader_syntax">Syntax</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static class KmlReader</code></pre>
  </div>
  <div class="codewrapper">
    <pre><code class="lang-vbnet hljs">Public Module KmlReader</code></pre>
  </div>
  <h5 id="C1_WPF_Maps_KmlReader_remarks"><strong>Remarks</strong></h5>
  <div class="markdown level0 remarks"><p>KML is a popular XML-based language used for representing geographic information.</p>
<p>There are several tools available for creating, editing, and viewing KML files.</p>
<p>There are also several sources of free and commercial KML and KMZ files, including for example 
www.geocommons.com and www.esri.com.</p>
<p>KMZ is also a popular format which consists of zipped KML, and is also supported 
by the <a class="xref" href="C1.WPF.Maps.KmlReader.html">KmlReader</a> class.</p>
The <a class="xref" href="C1.WPF.Maps.KmlReader.html">KmlReader</a> class has static methods that create collections of vector 
objects from the supplied KML or KMZ source. These objects can then be added to a 
<a class="xref" href="C1.WPF.Maps.VectorLayer.html">VectorLayer</a> and placed on the map.
</div>
  <h5 id="C1_WPF_Maps_KmlReader_examples"><strong>Examples</strong></h5>
  <p>The code below prompts the user for a KML or KMZ file, then uses the <a class="xref" href="C1.WPF.Maps.KmlReader.html">KmlReader</a>
class to parse the information into elements which are then added to a layer and to the map.</p>
<pre><code class="lang-csharp">// prompt the user to pick a KML or KMZ file
var dlg = new OpenFileDialog();
dlg.Filter = "KML/KMZ geodata files (*.kml;*.kmz)|*.kml;*.kmz";
if (dlg.ShowDialog().Value)
{
  // open the file for reading
  using (var stream = dlg.File.OpenRead())
  {
    // create a new vector layer to hold the KML/KMZ items
    var kmlLayer = new C1VectorLayer();

    // read the items from the file and add them to the new layer
    var kmlItems = KmlReader.Read(stream);
    foreach (var item in kmlItems)
    {
      kmlLayer.Children.Add(item);
    }

    // add the new layer to the map
    _c1map.Layers.Add(kmlLayer);
  }
}</code></pre>

  <h3 id="methods">Methods
</h3>
  <table class="table table-bordered table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td id="C1_WPF_Maps_KmlReader_Read_System_IO_Stream_" data-uid="C1.WPF.Maps.KmlReader.Read(System.IO.Stream)">
          <a class="xref" href="C1.WPF.Maps.KmlReader.Read.html#C1_WPF_Maps_KmlReader_Read_System_IO_Stream_">Read(Stream)</a>
        </td>
        <td class="markdown level1 summary"><p>Read kml data from stream.</p>
</td>
      </tr>
      <tr>
        <td id="C1_WPF_Maps_KmlReader_Read_System_String_" data-uid="C1.WPF.Maps.KmlReader.Read(System.String)">
          <a class="xref" href="C1.WPF.Maps.KmlReader.Read.html#C1_WPF_Maps_KmlReader_Read_System_String_">Read(string)</a>
        </td>
        <td class="markdown level1 summary"><p>Read kml data from string.</p>
</td>
      </tr>
    </tbody>
  </table>

</div>
