[]
Contains methods for importing KML and KMZ files.
public static class KmlReader
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 VectorLayer and placed on the map.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);
}
}
| Name | Description |
|---|---|
| Read(Stream) | Read kml data from stream. |
| Read(string) | Read kml data from string. |