Example #1
0
        /// <summary>
        /// Converts a point into an oms object.
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        private static Point ConvertPoint(OsmSharp.Xml.Kml.v2_1.PointType point)
        {
            // convert the coordiantes.
            IList <GeoCoordinate> coordinates = KmlGeoStreamSource.ConvertCoordinates(point.coordinates);

            // create the point.
            Point pointGeometry = new Point(coordinates[0]);

            pointGeometry.Attributes = new SimpleGeometryAttributeCollection();
            if (point.targetId != null)
            {
                pointGeometry.Attributes.Add("targetId", point.targetId);
            }
            pointGeometry.Attributes.Add("altitude", point.altitudeMode);
            if (point.extrude)
            {
                pointGeometry.Attributes.Add("extrude", point.extrude);
            }
            if (point.id != null)
            {
                pointGeometry.Attributes.Add("id", point.id);
            }

            return(pointGeometry);
        }
Example #2
0
 /// <summary>
 /// Converts a geometry to a list of osm objects.
 /// </summary>
 /// <param name="geometry"></param>
 /// <returns></returns>
 private void ConvertGeometry(OsmSharp.Xml.Kml.v2_1.GeometryType geometry)
 {
     if (geometry is OsmSharp.Xml.Kml.v2_1.PointType)
     {
         this.GeometryCollection.Add(
             KmlGeoStreamSource.ConvertPoint(geometry as OsmSharp.Xml.Kml.v2_1.PointType));
     }
     else if (geometry is OsmSharp.Xml.Kml.v2_1.LineStringType)
     {
         this.GeometryCollection.Add(
             KmlGeoStreamSource.ConvertLineString(geometry as OsmSharp.Xml.Kml.v2_1.LineStringType));
     }
     else if (geometry is OsmSharp.Xml.Kml.v2_1.LinearRingType)
     {
         this.GeometryCollection.Add(
             KmlGeoStreamSource.ConvertLinearRing(geometry as OsmSharp.Xml.Kml.v2_1.LinearRingType));
     }
     else if (geometry is OsmSharp.Xml.Kml.v2_1.PolygonType)
     {
         this.GeometryCollection.Add(
             KmlGeoStreamSource.ConvertPolygon(geometry as OsmSharp.Xml.Kml.v2_1.PolygonType));
     }
     else if (geometry is OsmSharp.Xml.Kml.v2_1.MultiGeometryType)
     {
         this.ConvertMultiGeometry(geometry as OsmSharp.Xml.Kml.v2_1.MultiGeometryType);
     }
 }
Example #3
0
        /// <summary>
        /// Convests the polygon to osm objects.
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        private static Polygon ConvertPolygon(OsmSharp.Xml.Kml.v2_1.PolygonType polygon)
        {
            IEnumerable <LineairRing> inners = KmlGeoStreamSource.ConvertBoundary(polygon.innerBoundaryIs);
            LineairRing outer = KmlGeoStreamSource.ConvertLinearRing(polygon.outerBoundaryIs.LinearRing);

            return(new Polygon(outer, inners));
        }
Example #4
0
        /// <summary>
        /// Converts a polygon.
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        private static Polygon ConvertPolygon(OsmSharp.Xml.Kml.v2_0_response.Polygon polygon)
        {
            LineairRing inner = KmlGeoStreamSource.ConvertLinearRing(polygon.innerBoundaryIs.LinearRing);
            LineairRing outer = KmlGeoStreamSource.ConvertLinearRing(polygon.outerBoundaryIs.LinearRing);

            return(new Polygon(outer, new LineairRing[] { inner }));
        }
Example #5
0
        /// <summary>
        /// Converts boundary type into an osm object.
        /// </summary>
        /// <param name="boundary"></param>
        /// <returns></returns>
        private static IEnumerable <LineairRing> ConvertBoundary(OsmSharp.Xml.Kml.v2_1.boundaryType[] boundary)
        {
            List <LineairRing> rings = new List <LineairRing>();

            foreach (OsmSharp.Xml.Kml.v2_1.boundaryType geo in boundary)
            {
                rings.Add(KmlGeoStreamSource.ConvertLinearRing(geo.LinearRing));
            }
            return(rings);
        }
