Esempio n. 1
0
        public void KmlReadTestv2_1()
        {
            // instantiate and load the gpx test document.
            XmlStreamSource source = new XmlStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.data.test.v2.1.kml"));
            KmlDocument document = new KmlDocument(source);
            object      kml      = document.Kml;

            if (kml is OsmSharp.IO.Xml.Kml.v2_1.KmlType)
            { // all ok here!
                OsmSharp.IO.Xml.Kml.v2_1.KmlType kml_type = (kml as OsmSharp.IO.Xml.Kml.v2_1.KmlType);

                // test the gpx test file content.
                Assert.IsNotNull(kml_type.Item, "No item was found!");
                Assert.IsInstanceOf <OsmSharp.IO.Xml.Kml.v2_1.FolderType>(kml_type.Item, "Incorrect item type!");

                OsmSharp.IO.Xml.Kml.v2_1.FolderType type = (kml_type.Item as OsmSharp.IO.Xml.Kml.v2_1.FolderType);
                Assert.AreEqual(type.Items1.Length, 10, "Incorrect number of items in folder!");
            }
            else
            {
                Assert.Fail("No kml data was read, or data was of the incorrect type!");
            }

            document.Close();
            source.Close();
        }
Esempio n. 2
0
        public void KmlWriteTestv2_1()
        {
            // instantiate and load the gpx test document.
            XmlStreamSource source = new XmlStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.data.test.v2.1.kml"));
            KmlDocument document = new KmlDocument(source);
            object      kml      = document.Kml;

            if (kml is OsmSharp.IO.Xml.Kml.v2_1.KmlType)
            { // all ok here!
                // delete the target file.
                MemoryStream write_file = new MemoryStream();

                // create a new xml source.
                XmlStreamSource write_source = new XmlStreamSource(write_file);
                KmlDocument     kml_target   = new KmlDocument(write_source);

                // set the target data the same as the source document.
                kml_target.Kml = kml;

                // save the data.
                kml_target.Save();

                // close the old document.
                document.Close();
                source.Close();

                // check to see if the data was writter correctly.
                // instantiate and load the osm test document.
                source   = new XmlStreamSource(write_file);
                document = new KmlDocument(source);
                kml      = document.Kml;

                // check the result that was written and then read again.
                if (kml is OsmSharp.IO.Xml.Kml.v2_1.KmlType)
                { // all ok here!
                    OsmSharp.IO.Xml.Kml.v2_1.KmlType kml_type = (kml as OsmSharp.IO.Xml.Kml.v2_1.KmlType);

                    // test the gpx test file content.
                    Assert.IsNotNull(kml_type.Item, "No item was found!");
                    Assert.IsInstanceOf <OsmSharp.IO.Xml.Kml.v2_1.FolderType>(kml_type.Item, "Incorrect item type!");

                    OsmSharp.IO.Xml.Kml.v2_1.FolderType type = (kml_type.Item as OsmSharp.IO.Xml.Kml.v2_1.FolderType);
                    Assert.AreEqual(type.Items1.Length, 10, "Incorrect number of items in folder!");
                }
                else
                {
                    Assert.Fail("No kml data was read, or data was of the incorrect type!");
                }

                document.Close();
                source.Close();
            }
            else
            {
                Assert.Fail("No kml data was read, or data was of the incorrect type!");
            }

            document.Close();
            source.Close();
        }