Пример #1
0
        // ***********************************************************************************************************************
        // GET TRACKRESULT
        // ***********************************************************************************************************************
        public TrackResult GetTrackResult(int id)
        {
            try
            {
                var cd = SetGetMemoryCache();

                TrackResult tr = new Models.TrackResult();
                foreach (CachedDataClass.Track.Feature f in cd.track.features)
                {
                    if (f.properties.SERIAL_NO == id.ToString())
                    {
                        tr.result.id          = id.ToString();
                        tr.result.name        = f.properties.NAME;
                        tr.result.description = f.properties.originalComments;
                        foreach (string s in f.trackFeatures)
                        {
                            if (!tr.result.features.Contains(s))
                            {
                                tr.result.features.Add(s);
                            }
                        }
                        tr.result.accessDescription = f.properties.ACCESS_DSC;


                        //get bounding box
                        double neLng = -9999999999;
                        double swLng = 9999999999;
                        double neLat = -9999999999;
                        double swLat = 9999999999;

                        bool firstpoint = false;

                        double x = 0;
                        double y = 0;
                        if (f.geometry.type == "MultiLineString")
                        {
                            foreach (List <object> g in f.geometry.coordinates)
                            {
                                foreach (object o in g)
                                {
                                    Newtonsoft.Json.Linq.JArray h = (Newtonsoft.Json.Linq.JArray)o;
                                    x = (double)h[0];
                                    y = (double)h[1];
                                    if (x > neLng)
                                    {
                                        neLng = x;
                                    }
                                    if (x < swLng)
                                    {
                                        swLng = x;
                                    }
                                    if (y > neLat)
                                    {
                                        neLat = y;
                                    }
                                    if (y < swLat)
                                    {
                                        swLat = y;
                                    }

                                    if (!firstpoint)
                                    {
                                        tr.result.startLocation           = new TrackResult.Location();
                                        tr.result.startLocation.latitude  = y;
                                        tr.result.startLocation.longitude = x;
                                        firstpoint = true;
                                    }
                                }

                                tr.result.endLocation           = new TrackResult.Location();
                                tr.result.endLocation.latitude  = y;
                                tr.result.endLocation.longitude = x;
                            }
                        }
                        if (f.geometry.type == "LineString")
                        {
                            foreach (List <object> h in f.geometry.coordinates)
                            {
                                x = (double)h[0];
                                y = (double)h[1];
                                if (x > neLng)
                                {
                                    neLng = x;
                                }
                                if (x < swLng)
                                {
                                    swLng = x;
                                }
                                if (y > neLat)
                                {
                                    neLat = y;
                                }
                                if (y < swLat)
                                {
                                    swLat = y;
                                }

                                if (!firstpoint)
                                {
                                    tr.result.startLocation           = new TrackResult.Location();
                                    tr.result.startLocation.latitude  = y;
                                    tr.result.startLocation.longitude = x;
                                    firstpoint = true;
                                }
                            }

                            tr.result.endLocation           = new TrackResult.Location();
                            tr.result.endLocation.latitude  = y;
                            tr.result.endLocation.longitude = x;
                        }
                        if (neLng != 9999999999)
                        {
                            tr.result.boundingBox.neLat = neLat;
                            tr.result.boundingBox.neLng = neLng;
                            tr.result.boundingBox.swLat = swLat;
                            tr.result.boundingBox.swLng = swLng;
                        }


                        /*
                         * foreach (List<List<double>> g in f.geometry.coordinates)
                         * {
                         *  foreach (List<double> h in g)
                         *  {
                         *      double x = h[0];
                         *      double y = h[1];
                         *      if (x > neLng) neLng = x;
                         *      if (x < swLng) swLng = x;
                         *      if (y > neLat) neLat = y;
                         *      if (y < swLat) swLat = y;
                         *
                         *      if(!firstpoint)
                         *      {
                         *          tr.result.location = new TrackResult.Location();
                         *          tr.result.location.latitude = y;
                         *          tr.result.location.longitude = x;
                         *          firstpoint = true;
                         *      }
                         *  }
                         *
                         *  if (neLng != 9999999999)
                         *  {
                         *      tr.result.boundingBox.neLat = neLat;
                         *      tr.result.boundingBox.neLng = neLng;
                         *      tr.result.boundingBox.swLat = swLat;
                         *      tr.result.boundingBox.swLng = swLng;
                         *  }
                         * }
                         */


                        //get activities
                        foreach (CachedDataClass.Track.Activity trAct in f.activities)
                        {
                            TrackResult.Activity a = new TrackResult.Activity();
                            a.activityType = trAct.activityType;
                            a.comment      = trAct.comment;
                            a.gradeComment = trAct.grade_comment;
                            //scott 20112017
                            a.grade           = trAct.grade;
                            a.distance        = trAct.distance;
                            a.duration        = trAct.duration;
                            a.durationMeasure = trAct.duration_measure;
                            tr.result.activities.Add(a);
                        }


                        tr.result.qualities.trackClass = f.qualities.track_class;
                        tr.result.qualities.quality    = f.qualities.quality;
                        tr.result.qualities.markings   = f.qualities.markings;

                        foreach (int pid in f.photos)
                        {
                            string p = getImageString(pid);
                            tr.result.images.Add(p);
                        }

                        tr.result.closure.description = f.properties.CLOS_DESC;
                        tr.result.closure.closureDate = ncdatestr(f.properties.CLOS_START);
                        tr.result.closure.openDate    = ncdatestr(f.properties.CLOS_OPEN);
                        tr.result.closure.reason      = f.properties.CLOS_REAS;
                        tr.result.closure.status      = f.properties.CLOS_STAT;

                        tr.meta.links.self = _appsettings.BaseURL + "/tracks/" + id.ToString();


                        if (tr.result.features.Count == 0)
                        {
                            tr.result.features = null;
                        }
                        if (tr.result.activities.Count == 0)
                        {
                            tr.result.activities = null;
                        }
                        if (tr.result.images.Count == 0)
                        {
                            tr.result.images = null;
                        }
                        break;
                    }
                }


                /*
                 * if(String.IsNullOrEmpty(tr.result.description))
                 * {
                 *  foreach(TrackResult.Activity a  in tr.result.activities)
                 *  {
                 *      if(a.comment != null && String.IsNullOrEmpty(a.comment.ToString()))
                 *      {
                 *          tr.result.description = a.comment.ToString();
                 *          break;
                 *      }
                 *  }
                 * }
                 */

                return(tr);
                //JsonResult jsonresult = new JsonResult(tr);
                //return jsonresult;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        public JsonResult GetTrack(int id)
        {
            try
            {
                TrackResult tr = new Models.TrackResult();
                tr = GetTrackResult(id);

                /*
                 *
                 * var cd = SetGetMemoryCache();
                 *
                 * TrackResult tr = new Models.TrackResult();
                 * foreach (CachedDataClass.Track.Feature f in cd.track.features)
                 * {
                 *  if (f.properties.SERIAL_NO == id.ToString())
                 *  {
                 *      tr.result.id = id.ToString();
                 *      tr.result.name = f.properties.NAME;
                 *      tr.result.description = f.properties.COMMENTS;
                 *      foreach (string s in f.trackFeatures)
                 *      {
                 *          if(!tr.result.features.Contains(s))  tr.result.features.Add(s);
                 *      }
                 *
                 *
                 *      //get bounding box
                 *      double neLng = -9999999999;
                 *      double swLng = 9999999999;
                 *      double neLat = -9999999999;
                 *      double swLat = 9999999999;
                 *
                 *      foreach (List<List<double>> g in f.geometry.coordinates)
                 *      {
                 *          foreach (List<double> h in g)
                 *          {
                 *              double x = h[0];
                 *              double y = h[1];
                 *              if (x > neLng) neLng = x;
                 *              if (x < swLng) swLng = x;
                 *              if (y > neLat) neLat = y;
                 *              if (y < swLat) swLat = y;
                 *          }
                 *
                 *          if (neLng != 9999999999)
                 *          {
                 *              tr.result.boundingBox.neLat = neLat;
                 *              tr.result.boundingBox.neLng = neLng;
                 *              tr.result.boundingBox.swLat = swLat;
                 *              tr.result.boundingBox.swLng = swLng;
                 *          }
                 *      }
                 *
                 *
                 *      //get activities
                 *      foreach(CachedDataClass.Track.Activity trAct in f.activities)
                 *      {
                 *          TrackResult.Activity a = new TrackResult.Activity();
                 *          a.activityType = trAct.activityType;
                 *          a.comment = trAct.comment;
                 *          a.gradeComment = trAct.grade_comment;
                 *          a.grade = trAct.grade;
                 *          a.distance = trAct.distance;
                 *          a.duration = trAct.duration;
                 *          a.durationMeasure = trAct.duration_measure;
                 *          tr.result.activities.Add(a);
                 *      }
                 *
                 *
                 *      tr.result.qualities.trackClass = f.qualities.track_class;
                 *      tr.result.qualities.quality = f.qualities.quality;
                 *      tr.result.qualities.markings = f.qualities.markings;
                 *
                 *      foreach(int pid in f.photos)
                 *      {
                 *          string p = getImageString(pid);
                 *          tr.result.images.Add(p);
                 *      }
                 *
                 *      tr.result.closure.description = f.properties.CLOS_DESC;
                 *      tr.result.closure.closureDate = ncdatestr(f.properties.CLOS_START);
                 *      tr.result.closure.openDate = ncdatestr(f.properties.CLOS_OPEN);
                 *      tr.result.closure.reason = f.properties.CLOS_REAS;
                 *      tr.result.closure.status = f.properties.CLOS_STAT;
                 *
                 *      tr.meta.links.self = baseurl + "/tracks/" + id.ToString();
                 *
                 *
                 *      if (tr.result.features.Count == 0) tr.result.features = null;
                 *      if (tr.result.activities.Count == 0) tr.result.activities = null;
                 *      if (tr.result.images.Count == 0) tr.result.images = null;
                 *      break;
                 *
                 *  }
                 * }
                 */

                JsonResult jsonresult = new JsonResult(tr);
                return(jsonresult);
            }
            catch (Exception ex)
            {
                JsonResult jsonresult = new JsonResult("Error: " + ex.ToString());
                return(jsonresult);
            }
        }