private static bool TryReadTrack(RavenJObject geo, LineString lineString, out object result) { var times = geo["times"] as RavenJArray; if (times != null) { var times2 = times.OfType<RavenJArray>().ToList(); var track = new Track(); ReadMetadata(geo, track.Metadata); var fixCount = 0; foreach (var ti in times2) { var tt = ti.OfType<RavenJValue>().Where(x => x.Type == JTokenType.String).Select(x => DateTime.Parse((string)x.Value)).ToList(); var segment = new TrackSegment(); for (var i = 0; i < tt.Count; i++) { if (fixCount + 1 > lineString.Coordinates.Count) break; var coord2D = lineString.Coordinates[fixCount]; var coord3D = coord2D as Is3D; if (coord3D == null) segment.Fixes.Add(new Fix(coord2D.Latitude, coord2D.Longitude, tt[i])); else segment.Fixes.Add(new Fix(coord2D.Latitude, coord2D.Longitude, coord3D.Elevation, tt[i])); fixCount++; } track.Segments.Add(segment); } if (fixCount == lineString.Coordinates.Count) { result = track; return true; } } result = default(object); return false; }
public void Track() { Func<Track> geometry = () => { var track = new Track(); track.Metadata.Attribute(x => x.Name, "test"); var segment = new TrackSegment(); segment.Fixes.Add(new Fix(56.543, 32.657, new DateTime(2013, 1, 1))); segment.Fixes.Add(new Fix(23.463, 23.343, new DateTime(2013, 1, 1, 1, 0, 0))); track.Segments.Add(segment); return track; }; Assertion(geometry, track => track.ToLineString()); Assertion(geometry, track => track.GetAllFixes().First()); Assertion(geometry, track => track.GetAllFixes().Last()); Assertion(geometry, track => track.Metadata.Attribute(x => x.Name)); }