FromKML() public method

public FromKML ( string coordinates ) : void
coordinates string
return void
Example #1
0
    /// <summary>
    /// Import XML data into this camera path overwriting the current data
    /// </summary>
    /// <param name="KMLPath">An Google Earth KML file path</param>
    public void FromKML(string KMLPath)
    {
        Debug.Log("Import Google Earth KML " + KMLPath);
        Clear();
        XmlDocument xml = new XmlDocument();

        using (StreamReader sr = new StreamReader(KMLPath))
        {
            xml.LoadXml(sr.ReadToEnd());
        }
        name = xml["kml"]["Document"]["Placemark"]["name"].FirstChild.Value;
        track.FromKML(xml["kml"]["Document"]["Placemark"]["LineString"]["coordinates"].FirstChild.Value);
    }
Example #2
0
    /// <summary>
    /// Import XML data into this camera path overwriting the current data
    /// </summary>
    /// <param name="KMLPath">An Google Earth KML file path</param>
    public void FromKML(string KMLPath)
    {
        Debug.Log("Track BuildR KML Import: Import Google Earth KML at " + KMLPath);
        Clear();

        try
        {
            XmlDocument xml = new XmlDocument();
            using (StreamReader sr = new StreamReader(KMLPath))
            {
                xml.LoadXml(sr.ReadToEnd());
            }

            if (xml["kml"] == null)
            {
                Debug.LogError("Track BuildR KML Import Error: Invlaid KML Document, no KML node entry");
                return;
            }

            if (xml["kml"]["Document"] == null)
            {
                Debug.LogError("Track BuildR KML Import Error: Invlaid KML Document, no Document node entry");
                return;
            }

            if (xml["kml"]["Document"]["Placemark"] == null)
            {
                Debug.LogError("Track BuildR KML Import Error: Invlaid KML Document, no Placemark node entry");
                return;
            }

            if (xml["kml"]["Document"]["Placemark"]["name"] != null && xml["kml"]["Document"]["Placemark"]["name"].FirstChild != null)
            {
                name = xml["kml"]["Document"]["Placemark"]["name"].FirstChild.Value;
            }
            else
            {
                name = "KML Import";
            }

            int nodes = xml["kml"]["Document"].ChildNodes.Count;
            for (int i = 0; i < nodes; i++)
            {
                XmlNode node = xml["kml"]["Document"].ChildNodes[i];
                if (node.Name == "Placemark")
                {
                    if (node["LineString"] != null)
                    {
                        if (node["LineString"]["coordinates"] != null)
                        {
                            track.FromKML(node["LineString"]["coordinates"].FirstChild.Value);
                            return;
                        }
                    }
                }
            }
            Debug.LogError("Track BuildR could not convert KML file, contact [email protected] and I'll sort this out. Thanks");
        }
        catch (Exception e)
        {
            Debug.LogError("Track BuildR could not convert KML file, contact [email protected] and I'll sort this out. ERROR: " + e);
        }
    }