Example #6
0
        /// <summary>
        /// Converts a line string into an osm object.
        /// </summary>
        /// <param name="lineString"></param>
        /// <returns></returns>
        private static LineString ConvertLineString(OsmSharp.Xml.Kml.v2_1.LineStringType lineString)
        {
            // convert the coordinates.
            IList <GeoCoordinate> coordinates = KmlGeoStreamSource.ConvertCoordinates(lineString.coordinates);

            // create the ring.
            LineString lineStringGeometry = new LineString(coordinates);

            lineStringGeometry.Attributes = new SimpleGeometryAttributeCollection();
            lineStringGeometry.Attributes.Add("id", lineString.id);

            return(lineStringGeometry);
        }
Example #7
0
        /// <summary>
        /// Converts a lineairring into an osm object.
        /// </summary>
        /// <param name="linearRing"></param>
        /// <returns></returns>
        private static LineairRing ConvertLinearRing(OsmSharp.Xml.Kml.v2_0_response.LinearRing linearRing)
        {
            // convert the coordinates.
            IList <GeoCoordinate> coordinates = KmlGeoStreamSource.ConvertCoordinates(linearRing.coordinates);

            // create the ring.
            LineairRing ring = new LineairRing(coordinates);

            ring.Attributes = new SimpleGeometryAttributeCollection();
            ring.Attributes.Add("id", linearRing.id);

            return(ring);
        }
        public void KmlReadGeometryv2_0()
        {
            // initialize the geometry source.
            KmlGeoStreamSource kmlSource = new KmlGeoStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test.v2.0.kml"));

            // pull all the objects from the stream into the given collection.
            GeometryCollection kmlCollection = new GeometryCollection(kmlSource);
            List<Geometry> geometries = new List<Geometry>(kmlCollection);

            // test collection contents.
            Assert.AreEqual(1, geometries.Count);
            Assert.IsInstanceOf(typeof(Point), geometries[0]);
        }
Example #9
0
        /// <summary>
        /// Converts a multigeometry to osm objects.
        /// </summary>
        /// <param name="multiGeometry"></param>
        /// <returns></returns>
        private void ConvertMultiGeometry(OsmSharp.Xml.Kml.v2_0_response.MultiGeometry multiGeometry)
        {
            for (int idx = 0; idx < multiGeometry.Items.Length; idx++)
            {
                switch (multiGeometry.ItemsElementName[idx])
                {
                case OsmSharp.Xml.Kml.v2_0_response.ItemsChoiceType.LineString:
                    this.GeometryCollection.Add(
                        KmlGeoStreamSource.ConvertLineString(multiGeometry.Items[idx] as OsmSharp.Xml.Kml.v2_0_response.LineString));
                    break;

                case OsmSharp.Xml.Kml.v2_0_response.ItemsChoiceType.MultiGeometry:
                    this.ConvertMultiGeometry(multiGeometry.Items[idx] as OsmSharp.Xml.Kml.v2_0_response.MultiGeometry);
                    break;

                case OsmSharp.Xml.Kml.v2_0_response.ItemsChoiceType.MultiLineString:
                    this.GeometryCollection.Add(
                        KmlGeoStreamSource.ConvertMultiLineString(multiGeometry.Items[idx] as OsmSharp.Xml.Kml.v2_0_response.MultiLineString));
                    break;

                case OsmSharp.Xml.Kml.v2_0_response.ItemsChoiceType.MultiPoint:
                    this.GeometryCollection.Add(
                        KmlGeoStreamSource.ConvertMultiPoint(multiGeometry.Items[idx] as OsmSharp.Xml.Kml.v2_0_response.MultiPoint));
                    break;

                case OsmSharp.Xml.Kml.v2_0_response.ItemsChoiceType.MultiPolygon:
                    this.GeometryCollection.Add(
                        KmlGeoStreamSource.ConvertMultiPolygon(multiGeometry.Items[idx] as OsmSharp.Xml.Kml.v2_0_response.MultiPolygon));
                    break;

                case OsmSharp.Xml.Kml.v2_0_response.ItemsChoiceType.Point:
                    this.GeometryCollection.Add(
                        KmlGeoStreamSource.ConvertPoint(multiGeometry.Items[idx] as OsmSharp.Xml.Kml.v2_0_response.Point));
                    break;

                case OsmSharp.Xml.Kml.v2_0_response.ItemsChoiceType.Polygon:
                    this.GeometryCollection.Add(
                        KmlGeoStreamSource.ConvertPolygon(multiGeometry.Items[idx] as OsmSharp.Xml.Kml.v2_0_response.Polygon));
                    break;
                }
            }
        }
