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

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

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

                OsmSharp.IO.Xml.Kml.v2_0.Placemark type = (kml_type.Item as OsmSharp.IO.Xml.Kml.v2_0.Placemark);
                Assert.AreEqual(type.Items.Length, 3, "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();
        }
예제 #2
0
        public void KmlWriteTestv2_0()
        {
            // instantiate and load the gpx test document.
            XmlStreamSource source = new XmlStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.data.test.v2.0.kml"));
            KmlDocument document = new KmlDocument(source);
            object      kml      = document.Kml;

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

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

                    OsmSharp.IO.Xml.Kml.v2_0.Placemark type = (kml_type.Item as OsmSharp.IO.Xml.Kml.v2_0.Placemark);
                    Assert.AreEqual(type.Items.Length, 3, "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();
        }
예제 #3
0
        /// <summary>
        /// Converts a placemark into an osm object.
        /// </summary>
        /// <param name="placemark"></param>
        /// <returns></returns>
        private void ConvertPlacemark(OsmSharp.IO.Xml.Kml.v2_0.Placemark placemark)
        {
            for (int idx = 0; idx < placemark.Items.Length; idx++)
            {
                switch (placemark.ItemsElementName[idx])
                {
                case OsmSharp.IO.Xml.Kml.v2_0.ItemsChoiceType1.LineString:
                    this.GeometryCollection.Add(
                        KmlGeoStreamSource.ConvertLineString(placemark.Items[idx] as OsmSharp.IO.Xml.Kml.v2_0.LineString));
                    break;

                case OsmSharp.IO.Xml.Kml.v2_0.ItemsChoiceType1.MultiGeometry:
                    this.ConvertMultiGeometry(placemark.Items[idx] as OsmSharp.IO.Xml.Kml.v2_0.MultiGeometry);
                    break;

                case OsmSharp.IO.Xml.Kml.v2_0.ItemsChoiceType1.MultiLineString:
                    this.GeometryCollection.Add(
                        KmlGeoStreamSource.ConvertMultiLineString(placemark.Items[idx] as OsmSharp.IO.Xml.Kml.v2_0.MultiLineString));
                    break;

                case OsmSharp.IO.Xml.Kml.v2_0.ItemsChoiceType1.MultiPoint:
                    this.GeometryCollection.Add(
                        KmlGeoStreamSource.ConvertMultiPoint(placemark.Items[idx] as OsmSharp.IO.Xml.Kml.v2_0.MultiPoint));
                    break;

                case OsmSharp.IO.Xml.Kml.v2_0.ItemsChoiceType1.MultiPolygon:
                    this.GeometryCollection.Add(
                        KmlGeoStreamSource.ConvertMultiPolygon(placemark.Items[idx] as OsmSharp.IO.Xml.Kml.v2_0.MultiPolygon));
                    break;

                case OsmSharp.IO.Xml.Kml.v2_0.ItemsChoiceType1.Point:
                    this.GeometryCollection.Add(
                        KmlGeoStreamSource.ConvertPoint(placemark.Items[idx] as OsmSharp.IO.Xml.Kml.v2_0.Point));
                    break;

                case OsmSharp.IO.Xml.Kml.v2_0.ItemsChoiceType1.Polygon:
                    this.GeometryCollection.Add(
                        KmlGeoStreamSource.ConvertPolygon(placemark.Items[idx] as OsmSharp.IO.Xml.Kml.v2_0.Polygon));
                    break;
                }
            }
        }