Esempio n. 1
0
        private TrackEditModel InitEditModel(TrackEditData track)
        {
            // prepare edit model
            var model = new TrackEditModel();

            model.File  = new FileInfo(track.Source);
            model.Track = track;

            // build fake trail data
            var topoTrail = new TopoTrailInfo();
            var first     = track.Points.FirstOrDefault();
            var country   = Graffiti.Geo.NearestCountry(first);

            if (country != null)
            {
                topoTrail.Country = country;
                if (country.HasRegions)
                {
                    var region = Graffiti.Geo.NearestRegion(first);
                    if (region != null && topoTrail.Timezone == null)
                    {
                        topoTrail.Timezone = Graffiti.Geo.GuessTimezone(region);
                    }
                    topoTrail.Region = region;
                }
                if (topoTrail.Timezone == null)
                {
                    topoTrail.Timezone = Graffiti.Geo.GuessTimezone(country);
                }
            }
            if (topoTrail.Timezone == null)
            {
                topoTrail.Timezone = GeoTimezoneInfo.UTC;
            }

            // start and finish places
            var topoTrack = new TopoTrackInfo(topoTrail, track);

            topoTrack.StartPlace  = _cartoPlaceService.NearestPlace(topoTrack.StartPoint);
            topoTrack.FinishPlace = _cartoPlaceService.NearestPlace(topoTrack.FinishPoint);
            model.TopoTrack       = topoTrack;

            // discover additional places
            var bounds = GeoPerimeter.FromPoints(track.Points);

            model.NearbyPlaces    = _cartoPlaceService.ListPlacesContainingBounds(bounds);
            model.ContainedPlaces = _cartoPlaceService.ListPlacesContainedInBounds(bounds);

            // default filter values
            var filters = new TrackEditFilter();

            filters.MaximumDilution  = track.Points.Max(x => _trackEditService.GetMaxDOP(x));
            filters.MaximumVelocity  = track.Points.Max(x => x.Speed ?? 0);
            filters.MinimumSatellite = track.Points.Min(x => x.Sats ?? 0);
            model.Filters            = filters;

            return(model);
        }
        private OrthoTrackImportModel InitOrthoTrackImportModel(FileInfo file)
        {
            var model = new OrthoTrackImportModel();

            // init model
            model.File = file;

            // load raw file data
            model.Data = new GpxFileInfo(file.FullName);

            // match with existing trail
            var existing = _trailDataService.FindTrackSource_TODO(file.Name);

            model.Trail = existing?.Trail;

            // build trail preview
            var trail = new TopoTrailInfo();

            model.Preview = trail;

            // find intersecting places
            var points = model.Data.Tracks?.SelectMany(x => x.PointData);

            if (points != null)
            {
                var bounds = new GeoPerimeter(points.Select(x => new GeoPosition(x.Latitude, x.Longitude)));
                model.Places = _cartoPlaceService.ListPlacesContainingBounds(bounds).OrderBy(x => x.Bounds.Area).ToList();
                model.Nearby = _cartoPlaceService.ListPlacesContainedInBounds(bounds).OrderBy(x => x.Bounds.Area).ToList();
            }

            // set trail information
            var first = points?.FirstOrDefault();

            if (first != null)
            {
                trail.Country  = Graffiti.Geo.NearestCountry(first);
                trail.Region   = Graffiti.Geo.NearestRegion(first);
                trail.Timezone = Graffiti.Geo.GuessTimezone(trail.Country);
                //trail.StartLocal = trail.Timezone.FromUTC(first.Timestamp.Value);

                // discover all regions
                model.Regions = Graffiti.Geo.NearbyRegions(first);
                foreach (var region in Graffiti.Geo.NearbyRegions(points.Last()))
                {
                    if (!model.Regions.Any(x => x.RegionID == region.RegionID))
                    {
                        model.Regions.Add(region);
                    }
                }
            }

            // build track previews
            foreach (var t in model.Data.Tracks)
            {
                var track = new TopoTrackInfo(trail, t);

                var start = t.PointData.First();
                track.StartPlace = _cartoPlaceService.ListPlacesByContainingPoint(start).OrderBy(x => x.Bounds.Area).FirstOrDefault();

                var finish = t.PointData.Last();
                track.FinishPlace = _cartoPlaceService.ListPlacesByContainingPoint(finish).OrderBy(x => x.Bounds.Area).FirstOrDefault();

                trail.AddTrack_TODO_DEPRECATE(track);
            }

            return(model);
        }