Example #10
0
        /// <summary>
        /// Converts a placemark into an osm object.
        /// </summary>
        /// <param name="placemark"></param>
        /// <returns></returns>
        private void ConvertPlacemark(OsmSharp.Xml.Kml.v2_0.Placemark placemark)
        {
            for (int idx = 0; idx < placemark.Items.Length; idx++)
            {
                switch (placemark.ItemsElementName[idx])
                {
                case OsmSharp.Xml.Kml.v2_0.ItemsChoiceType1.LineString:
                    this.GeometryCollection.Add(
                        KmlGeoStreamSource.ConvertLineString(placemark.Items[idx] as OsmSharp.Xml.Kml.v2_0.LineString));
                    break;

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

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

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

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

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

                case OsmSharp.Xml.Kml.v2_0.ItemsChoiceType1.Polygon:
                    this.GeometryCollection.Add(
                        KmlGeoStreamSource.ConvertPolygon(placemark.Items[idx] as OsmSharp.Xml.Kml.v2_0.Polygon));
                    break;
                }
            }
        }
Example #11
0
 /// <summary>
 /// Converts a multilinestring to osm objects.
 /// </summary>
 /// <param name="multiLineString"></param>
 /// <returns></returns>
 private static MultiLineString ConvertMultiLineString(OsmSharp.Xml.Kml.v2_0_response.MultiLineString multiLineString)
 {
     return(new MultiLineString(new LineString[] { KmlGeoStreamSource.ConvertLineString(multiLineString.LineString) }));
 }
Example #12
0
 /// <summary>
 /// Converts a multipoint to osm objects.
 /// </summary>
 /// <param name="multiPoint"></param>
 /// <returns></returns>
 private static MultiPoint ConvertMultiPoint(OsmSharp.Xml.Kml.v2_0_response.MultiPoint multiPoint)
 {
     return(new MultiPoint(new Point[] { KmlGeoStreamSource.ConvertPoint(multiPoint.Point) }));
 }
Example #13
0
 /// <summary>
 /// Converts a multipolygon into osm objects.
 /// </summary>
 /// <param name="multiPolygon"></param>
 /// <returns></returns>
 private static MultiPolygon ConvertMultiPolygon(OsmSharp.Xml.Kml.v2_0_response.MultiPolygon multiPolygon)
 {
     return(new MultiPolygon(new Polygon[] { KmlGeoStreamSource.ConvertPolygon(multiPolygon.Polygon) }));
 }
        public void KmlReadGeometryv2_1()
        {
            // initialize the geometry source.
            KmlGeoStreamSource kmlSource = new KmlGeoStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test.v2.1.kml"));

            // pull all the objects from the stream into the given collection.
            GeometryCollection kmlCollection = new GeometryCollection(kmlSource);
            List<Geometry> geometries = new List<Geometry>(kmlCollection);

            // test collection contents.
            Assert.AreEqual(23, geometries.Count);
            Assert.IsInstanceOf(typeof(LineString), geometries[0]);
            Assert.IsInstanceOf(typeof(LineString), geometries[1]);
            Assert.IsInstanceOf(typeof(LineString), geometries[2]);
            Assert.IsInstanceOf(typeof(LineString), geometries[3]);
            Assert.IsInstanceOf(typeof(LineString), geometries[4]);
            Assert.IsInstanceOf(typeof(LineString), geometries[5]);
            Assert.IsInstanceOf(typeof(LineString), geometries[6]);
            Assert.IsInstanceOf(typeof(LineString), geometries[7]);
            Assert.IsInstanceOf(typeof(LineString), geometries[8]);
            Assert.IsInstanceOf(typeof(LineString), geometries[9]);
            Assert.IsInstanceOf(typeof(LineString), geometries[10]);
            Assert.IsInstanceOf(typeof(LineString), geometries[11]);
            Assert.IsInstanceOf(typeof(LineString), geometries[12]);
            Assert.IsInstanceOf(typeof(LineString), geometries[13]);
            Assert.IsInstanceOf(typeof(LineString), geometries[14]);
            Assert.IsInstanceOf(typeof(LineString), geometries[15]);
            Assert.IsInstanceOf(typeof(LineString), geometries[16]);
            Assert.IsInstanceOf(typeof(LineString), geometries[17]);
            Assert.IsInstanceOf(typeof(LineString), geometries[18]);
            Assert.IsInstanceOf(typeof(LineString), geometries[19]);
            Assert.IsInstanceOf(typeof(LineString), geometries[20]);
            Assert.IsInstanceOf(typeof(LineString), geometries[21]);
            Assert.IsInstanceOf(typeof(LineString), geometries[22]);
        }