Exemplo n.º 1
0
 /// <summary>
 /// Converts a geometry to a list of osm objects.
 /// </summary>
 /// <param name="geometry"></param>
 /// <returns></returns>
 private void ConvertGeometry(OsmSharp.IO.Xml.Kml.v2_1.GeometryType geometry)
 {
     if (geometry is OsmSharp.IO.Xml.Kml.v2_1.PointType)
     {
         this.FeatureCollection.Add(
             KmlFeatureStreamSource.ConvertPoint(geometry as OsmSharp.IO.Xml.Kml.v2_1.PointType));
     }
     else if (geometry is OsmSharp.IO.Xml.Kml.v2_1.LineStringType)
     {
         this.FeatureCollection.Add(
             KmlFeatureStreamSource.ConvertLineString(geometry as OsmSharp.IO.Xml.Kml.v2_1.LineStringType));
     }
     else if (geometry is OsmSharp.IO.Xml.Kml.v2_1.LinearRingType)
     {
         this.FeatureCollection.Add(
             KmlFeatureStreamSource.ConvertLinearRing(geometry as OsmSharp.IO.Xml.Kml.v2_1.LinearRingType));
     }
     else if (geometry is OsmSharp.IO.Xml.Kml.v2_1.PolygonType)
     {
         this.FeatureCollection.Add(
             KmlFeatureStreamSource.ConvertPolygon(geometry as OsmSharp.IO.Xml.Kml.v2_1.PolygonType));
     }
     else if (geometry is OsmSharp.IO.Xml.Kml.v2_1.MultiGeometryType)
     {
         this.ConvertMultiGeometry(geometry as OsmSharp.IO.Xml.Kml.v2_1.MultiGeometryType);
     }
 }
