Пример #1
0
        public void GpxReadGeometryv1_0()
        {
            // initialize the geometry source.
            GpxGeoStreamSource gpxSource = new GpxGeoStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test.v1.0.gpx"),
                false);

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

            // test collection contents.
            Assert.AreEqual(1, geometries.Count);
            Assert.IsInstanceOf(typeof(LineString), geometries[0]);
            Assert.AreEqual(424, (geometries[0] as LineString).Coordinates.Count);
        }
Пример #2
0
        /// <summary>
        /// Adds a new GPX.
        /// </summary>
        /// <param name="stream">Stream.</param>
        public GeoCoordinateBox AddGpx(Stream stream)
        {
            GeoCoordinateBox bounds = null;
            var gpxStream = new GpxGeoStreamSource(stream);
            foreach (var geometry in gpxStream)
            {
                if (geometry is Point)
                { // add the point.
                    var point = (geometry as Point);

                    // get x/y.
                    var x = _projection.LongitudeToX(point.Coordinate.Longitude);
                    var y = _projection.LatitudeToY(point.Coordinate.Latitude);

                    // set the default color if none is given.
                    var blue = SimpleColor.FromKnownColor(KnownColor.Blue);
                    var transparantBlue = SimpleColor.FromArgb(128,
                                                      blue.R, blue.G, blue.B);

                    uint pointId = _scene.AddPoint(x, y);
                    _scene.AddStylePoint(pointId, 0, float.MinValue, float.MaxValue, transparantBlue.Value, 8);

                    if (bounds == null)
                    { // create box.
                        bounds = point.Box;
                    }
                    else
                    { // add to the current box.
                        bounds = bounds + point.Box;
                    }
                }
                else if (geometry is LineString)
                { // add the lineString.
                    var lineString = (geometry as LineString);

                    // get x/y.
                    var x = new double[lineString.Coordinates.Count];
                    var y = new double[lineString.Coordinates.Count];
                    for (int idx = 0; idx < lineString.Coordinates.Count; idx++)
                    {
                        x[idx] = _projection.LongitudeToX(
                            lineString.Coordinates[idx].Longitude);
                        y[idx] = _projection.LatitudeToY(
                            lineString.Coordinates[idx].Latitude);
                    }

                    // set the default color if none is given.
                    var blue = SimpleColor.FromKnownColor(KnownColor.Blue);
                    var transparantBlue = SimpleColor.FromArgb(128,
                                                      blue.R, blue.G, blue.B);

                    uint? pointsId = _scene.AddPoints(x, y);
                    if (pointsId.HasValue)
                    {
                        _scene.AddStyleLine(pointsId.Value, 0, float.MinValue, float.MaxValue, transparantBlue.Value, 8, Renderer.Primitives.LineJoin.Round, null);

                        if (bounds == null)
                        { // create box.
                            bounds = lineString.Box;
                        }
                        else
                        { // add to the current box.
                            bounds = bounds + lineString.Box;
                        }
                    }
                }
            }

            // update envelope.
            if (_envelope == null)
            { // create initial envelope.
                _envelope = bounds;
            }
            if (bounds != null)
            {  // also include the current bounds.
                _envelope = _envelope + bounds;
            }

            return bounds;
        }
Пример #3
0
        /// <summary>
        /// Adds a new GPX.
        /// </summary>
        /// <param name="stream">Stream.</param>
        public GeoCoordinateBox AddGpx(Stream stream)
        {
            GeoCoordinateBox bounds = null;
            var gpxStream = new GpxGeoStreamSource(stream);
            foreach (var geometry in gpxStream)
            {
                if (geometry is Point)
                { // add the point.
                    var point = (geometry as Point);

                    // get x/y.
                    var x = _projection.LongitudeToX(point.Coordinate.Longitude);
                    var y = _projection.LatitudeToY(point.Coordinate.Latitude);

                    // set the default color if none is given.
                    SimpleColor blue = SimpleColor.FromKnownColor(KnownColor.Blue);
                    SimpleColor transparantBlue = SimpleColor.FromArgb(128,
                                                                       blue.R, blue.G, blue.B);

                    this.Scene.AddPoint(float.MinValue, float.MaxValue, x, y,
                                       transparantBlue.Value, 8);

                    if (bounds == null)
                    { // create box.
                        bounds = point.Box;
                    }
                    else
                    { // add to the current box.
                        bounds = bounds + point.Box;
                    }
                }
                else if (geometry is LineString)
                { // add the lineString.
                    var lineString = (geometry as LineString);

                    // get x/y.
                    var x = new double[lineString.Coordinates.Count];
                    var y = new double[lineString.Coordinates.Count];
                    for (int idx = 0; idx < lineString.Coordinates.Count; idx++)
                    {
                        x[idx] = _projection.LongitudeToX(
                            lineString.Coordinates[idx].Longitude);
                        y[idx] = _projection.LatitudeToY(
                            lineString.Coordinates[idx].Latitude);
                    }

                    // set the default color if none is given.
                    SimpleColor blue = SimpleColor.FromKnownColor(KnownColor.Blue);
                    SimpleColor transparantBlue = SimpleColor.FromArgb(128,
                                                                       blue.R, blue.G, blue.B);

                    this.Scene.AddLine(float.MinValue, float.MaxValue, x, y,
                                       transparantBlue.Value, 8);

                    if (bounds == null)
                    { // create box.
                        bounds = lineString.Box;
                    }
                    else
                    { // add to the current box.
                        bounds = bounds + lineString.Box;
                    }
                }
            }
            return bounds;
        }