ComponentOne Maps for WPF and Silverlight
C1.WPF.Maps Namespace / KmlReader Class
Members Example

In This Topic
    KmlReader Class
    In This Topic
    Contains methods for importing KML and KMZ files.
    Object Model
    KmlReader Class
    Syntax
    'Declaration
     
    
    Public MustInherit NotInheritable Class KmlReader 
    public static class KmlReader 
    Remarks

    KML is a popular XML-based language used for representing geographic information.

    There are several tools available for creating, editing, and viewing KML files.

    There are also several sources of free and commercial KML and KMZ files, including for example www.geocommons.com and www.esri.com.

    KMZ is also a popular format which consists of zipped KML, and is also supported by the KmlReader class.

    The KmlReader 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 C1VectorLayer and placed on the map.
    Example
    The code below prompts the user for a KML or KMZ file, then uses the KmlReader class to parse the information into elements which are then added to a layer and to the map.
    // 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);
      }
    }
    Inheritance Hierarchy

    System.Object
       C1.WPF.Maps.KmlReader

    See Also