public async Task <IActionResult> PutGpsTrace(string id, [FromBody] GpxFile trace) { var gateway = _httpGatewayFactory.CreateOsmGateway(_cache.Get(User.Identity.Name)); await gateway.UpdateTrace(trace); return(Ok()); }
public GpxFile ApplyFilters(GpxFile inputFile) { foreach (IFileFilter filter in filters) inputFile = filter.ApplyFilter(inputFile); return inputFile; }
///<inheritdoc /> public GpxFile ToGpx(FeatureCollection collection) { var gpx = new GpxFile { Metadata = new GpxMetadata(collection.FirstOrDefault(f => f.Attributes.Exists(CREATOR)) ?.Attributes[CREATOR]?.ToString() ?? GpxDataContainerConverter.ISRAEL_HIKING_MAP + "_geojson") }; gpx.Waypoints.AddRange(collection.Where(f => f.Geometry is Point) .Select(CreateWaypoint) .Union(collection.Where(f => f.Geometry is MultiPoint) .SelectMany(CreateWayPointsFromMultiPoint)) .ToList()); gpx.Routes.AddRange(collection.Where(f => f.Geometry is LineString) .Select(CreateRouteFromLineString) .Union(collection.Where(f => f.Geometry is Polygon).Select(CreateRouteFromPolygon)) .Union(collection.Where(f => f.Geometry is MultiPolygon) .SelectMany(CreateRoutesFromMultiPolygon)) .ToList()); gpx.Tracks.AddRange(collection.Where(f => f.Geometry is MultiLineString) .SelectMany(CreateTracksFromMultiLineString) .ToList()); gpx.UpdateBounds(); return(gpx); }
public void PostGpsTrace_UrlProvidedForTrackGpxFile_ShouldReturnFeatureCollection() { var gpx = new GpxFile(); gpx.Routes.Add( new GpxRoute().WithWaypoints(new[] { new GpxWaypoint(new GpxLongitude(0), new GpxLatitude(0)).WithTimestampUtc( DateTime.Now.ToUniversalTime()), new GpxWaypoint(new GpxLongitude(0.01), new GpxLatitude(0.01)).WithTimestampUtc(DateTime.Now .AddMinutes(1).ToUniversalTime()) }) ); var url = SetupGpxUrl(gpx); _controller.SetupIdentity(_cache); var results = _controller.PostFindUnmappedPartsFromGpsTrace(url).Result as OkObjectResult; Assert.IsNotNull(results); var featureCollection = results.Value as FeatureCollection; Assert.IsNotNull(featureCollection); Assert.AreEqual(1, featureCollection.Count); Assert.IsTrue(featureCollection.First().Attributes.GetValues().Contains("track")); }
public static List <GpsRoute> ConvertToRoutes(GpxFile gpxFile) { List <GpsRoute> gpsRoutes = new List <GpsRoute>(); if (gpxFile == null) { return(gpsRoutes); } foreach (GpxRouteNode route in gpxFile.RootNode.Routes) { // Add a new Route gpsRoutes.Add(new GpsRoute()); gpsRoutes.Last().Name = route.Name; gpsRoutes.Last().Points = new List <GpsRoutePoint>(); foreach (GpxRoutePointNode pointNode in route.RoutePoints) { // Add a new Route Point gpsRoutes.Last().Points.Add(new GpsRoutePoint(pointNode.Position)); gpsRoutes.Last().Points.Last().Comment = pointNode.Comment; gpsRoutes.Last().Points.Last().Description = pointNode.Description; gpsRoutes.Last().Points.Last().Name = pointNode.Name; gpsRoutes.Last().Points.Last().Source = pointNode.Source; } } return(gpsRoutes); }
public GpxFileRepositoryNodeFile(GpxFile gpxFile, FileOrDirectoryPath filePath) { this.FilePath = filePath; _gpxFile = new LoadedGpxFile(gpxFile); this.InitializeProperties(); }
static int TaskWorker4Info(GpxFile gpx, GpxInfos[] infos, int idx, CancellationTokenSource cancel, IProgress <string> progress) { TaskProgress4Info(string.Format("ermittle Infos zu {0} ...", gpx.Filename)); infos[idx] = new GpxInfos(gpx); TaskProgress4Info(string.Format("Infos zu {0} ermittelt", gpx.Filename)); return(0); }
private static int WriteToGpx(GpxInputData gpxData, string path) { var f = new GpxFile(); f.Tracks.Add(gpxData.gpxTrack); var writerSettings = new XmlWriterSettings { Encoding = Encoding.UTF8 }; if (path != null) { path = Path.Combine(path, gpxData.filename); } else { path = gpxData.filename; } using (var wr = XmlWriter.Create(path, writerSettings)) { f.WriteTo(wr, new GpxWriterSettings()); Console.WriteLine(path + " written..."); } // byte[] expected = File.ReadAllBytes (path); // note that this is not a guarantee in the general case. the inputs here have all been // slightly tweaked such that it should succeed for our purposes. // Assert.False (diff.HasDifferences (), string.Join (Environment.NewLine, diff.Differences)); return(0); }
public void ConvertGpxToDataContainer_NonSiteFile_ShouldManipulateRouteData() { var gpx = new GpxFile(); gpx.Tracks.Add(new GpxTrack().WithName("track").WithSegments( new[] { new GpxTrackSegment(new ImmutableGpxWaypointTable(new[] { new GpxWaypoint(new GpxLongitude(1), new GpxLatitude(1), null), new GpxWaypoint(new GpxLongitude(1), new GpxLatitude(1.000001), null), new GpxWaypoint(new GpxLongitude(1), new GpxLatitude(1.000002), null), new GpxWaypoint(new GpxLongitude(1), new GpxLatitude(1.000003), null), }), null) }.ToImmutableArray())); var newRouteData = new RouteData { Segments = new List <RouteSegmentData> { new RouteSegmentData(), new RouteSegmentData() } }; _routeDataSplitterService.Split(Arg.Any <RouteData>()).Returns(newRouteData); var dataContainer = _converterService.ToDataContainer(gpx.ToBytes(), FlowFormats.GPX).Result; Assert.AreEqual(1, dataContainer.Routes.Count); Assert.AreEqual(newRouteData.Segments.Count, dataContainer.Routes.First().Segments.Count); }
///<inheritdoc /> public DataContainer ToDataContainer(GpxFile gpx) { gpx = gpx.UpdateBounds(); var container = new DataContainer { Routes = ConvertRoutesToRoutesData(gpx.Routes ?? new List <GpxRoute>()) }; container.Routes.AddRange(ConvertTracksToRouteData(gpx.Tracks ?? new List <GpxTrack>())); var nonEmptyWayPoints = gpx.Waypoints ?? new List <GpxWaypoint>(); var markers = nonEmptyWayPoints.Select(ToMarkerData).ToList(); if (markers.Any()) { if (!container.Routes.Any()) { var title = string.IsNullOrWhiteSpace(markers.First().Title) ? "Markers" : markers.First().Title; var name = markers.Count == 1 ? title : "Markers"; container.Routes.Add(new RouteData { Name = name, Description = nonEmptyWayPoints.First().Description }); } container.Routes.First().Markers = markers; } if (gpx.Metadata?.Bounds != null) { UpdateBoundingBox(container, gpx.Metadata.Bounds); } return(container); }
public void Add(GpxFile gpxFile) { if (gpxFile != null && gpxFile.RootNode != null && gpxFile.RootNode.Tracks.Count > 0) { // Loop through each Track foreach (GpxTrackNode gpxTrackNode in gpxFile.RootNode.Tracks) { // Loop through each Segment foreach (GpxSegmentNode gpxSegmentNode in gpxTrackNode.Segments) { // Loop through each Point foreach (GpxPointNode pointNode in gpxSegmentNode.Points) { GpsPosition newCoordinate = new GpsPosition(); newCoordinate.Time = pointNode.Time; newCoordinate.Latitude.Numeric = pointNode.Lat; newCoordinate.Longitude.Numeric = pointNode.Lon; newCoordinate.Altitude = pointNode.Ele; // Use the tracks data or the parameter override newCoordinate.Source = string.IsNullOrEmpty(this.GpsTrackSource) ? gpxFile.RootNode.Creator : this.GpsTrackSource; // Add the point to the cache this.TrackPoints.Add(newCoordinate); } } } // ReOptimise the Track this.OptimiseTrack(); } }
/// <summary> /// Updates the bounds of a <see cref="GpxFile"/> object according to internal data /// </summary> /// <param name="gpx">The <see cref="GpxFile"/></param> /// <returns>An updated <see cref="GpxFile"/></returns> public static GpxFile UpdateBounds(this GpxFile gpx) { if (gpx.Metadata?.Bounds != null && gpx.Metadata.Bounds.MinLatitude.Value != 0.0 && gpx.Metadata.Bounds.MaxLatitude.Value != 0.0 && gpx.Metadata.Bounds.MinLongitude.Value != 0.0 && gpx.Metadata.Bounds.MaxLongitude.Value != 0.0) { return(gpx); } var points = (gpx.Routes ?? new List <GpxRoute>()).Where(r => r.Waypoints != null).SelectMany(r => r.Waypoints).ToArray(); points = points.Concat(gpx.Waypoints ?? new List <GpxWaypoint>()).ToArray(); points = points.Concat((gpx.Tracks ?? new List <GpxTrack>()).Where(r => r.Segments != null).SelectMany(t => t.Segments).SelectMany(s => s.Waypoints)).ToArray(); if (!points.Any()) { return(gpx); } var boundingBox = new GpxBoundingBox( minLatitude: new GpxLatitude(points.Min(p => p.Latitude.Value)), maxLatitude: new GpxLatitude(points.Max(p => p.Latitude.Value)), minLongitude: new GpxLongitude(points.Min(p => p.Longitude.Value)), maxLongitude: new GpxLongitude(points.Max(p => p.Longitude.Value)) ); gpx.Metadata = gpx.Metadata == null ? new GpxMetadata(null, null, null, null, null, ImmutableArray <GpxWebLink> .Empty, null, null, boundingBox, null) : new GpxMetadata(gpx.Metadata.Creator, gpx.Metadata.Name, gpx.Metadata.Description, gpx.Metadata.Author, gpx.Metadata.Copyright, gpx.Metadata.Links, gpx.Metadata.CreationTimeUtc, gpx.Metadata.Keywords, boundingBox, gpx.Metadata.Extensions); return(gpx); }
private void mapUpdate(object sender, RoutedEventArgs e) { List <GpxFile> tmpGpxList = new List <GpxFile>(); foreach (GpxFile elementFileList in traceListView.ItemsSource) { if (!elementFileList.Check && elementFileList.InMap) { mapControl.Children.Remove(polylineList[elementFileList.NumberPolyline]); elementFileList.InMap = false; var lvitem = traceListView.ItemContainerGenerator.ContainerFromItem(elementFileList) as ListViewItem; lvitem.Foreground = new SolidColorBrush(Colors.Black); lvitem.BorderBrush = null; } else if (elementFileList.Check && !elementFileList.InMap) { if (elementFileList.Track) { GpxFile.trackGPXfile_API_1(elementFileList, polylineList, mapControl); elementFileList.InMap = true; } if (elementFileList.Route) { GpxFile.routesGPXfile_API_1(elementFileList, polylineList, mapControl); elementFileList.InMap = true; } var lvitem = traceListView.ItemContainerGenerator.ContainerFromItem(elementFileList) as ListViewItem; lvitem.Foreground = elementFileList.color; lvitem.BorderBrush = elementFileList.color; lvitem.BorderThickness = new Thickness(5, 5, 5, 5); } } }
public void CovertTwoWays_OnlyOneTrack_ShouldBeTheSame() { var gpx = new GpxFile(); gpx.Tracks.Add(new GpxTrack().WithName("track").WithSegments( new[] { new GpxTrackSegment(new ImmutableGpxWaypointTable(new[] { new GpxWaypoint(new GpxLongitude(1), new GpxLatitude(2), 3), new GpxWaypoint(new GpxLongitude(4), new GpxLatitude(5), 6) }), null), new GpxTrackSegment(new ImmutableGpxWaypointTable(new[] { new GpxWaypoint(new GpxLongitude(4), new GpxLatitude(5), 6), new GpxWaypoint(new GpxLongitude(14), new GpxLatitude(15), null) }), null) }.ToImmutableArray())); var featureCollection = _gpxGeoJsonConverter.ToGeoJson(gpx); var newGpx = _gpxGeoJsonConverter.ToGpx(featureCollection); Assert.AreEqual(gpx.Tracks.Count, newGpx.Tracks.Count); Assert.AreEqual(gpx.Tracks[0].Name, newGpx.Tracks[0].Name); for (int i = 0; i < newGpx.Tracks[0].Segments.Length; i++) { for (int j = 0; j < newGpx.Tracks[0].Segments[i].Waypoints.Count; j++) { Assert.AreEqual(gpx.Tracks[0].Segments[i].Waypoints[j].ElevationInMeters, newGpx.Tracks[0].Segments[i].Waypoints[j].ElevationInMeters); Assert.AreEqual(gpx.Tracks[0].Segments[i].Waypoints[j].Latitude.Value, newGpx.Tracks[0].Segments[i].Waypoints[j].Latitude.Value); Assert.AreEqual(gpx.Tracks[0].Segments[i].Waypoints[j].Longitude.Value, newGpx.Tracks[0].Segments[i].Waypoints[j].Longitude.Value); } } }
///<inheritdoc /> public FeatureCollection ToGeoJson(GpxFile gpx) { var collection = new FeatureCollection(); var points = gpx.Waypoints ?? new List <GpxWaypoint>(); var pointsFeatures = points.Select(point => new Feature(new Point(CreateGeoPosition(point)), CreateProperties(point.Name, point.Description))); pointsFeatures.ToList().ForEach(f => collection.Add(f)); var routes = gpx.Routes ?? new List <GpxRoute>(); var routesFeatures = routes.Select(route => new Feature(new LineString(route.Waypoints.Select(CreateGeoPosition).ToArray()), CreateProperties(route.Name, route.Description))); routesFeatures.ToList().ForEach(f => collection.Add(f)); foreach (var track in gpx.Tracks ?? new List <GpxTrack>()) { if (track.Segments.Length == 1) { var lineStringFeature = new Feature(new LineString(track.Segments[0].Waypoints.Select(CreateGeoPosition).ToArray()), CreateProperties(track.Name, track.Description)); collection.Add(lineStringFeature); continue; } var lineStringList = track.Segments.Select(segment => new LineString(segment.Waypoints.Select(CreateGeoPosition).ToArray()) as LineString).ToArray(); var feature = new Feature(new MultiLineString(lineStringList), CreateMultiLineProperties(track.Name, gpx.Metadata.Creator, track.Description)); collection.Add(feature); } return(collection); }
public void ReadGpxData(GpxFile gpxFile, Stream stream) { XmlSerializer serializer = new XmlSerializer (typeof (gpx)); gpx gpx = (gpx)serializer.Deserialize (stream); if (gpx.trk != null) { foreach (gpxTrk trkType in gpx.trk) { Track track = new Track (); foreach (gpxTrkTrkseg trkseg in trkType.trkseg) { if (trkseg.trkpt.Length > 0) { TrackSegment segment = new TrackSegment (); foreach (gpxTrkTrksegTrkpt trkpt in trkseg.trkpt) { TrackPoint waypoint = ReadTrackPoint (trkpt); segment.AddPoint (waypoint); } track.AddSegment (segment); } } gpxFile.AddTrack (track); } } if (gpx.wpt != null) { foreach (gpxWpt wptType in gpx.wpt) { TrackPoint waypoint = ReadWayoint(wptType); gpxFile.AddWaypoint (waypoint); } } if (gpx.rte != null) { foreach (gpxRte rteType in gpx.rte) { Track route = new Track (); if (rteType.rtept != null) { TrackSegment segment = new TrackSegment (); foreach (gpxRteRtept wptType in rteType.rtept) { TrackPoint waypoint = ReadRoutePoint (wptType); segment.AddPoint (waypoint); } } gpxFile.AddRoute (route); } } }
public void ToDataContainer_NoData_ShouldReturnEmptyDataContainer() { var gpx = new GpxFile(); var dataContainer = _converter.ToDataContainer(gpx); Assert.AreEqual(0, dataContainer.Routes.Count); }
protected static GpxFile CreateGpxFileCopy(GpxFile file) { GpxFile copy = new GpxFile(); copy.Creator = file.Creator; copy.Metadata = file.Metadata; return(copy); }
public static void Import(string aKey, string aPath, AddEntryCallback aCallback) { GpxFile file = GpxFile.Load(aPath); if (file != null) { Import(aKey, file, aCallback); } }
public GpxFile ApplyFilters(GpxFile inputFile) { foreach (IFileFilter filter in filters) { inputFile = filter.ApplyFilter(inputFile); } return(inputFile); }
public void ToDataContainer_RouteWithoutPoints_ShouldReturnRouteWithoutPointsDataContainer() { var gpx = new GpxFile(); gpx.Tracks.Add(new GpxTrack()); var dataContainer = _converter.ToDataContainer(gpx); Assert.AreEqual(0, dataContainer.Routes.Count); }
public SegmentInfo(GpxFile gpx, int trackno, int segmentno) { Length = GetLengthAndMinMaxHeight(gpx.GetTrackSegmentPointList(trackno, segmentno, false), out Minheight, out Maxheight, out Descent, out Ascent, out AverageSpeed); PointCount = gpx.TrackSegmentPointCount(trackno, segmentno); }
public TrackInfo(GpxFile gpx, int trackno) { Trackname = gpx.GetTrackname(trackno); SegmentCount = gpx.TrackSegmentCount(trackno); Segment = new List <SegmentInfo>(); for (int i = 0; i < SegmentCount; i++) { Segment.Add(new SegmentInfo(gpx, trackno, i)); } }
static int TaskWorker4Read(string filename, int idx, CancellationTokenSource cancel, IProgress <string> progress) { gpxfiles[idx] = new GpxFile(filename) { InternalGpx = GpxFile.InternalGpxForm.OnlyPoorGpx // GpxFile.InternalGpxForm.NormalAndPoor; }; TaskProgress4Read(string.Format("lese {0} ...", filename)); gpxfiles[idx].Read(); return(0); }
/// <inheritdoc /> public async Task UpdateTrace(GpxFile trace) { var address = BaseAddress + $"0.6/gpx/{trace.Id}"; var osm = new Osm { GpxFiles = new[] { trace } }; var content = new StringContent(osm.SerializeToXml()); await SendAuthRequest(HttpMethod.Put, address, content); }
public void ConvertGpxToDataContainer_NonSiteFileNoPointsInTrack_ShouldManipulateRouteData() { var gpx = new GpxFile(); gpx.Routes.Add(new GpxRoute()); var dataContainer = _converterService.ToDataContainer(gpx.ToBytes(), FlowFormats.GPX).Result; Assert.AreEqual(0, dataContainer.Routes.Count); }
public void ToDataContainer_PointsOlny_ShouldReturnRouteWithoutPointsOnlyDataContainer() { var gpx = new GpxFile(); gpx.Waypoints.Add(new GpxWaypoint(new GpxLongitude(5), new GpxLatitude(4), 6)); var dataContainer = _converter.ToDataContainer(gpx); Assert.AreEqual(1, dataContainer.Routes.Count); Assert.AreEqual(0, dataContainer.Routes.First().Segments.Count); Assert.AreEqual(1, dataContainer.Routes.First().Markers.Count); }
public void ConvertGpxToDataContainer_NonSiteFileWithType_ShouldRemoveType() { var gpx = new GpxFile(); gpx.Routes.Add(new GpxRoute()); gpx.Waypoints.Add(new GpxWaypoint(new Coordinate(0, 0)).WithClassification("Generic")); var dataContainer = _converterService.ToDataContainer(gpx.ToBytes(), FlowFormats.GPX).Result; Assert.AreEqual(string.Empty, dataContainer.Routes[0].Markers[0].Type); }
/// <inheritdoc /> protected override async ValueTask SaveThisNodesContentsAsync() { if (_gpxFile == null) { return; } await Task.Factory.StartNew( () => GpxFile.Serialize(_gpxFile.RawGpxFile, this.FilePath.Path)); _gpxFile.ContentsChanged = false; }
public void ToDataContainer_RouteWithPoints_ShouldReturnRouteWithPointsDataContainer() { var gpx = new GpxFile(); gpx.Waypoints.Add(new GpxWaypoint(new GpxLongitude(5), new GpxLatitude(4), 6)); gpx.Routes.Add(new GpxRoute().WithWaypoints(new[] { new GpxWaypoint(new GpxLongitude(1), new GpxLatitude(2), 3) })); var dataContainer = _converter.ToDataContainer(gpx); Assert.AreEqual(1, dataContainer.Routes.Count); Assert.AreEqual(1, dataContainer.Routes.First().Markers.Count); }
void LoadGPX(string path) { try { var file = GpxFile.ReadFrom(XmlReader.Create(path), null); textBoxDesc.Text = file.Metadata.Description; if (DateTime.TryParse(file.Metadata.Name, out DateTime dt)) { dateTimePicker1.Value = dt; } var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326); double fullDist = 0; GpxWaypoint prev_wp = null; TimeSpan timeSpan = new TimeSpan(); TimeSpan timeSpanMove = new TimeSpan(); foreach (var track in file.Tracks) { foreach (var seg in track.Segments) { foreach (var wp in seg.Waypoints) { if (prev_wp != null) { var distance = gps2m(wp.Latitude.Value, wp.Longitude.Value, prev_wp.Latitude.Value, prev_wp.Longitude.Value); //var distance = point.Distance(prevPoint); fullDist += distance; if (wp.TimestampUtc.HasValue && prev_wp.TimestampUtc.HasValue) { timeSpan = timeSpan.Add(wp.TimestampUtc.Value - prev_wp.TimestampUtc.Value); if (distance > 1e-06) { timeSpanMove = timeSpan.Add(wp.TimestampUtc.Value - prev_wp.TimestampUtc.Value); } } } prev_wp = wp; } } } numericUpDownHours.Value = timeSpan.Hours; numericUpDownMinutes.Value = timeSpan.Minutes; numericUpDownDistance.Value = (decimal)(0.001 * fullDist); currentTrackPath = path; } catch (Exception ex) { MessageBox.Show($"Load treck error:\n{ex.Message}"); } }
public void PostGpsTrace_UrlProvidedForSemiEmptyGpxFile_ShouldReturnEmptyFeatureCollection() { var gpx = new GpxFile(); gpx.Tracks.Add(new GpxTrack()); var url = SetupGpxUrl(gpx, new List <LineString>()); _controller.SetupIdentity(_cache); var results = _controller.PostFindUnmappedPartsFromGpsTrace(url).Result as BadRequestObjectResult; Assert.IsNotNull(results); }
public static void Import(string aKey, GpxFile aFile, AddEntryCallback aCallback) { if (aFile != null) { // apply some basic filtering of loaded GPX data FileFilterChain filterChain = new FileFilterChain(); filterChain.Filters.Add(new RemoveErrorPointsFilter()); aFile = filterChain.ApplyFilters(aFile); // convert to LogEntry. int idx = 0; foreach (Track track in aFile.Tracks) { if (track.Segments.Count > 0) { TrackSegment firstSeg = track.Segments[0]; string key = string.Format("{0}/{1}[{2}]", aKey, track.Name, idx); DateTime time = (DateTime)firstSeg.StartTime; LogEntry entry = new LogEntry(key, time, firstSeg.PointsCount); foreach (TrackSegment seg in track.Segments) { foreach (TrackPoint pnt in seg.Points) { Record rec = new Record(); rec.Location = new PointLatLng(pnt.Location.Y, pnt.Location.X); if (pnt.Time != null) { rec.Time = (DateTime)pnt.Time; } if (pnt.Elevation != null) { rec.Altitude = (float)pnt.Elevation; } entry.Records.Add(rec); } } CalculateMissingData(entry); aCallback(key, entry); idx++; } } } }
public void WriteGpxData(GpxFile gpxFile, string fileName) { throw new System.NotImplementedException(); }