Calculate Route

This forum deals with any kind of routing computation whether it is simple A:B-routing, calculation of isochrones, simple matrix computation or nearest search.
Post Reply
javor
Posts: 2
Joined: Mon Jan 09, 2017 6:52 am

Calculate Route

Post by javor »

I try to calculate route but always I have this error message - "linking to waypoint (zero-based index list: unknown) failed".
Below is my code.

Code: Select all

public class Location
    {
        public Location(double latitude, double longitude)
        {
            this.Latitude = latitude;
            this.Longitude = Longitude;
        }

        /// <summary>
        /// Get or sets latitude.
        /// </summary>
        public double Latitude { get; set; }

        /// <summary>
        /// Get or sets longitude.
        /// </summary>
        public double Longitude { get; set; }
    }

    public class PtvRoute
    {
        private XRouteWSClient xRouteClient;

        public PtvRoute()
        {
            xRouteClient = new XRouteWSClient();
            xRouteClient.ClientCredentials.UserName.UserName = "UserName";
            xRouteClient.ClientCredentials.UserName.Password = "Password";
            xRouteClient.Endpoint.Address = new EndpointAddress("https://xroute-eu-n-test.cloud.ptvgroup.com/xroute/ws/XRoute");
            (xRouteClient.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = 4 << 20;
            (xRouteClient.Endpoint.Binding as BasicHttpBinding).ReaderQuotas.MaxBytesPerRead = 4 << 20;

            // set timeouts
            xRouteClient.Endpoint.Binding.SendTimeout = TimeSpan.FromMilliseconds(5000);
            xRouteClient.Endpoint.Binding.ReceiveTimeout = TimeSpan.FromMilliseconds(10000);
        }

        public ExtendedRoute CalcRoute(Location from, Location to)
        {
            Point startPoint = new Point();
            startPoint.point = new PlainPoint { x = from.Longitude, y = from.Latitude };
            WaypointDesc wpdStart = new WaypointDesc();
            wpdStart.wrappedCoords = new Point[] { startPoint };
            wpdStart.linkType = LinkType.AUTO_LINKING;

            Point destPoint = new Point();
            destPoint.point = new PlainPoint { x = to.Longitude, y = to.Latitude };
            WaypointDesc wpdDest = new WaypointDesc();
            wpdDest.wrappedCoords = new Point[] { destPoint };
            wpdDest.linkType = LinkType.AUTO_LINKING;

            ResultListOptions resultOptions = new ResultListOptions()
            {
                polygon = true,
                detailLevel = DetailLevel.STANDARD,
            };
            CountryInfoVehicleOptions countryInfoVehicleOptions = new CountryInfoVehicleOptions();
            countryInfoVehicleOptions.allEuro = true;
            countryInfoVehicleOptions.detailedTollCosts = true;

            // Define vehicleOptions
            countryInfoVehicleOptions.wrappedOptions = new VehicleOption[]{
                        new VehicleOption{ parameter = VehicleParameter.TYPE, value = "TRU"},
                        new VehicleOption{ parameter = VehicleParameter.TOTAL_WEIGHT, value = "15000"},
                        //new XRoute.VehicleOption{ parameter = VehicleParameter.TRAILER_WEIGHT, value = "20000"},
                        //new XRoute.VehicleOption{ parameter = VehicleParameter.NUMBER_OF_AXLES, value = "4"},
                        new VehicleOption{ parameter = VehicleParameter.EMISSION_CLASS, value = "EURO_4"},
                        //new XRoute.VehicleOption{ parameter = XRoute.VehicleParameter.HEIGHT, value = "400"},
                        //new XRoute.VehicleOption{ parameter = XRoute.VehicleParameter.LENGTH, value = "2000"}
                    };

            CallerContext context = new CallerContext()
            {
                wrappedProperties = new CallerContextProperty[]
                       {
                            new CallerContextProperty() { key = "CoordFormat", value = "PTV_SMARTUNITS" },
                            new CallerContextProperty() { key = "ResponseGeometry", value = "WKB" }
                       }
            };


            // Step 2.2: Set both way-points into the specific array WaypointDesc[]
            WaypointDesc[] waypointDescs = new WaypointDesc[] { wpdStart, wpdDest };

            var route = xRouteClient.calculateExtendedRoute(waypointDescs, null, null, resultOptions, countryInfoVehicleOptions, context);

            return route;
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            PtvRoute routing = new PtvRoute();

            try
            {
                var route = routing.CalcRoute(new Location(42.708501, 23.332621), new Location(42.658578, 23.316328));
            }
            catch (Exception e)
            {

                Console.WriteLine(e.Message);
            }
            Console.ReadLine();
        }
    }
User avatar
Bernd Welter
Site Admin
Posts: 2564
Joined: Mon Apr 14, 2014 10:28 am
Contact:

Re: Calculate Route

Post by Bernd Welter »

Hi there,

Looks like the coordinates provided in line 100 of your code:

Code: Select all

var route = routing.CalcRoute(new Location(42.708501, 23.332621), new Location(42.658578, 23.316328));
are OG_DECIMAL formatted. Therefore line 76 should look like this:

Code: Select all

new CallerContextProperty() { key = "CoordFormat", value = "OG_GEODECIMAL" },
But besides the wrong coordinate format there is an issue with the location specified:
At least the destination coordinate lies in the forrest.
coordinate in the far off...
coordinate in the far off...
Best regards
Bernd
Bernd Welter
Technical Partner Manager Developer Components
PTV Logistics - Germany

Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning... :twisted:
Post Reply