コード例 #1
0
ファイル: KmlXmlTest.cs プロジェクト: robert-hickey/OsmSharp
        public void KmlReadTestv2_0_response()
        {
            // instantiate and load the gpx test document.
            XmlStreamSource source = new XmlStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test.v2.0.response.kml"));
            KmlDocument document = new KmlDocument(source);
            object kml = document.Kml;

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

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

                OsmSharp.Xml.Kml.v2_0_response.Response type = (kml_type.Item as OsmSharp.Xml.Kml.v2_0_response.Response);
                Assert.AreEqual(type.Items.Length, 8, "Incorrect number of items in response!");
            }
            else
            {
                Assert.Fail("No kml data was read, or data was of the incorrect type!");
            }

            document.Close();
            source.Close();
        }
コード例 #2
0
ファイル: GpxXmlTest.cs プロジェクト: robert-hickey/OsmSharp
        public void GpxReadv1_1Test()
        {
            // instantiate and load the gpx test document.
            XmlStreamSource source = new XmlStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test.v1.1.gpx"));
            GpxDocument document = new GpxDocument(source);
            object gpx = document.Gpx;

            if (gpx is OsmSharp.Xml.Gpx.v1_1.gpxType)
            { // all ok here!
                OsmSharp.Xml.Gpx.v1_1.gpxType gpx_type = (gpx as OsmSharp.Xml.Gpx.v1_1.gpxType);

                // test the gpx test file content.
                Assert.IsNotNull(gpx_type.trk, "Gpx has no track!");
                Assert.AreEqual(gpx_type.trk[0].trkseg.Length, 1, "Not the correct number of track segments found!");
            }
            else
            {
                Assert.Fail("No gpx data was read, or data was of the incorrect type!");
            }

            document.Close();
            source.Close();
        }
コード例 #3
0
        /// <summary>
        /// Reads the actual Kml.
        /// </summary>
        private void DoReadKml()
        {
            // seek to the beginning of the stream.
            if (_stream.CanSeek) { _stream.Seek(0, SeekOrigin.Begin); }

            // instantiate and load the gpx test document.
            XmlStreamSource source = new XmlStreamSource(_stream);
            KmlDocument document = new KmlDocument(source);
            object kml = document.Kml;

            switch (document.Version)
            {
                case KmlVersion.Kmlv2_1:
                    this.ConvertKml(kml as OsmSharp.Xml.Kml.v2_1.KmlType);
                    break;
                case KmlVersion.Kmlv2_0_response:
                    this.ConvertKml(kml as OsmSharp.Xml.Kml.v2_0_response.kml);
                    break;
                case KmlVersion.Kmlv2_0:
                    this.ConvertKml(kml as OsmSharp.Xml.Kml.v2_0.kml);
                    break;
            }
        }
コード例 #4
0
        /// <summary>
        /// Reads the actual Gpx.
        /// </summary>
        private void DoReadGpx()
        {
            // seek to the beginning of the stream.
            if (_stream.CanSeek) { _stream.Seek(0, SeekOrigin.Begin); }

            // instantiate and load the gpx test document.
            XmlStreamSource source = new XmlStreamSource(_stream);
            GpxDocument document = new GpxDocument(source);
            object gpx = document.Gpx;

            switch(document.Version)
            {
                case GpxVersion.Gpxv1_0:
                    this.ReadGpxv1_0(gpx as OsmSharp.Xml.Gpx.v1_0.gpx);
                    break;
                case GpxVersion.Gpxv1_1:
                    this.ReadGpxv1_1(gpx as Xml.Gpx.v1_1.gpxType);
                    break;
            }
        }
コード例 #5
0
ファイル: GpxXmlTest.cs プロジェクト: robert-hickey/OsmSharp
        public void GpxWritev1_1Test()
        {
            // instantiate and load the gpx test document.
            XmlStreamSource source = new XmlStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test.v1.1.gpx"));
            GpxDocument document = new GpxDocument(source);
            object gpx = document.Gpx;

            if (gpx is OsmSharp.Xml.Gpx.v1_1.gpxType)
            { // all ok here!
                // get the target file.
                MemoryStream write_file = new MemoryStream();

                // create a new xml source.
                XmlStreamSource write_source = new XmlStreamSource(write_file);
                GpxDocument gpx_target = new GpxDocument(write_source);

                // set the target data the same as the source document.
                gpx_target.Gpx = gpx;

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

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

                // check to see if the data was writter correctly.
                // instantiate and load the gpx test document.
                source = new XmlStreamSource(write_file);
                document = new GpxDocument(source);
                gpx = document.Gpx;
                if (gpx is OsmSharp.Xml.Gpx.v1_1.gpxType)
                { // all ok here!
                    OsmSharp.Xml.Gpx.v1_1.gpxType gpx_type = (gpx as OsmSharp.Xml.Gpx.v1_1.gpxType);

                    // test the gpx test file content.
                    Assert.IsNotNull(gpx_type.trk, "Gpx has not track!");
                    Assert.AreEqual(gpx_type.trk[0].trkseg.Length, 1, "Not the correct number of track segments found!");
                }
                else
                {
                    Assert.Fail("No gpx data was read, or data was of the incorrect type!");
                }
            }
            else
            {
                Assert.Fail("No gpx data was read, or data was of the incorrect type!");
            }

            document.Close();
            source.Close();
        }
コード例 #6
0
ファイル: KmlXmlTest.cs プロジェクト: robert-hickey/OsmSharp
        public void KmlWriteTestv2_1()
        {
            // instantiate and load the gpx test document.
            XmlStreamSource source = new XmlStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test.v2.1.kml"));
            KmlDocument document = new KmlDocument(source);
            object kml = document.Kml;

            if (kml is OsmSharp.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.Xml.Kml.v2_1.KmlType)
                { // all ok here!
                    OsmSharp.Xml.Kml.v2_1.KmlType kml_type = (kml as OsmSharp.Xml.Kml.v2_1.KmlType);

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

                    OsmSharp.Xml.Kml.v2_1.FolderType type = (kml_type.Item as OsmSharp.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();
        }