Exemplo n.º 2
0
 private static Feature ConvertMultiPoint(OsmSharp.IO.Xml.Kml.v2_0_response.MultiPoint multiPoint)
 {
     return(new Feature((Geometry) new OsmSharp.Geo.Geometries.MultiPoint(new OsmSharp.Geo.Geometries.Point[1]
     {
         KmlFeatureStreamSource.ConvertPoint(multiPoint.Point).Geometry as OsmSharp.Geo.Geometries.Point
     })));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Convests the polygon to osm objects.
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        private static Feature ConvertPolygon(OsmSharp.IO.Xml.Kml.v2_1.PolygonType polygon)
        {
            IEnumerable <LineairRing> inners = KmlFeatureStreamSource.ConvertBoundary(polygon.innerBoundaryIs);
            LineairRing outer = KmlFeatureStreamSource.ConvertLinearRing(polygon.outerBoundaryIs.LinearRing).Geometry as LineairRing;

            return(new Feature(new Polygon(outer, inners)));
        }
Exemplo n.º 4
0
 private static Feature ConvertMultiLineString(OsmSharp.IO.Xml.Kml.v2_0_response.MultiLineString multiLineString)
 {
     return(new Feature((Geometry) new OsmSharp.Geo.Geometries.MultiLineString(new OsmSharp.Geo.Geometries.LineString[1]
     {
         KmlFeatureStreamSource.ConvertLineString(multiLineString.LineString).Geometry as OsmSharp.Geo.Geometries.LineString
     })));
 }
Exemplo n.º 5
0
        /// <summary>
        /// Converts a polygon.
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        private static Feature ConvertPolygon(OsmSharp.IO.Xml.Kml.v2_0_response.Polygon polygon)
        {
            var inner = KmlFeatureStreamSource.ConvertLinearRing(polygon.innerBoundaryIs.LinearRing);
            var outer = KmlFeatureStreamSource.ConvertLinearRing(polygon.outerBoundaryIs.LinearRing);

            return(new Feature(new Polygon(outer.Geometry as LineairRing, new LineairRing[] { inner.Geometry as LineairRing })));
        }
Exemplo n.º 6
0
 private void ConvertGeometry(GeometryType geometry)
 {
     if (geometry is PointType)
     {
         this.FeatureCollection.Add(KmlFeatureStreamSource.ConvertPoint(geometry as PointType));
     }
     else if (geometry is LineStringType)
     {
         this.FeatureCollection.Add(KmlFeatureStreamSource.ConvertLineString(geometry as LineStringType));
     }
     else if (geometry is LinearRingType)
     {
         this.FeatureCollection.Add(KmlFeatureStreamSource.ConvertLinearRing(geometry as LinearRingType));
     }
     else if (geometry is PolygonType)
     {
         this.FeatureCollection.Add(KmlFeatureStreamSource.ConvertPolygon(geometry as PolygonType));
     }
     else
     {
         if (!(geometry is MultiGeometryType))
         {
             return;
         }
         this.ConvertMultiGeometry(geometry as MultiGeometryType);
     }
 }
Exemplo n.º 7
0
 private static Feature ConvertMultiPolygon(OsmSharp.IO.Xml.Kml.v2_0_response.MultiPolygon multiPolygon)
 {
     return(new Feature((Geometry) new OsmSharp.Geo.Geometries.MultiPolygon(new OsmSharp.Geo.Geometries.Polygon[1]
     {
         KmlFeatureStreamSource.ConvertPolygon(multiPolygon.Polygon).Geometry as OsmSharp.Geo.Geometries.Polygon
     })));
 }
Exemplo n.º 8
0
        private static Feature ConvertPolygon(OsmSharp.IO.Xml.Kml.v2_0_response.Polygon polygon)
        {
            Feature feature = KmlFeatureStreamSource.ConvertLinearRing(polygon.innerBoundaryIs.LinearRing);

            return(new Feature((Geometry) new OsmSharp.Geo.Geometries.Polygon(KmlFeatureStreamSource.ConvertLinearRing(polygon.outerBoundaryIs.LinearRing).Geometry as LineairRing, (IEnumerable <LineairRing>) new LineairRing[1]
            {
                feature.Geometry as LineairRing
            })));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Converts boundary type into an osm object.
        /// </summary>
        /// <param name="boundary"></param>
        /// <returns></returns>
        private static IEnumerable <LineairRing> ConvertBoundary(OsmSharp.IO.Xml.Kml.v2_1.boundaryType[] boundary)
        {
            List <LineairRing> rings = new List <LineairRing>();

            foreach (OsmSharp.IO.Xml.Kml.v2_1.boundaryType geo in boundary)
            {
                rings.Add(KmlFeatureStreamSource.ConvertLinearRing(geo.LinearRing).Geometry as LineairRing);
            }
            return(rings);
        }
Exemplo n.º 10
0
        private static IEnumerable <LineairRing> ConvertBoundary(boundaryType[] boundary)
        {
            List <LineairRing> lineairRingList = new List <LineairRing>();

            foreach (boundaryType boundaryType in boundary)
            {
                lineairRingList.Add(KmlFeatureStreamSource.ConvertLinearRing(boundaryType.LinearRing).Geometry as LineairRing);
            }
            return((IEnumerable <LineairRing>)lineairRingList);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Converts a line string into an osm object.
        /// </summary>
        /// <param name="lineString"></param>
        /// <returns></returns>
        private static Feature ConvertLineString(OsmSharp.IO.Xml.Kml.v2_1.LineStringType lineString)
        {
            // convert the coordinates.
            var coordinates = KmlFeatureStreamSource.ConvertCoordinates(lineString.coordinates);

            // create the ring.
            var feature = new Feature(new LineString(coordinates));

            feature.Attributes.Add("id", lineString.id);

            return(feature);
        }
Exemplo n.º 12
0
        public void KmlReadGeometryv2_0()
        {
            // initialize the geometry source.
            var kmlSource = new KmlFeatureStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.data.test.v2.0.kml"));

            // pull all the objects from the stream into the given collection.
            var kmlCollection = new FeatureCollection(kmlSource);
            var features = new List<Feature>(kmlCollection);

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

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

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

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

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

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

                case OsmSharp.IO.Xml.Kml.v2_0_response.ItemsChoiceType.Polygon:
                    this.FeatureCollection.Add(
                        KmlFeatureStreamSource.ConvertPolygon(multiGeometry.Items[idx] as OsmSharp.IO.Xml.Kml.v2_0_response.Polygon));
                    break;
                }
            }
        }
Exemplo n.º 14
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.FeatureCollection.Add(
                        KmlFeatureStreamSource.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.FeatureCollection.Add(
                        KmlFeatureStreamSource.ConvertMultiLineString(placemark.Items[idx] as OsmSharp.IO.Xml.Kml.v2_0.MultiLineString));
                    break;

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

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

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

                case OsmSharp.IO.Xml.Kml.v2_0.ItemsChoiceType1.Polygon:
                    this.FeatureCollection.Add(
                        KmlFeatureStreamSource.ConvertPolygon(placemark.Items[idx] as OsmSharp.IO.Xml.Kml.v2_0.Polygon));
                    break;
                }
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Converts a point into an osm object.
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        private static Feature ConvertPoint(OsmSharp.IO.Xml.Kml.v2_0_response.Point point)
        {
            // convert the coordiantes.
            var coordinates = KmlFeatureStreamSource.ConvertCoordinates(point.coordinates);

            // create the point.
            var feature = new Feature(new Point(coordinates[0]));

            if (point.altitudeModeSpecified)
            {
                feature.Attributes.Add("altitude", point.altitudeMode);
            }
            if (point.extrudeSpecified)
            {
                feature.Attributes.Add("extrude", point.extrude);
            }
            if (point.id != null)
            {
                feature.Attributes.Add("id", point.id);
            }

            return(feature);
        }
Exemplo n.º 16
0
        private static Feature ConvertPoint(PointType point)
        {
            Feature feature = new Feature((Geometry) new OsmSharp.Geo.Geometries.Point(KmlFeatureStreamSource.ConvertCoordinates(point.coordinates)[0]));

            if (point.targetId != null)
            {
                feature.Attributes.Add("targetId", (object)point.targetId);
            }
            feature.Attributes.Add("altitude", (object)point.altitudeMode);
            if (point.extrude)
            {
                feature.Attributes.Add("extrude", (object)point.extrude);
            }
            if (point.id != null)
            {
                feature.Attributes.Add("id", (object)point.id);
            }
            return(feature);
        }
Exemplo n.º 17
0
 private static Feature ConvertLineString(LineStringType lineString)
 {
     return(new Feature((Geometry) new OsmSharp.Geo.Geometries.LineString((IEnumerable <GeoCoordinate>)KmlFeatureStreamSource.ConvertCoordinates(lineString.coordinates)))
     {
         Attributes =
         {
             {
                 "id",
                 (object)lineString.id
             }
         }
     });
 }
Exemplo n.º 18
0
 /// <summary>
 /// Converts a multipoint to osm objects.
 /// </summary>
 /// <param name="multiPoint"></param>
 /// <returns></returns>
 private static Feature ConvertMultiPoint(OsmSharp.IO.Xml.Kml.v2_0.MultiPoint multiPoint)
 {
     return(new Feature(new MultiPoint(new Point[] { KmlFeatureStreamSource.ConvertPoint(multiPoint.Point).Geometry as Point })));
 }
Exemplo n.º 19
0
        private static Feature ConvertPolygon(PolygonType polygon)
        {
            IEnumerable <LineairRing> holes = KmlFeatureStreamSource.ConvertBoundary(polygon.innerBoundaryIs);

            return(new Feature((Geometry) new OsmSharp.Geo.Geometries.Polygon(KmlFeatureStreamSource.ConvertLinearRing(polygon.outerBoundaryIs.LinearRing).Geometry as LineairRing, holes)));
        }
Exemplo n.º 20
0
 /// <summary>
 /// Converts a multilinestring to osm objects.
 /// </summary>
 /// <param name="multiLineString"></param>
 /// <returns></returns>
 private static Feature ConvertMultiLineString(OsmSharp.IO.Xml.Kml.v2_0.MultiLineString multiLineString)
 {
     return(new Feature(new MultiLineString(new LineString[] { KmlFeatureStreamSource.ConvertLineString(multiLineString.LineString).Geometry as LineString })));
 }
Exemplo n.º 21
0
 /// <summary>
 /// Converts a multipolygon into osm objects.
 /// </summary>
 /// <param name="multiPolygon"></param>
 /// <returns></returns>
 private static Feature ConvertMultiPolygon(OsmSharp.IO.Xml.Kml.v2_0.MultiPolygon multiPolygon)
 {
     return(new Feature(new MultiPolygon(new Polygon[] { KmlFeatureStreamSource.ConvertPolygon(multiPolygon.Polygon).Geometry as Polygon })));
 }
Exemplo n.º 22
0
        private static Feature ConvertPoint(OsmSharp.IO.Xml.Kml.v2_0_response.Point point)
        {
            Feature feature = new Feature((Geometry) new OsmSharp.Geo.Geometries.Point(KmlFeatureStreamSource.ConvertCoordinates(point.coordinates)[0]));

            if (point.altitudeModeSpecified)
            {
                feature.Attributes.Add("altitude", (object)point.altitudeMode);
            }
            if (point.extrudeSpecified)
            {
                feature.Attributes.Add("extrude", (object)point.extrude);
            }
            if (point.id != null)
            {
                feature.Attributes.Add("id", (object)point.id);
            }
            return(feature);
        }
Exemplo n.º 23
0
        public void KmlReadGeometryv2_1()
        {
            // initialize the geometry source.
            var kmlSource = new KmlFeatureStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.data.test.v2.1.kml"));

            // pull all the objects from the stream into the given collection.
            var kmlCollection = new FeatureCollection(kmlSource);
            var features = new List<Feature>(kmlCollection);

            // test collection contents.
            Assert.AreEqual(23, features.Count);
            Assert.IsInstanceOf(typeof(LineString), features[0].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[1].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[2].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[3].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[4].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[5].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[6].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[7].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[8].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[9].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[10].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[11].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[12].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[13].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[14].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[15].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[16].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[17].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[18].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[19].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[20].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[21].Geometry);
            Assert.IsInstanceOf(typeof(LineString), features[22].Geometry);
        }
Exemplo n.º 24
0
 private static Feature ConvertLinearRing(OsmSharp.IO.Xml.Kml.v2_0_response.LinearRing linearRing)
 {
     return(new Feature((Geometry) new LineairRing((IEnumerable <GeoCoordinate>)KmlFeatureStreamSource.ConvertCoordinates(linearRing.coordinates)))
     {
         Attributes =
         {
             {
                 "id",
                 (object)linearRing.id
             }
         }
     });
 }