Exemplo n.º 1
0
        public List<RoutePointModel> linestringToRoutePointModel()
        {
            List<RoutePointModel> rpmList = new List<RoutePointModel>();
            for(int i=0; i<this.routeLineString.STNumPoints(); i++)
            {
                RoutePointModel rpm = new RoutePointModel(this.routeLineString.STPointN(i+1));

                rpmList.Add(rpm);
            }
            return rpmList;
        }
Exemplo n.º 2
0
        public ActionResult SearchViaPoint(String Latitude, String Longitude)
        {
            Latitude = Latitude.Replace(".", ",");
            Longitude = Longitude.Replace(".", ",");

            RoutePointModel rpm = new RoutePointModel(double.Parse(Latitude), double.Parse(Longitude));
            List<RouteModel> ResultRoutes = RouteModel.getNearestRoutes(rpm, 10);
            return PartialView("Routes/_ListRoutes", ResultRoutes);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieve the routes closest to the provided RoutePointModel
        /// </summary>
        /// <param name="rpm">The RPM to search near.</param>
        /// <param name="amountOfRoutes">The amount of routes to retrieve (at most).</param>
        /// <returns>The nearest routes, sorted by distance (shortest distance first).</returns>
        public static List<RouteModel> getNearestRoutes(RoutePointModel rpm, int amountOfRoutes)
        {
            SqlConnection conn = new SqlConnection(_db.Connection.ConnectionString);

            // Select the SPROC to use
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "NNSearch";
            cmd.CommandType = CommandType.StoredProcedure;

            // Add arguments to the SPROC

            // The amount of routes to return
            cmd.Parameters.Add(new SqlParameter("@AMOUNT", amountOfRoutes));

            // The point to find NN's for
            SqlParameter param = new SqlParameter("@POINT", SqlDbType.Udt);
            param.SqlDbType = SqlDbType.Udt;
            param.UdtTypeName = "geography";
            param.Value = rpm.asSqlGeography();
            cmd.Parameters.Add(param);

            // Prepare for the result
            List<RouteModel> result = new List<RouteModel>();

            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();

            // Read output from SPROC
            while (reader.Read())
            {
                // Read the "RouteLineStringID" attribute
                result.Add(new RouteModel((int)reader["RouteID"]));
            }

            reader.Close();
            conn.Close();
            return result;
        }