public void GpxReadGeometryv1_0() { // initialize the geometry source. var gpxSource = new GpxFeatureStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.data.test.v1.0.gpx"), false); // pull all the objects from the stream into the given collection. var gpxCollection = new FeatureCollection(gpxSource); var features = new List<Feature>(gpxCollection); // test collection contents. Assert.AreEqual(1, features.Count); Assert.IsInstanceOf(typeof(LineString), features[0].Geometry); Assert.AreEqual(424, (features[0].Geometry as LineString).Coordinates.Count); }
/// <summary> /// Adds a new GPX. /// </summary> /// <param name="stream">Stream.</param> public GeoCoordinateBox AddGpx(Stream stream) { GeoCoordinateBox bounds = null; var gpxStream = new GpxFeatureStreamSource(stream); foreach (var feature in gpxStream) { if (feature.Geometry is Point) { // add the point. var point = (feature.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 (feature.Geometry is LineString) { // add the lineString. var lineString = (feature.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; }