Example #1
0
        /// <summary>
        /// Transforms a point into a way point description for xRoute
        /// </summary>
        /// <param name="p">Point to create the way point from</param>
        /// <param name="viaType">Via type to be set, if any</param>
        /// <returns>Newly created way point</returns>
        public static WaypointDesc ToWayPoint(this System.Windows.Point p, ViaTypeEnum?viaType = null)
        {
            p = Wgs84ToPtvSmartUnitsTransform.Transform(p);

            var wayPointDesc = new WaypointDesc
            {
                linkType      = LinkType.AUTO_LINKING,
                wrappedCoords = new[] { new Point {
                                            point = new PlainPoint {
                                                x = p.X, y = p.Y
                                            }
                                        } }
            };

            if (viaType.HasValue)
            {
                wayPointDesc.viaType = new ViaType {
                    viaType = viaType.Value
                }
            }
            ;

            return(wayPointDesc);
        }
        static void Main(string[] args)
        {
            #region general purpose
            var rlo = new ResultListOptions()
            {
                segments = true,
            };
            var cio = new CountryInfoOptions();
            var cc  = new CallerContext()
            {
                wrappedProperties = new CallerContextProperty[]
                {
                    new CallerContextProperty()
                    {
                        key = "ProfileXMLSnippet",
                    },
                    new CallerContextProperty()
                    {
                        key = "Profile", value = "mg-trailer-truck",
                    },
                },
            };
            #endregion

            #region adr example
            var adrSnippet = new com.ptvgroup.xserver1.XRouteProfile.Profile()
            {
                MajorVersion             = "1",
                MinorVersion             = "0",
                DataCompatibilityVersion = "2",
                FeatureLayer             = new com.ptvgroup.xserver1.XRouteProfile.FeatureLayer()
                {
                    MajorVersion   = "1",
                    MinorVersion   = "0",
                    GlobalSettings = new com.ptvgroup.xserver1.XRouteProfile.GlobalSettings()
                    {
                        EnableVehicleDependency = "true",
                    },
                    Themes = new com.ptvgroup.xserver1.XRouteProfile.Themes()
                    {
                        Theme = new List <com.ptvgroup.xserver1.XRouteProfile.Theme>()
                        {
                            new com.ptvgroup.xserver1.XRouteProfile.Theme()
                            {
                                Enabled = "true",
                                Id      = "PTV_TruckAttributes",
                            },
                        },
                    },
                },
                Routing = new com.ptvgroup.xserver1.XRouteProfile.Routing()
                {
                    MajorVersion = "2",
                    MinorVersion = "0",
                    Vehicle      = new com.ptvgroup.xserver1.XRouteProfile.Vehicle()
                    {
                        Load = new com.ptvgroup.xserver1.XRouteProfile.Load()
                        {
                            LoadType              = "GOODS",
                            HazardousGoodsType    = "HAZARDOUS",
                            TunnelRestrictionCode = "E",
                        },
                    },
                    Course = new com.ptvgroup.xserver1.XRouteProfile.Course()
                    {
                        AdditionalDataRules = new com.ptvgroup.xserver1.XRouteProfile.AdditionalDataRules()
                        {
                            Enabled = "true",
                        },
                    },
                }
            };
            var tunnelWps = new WaypointDesc[]
            {
                new WaypointDesc()
                {
                    linkType      = LinkType.AUTO_LINKING,
                    wrappedCoords = new Point[]
                    {
                        new Point()
                        {
                            point = new PlainPoint()
                            {
                                x = 520127, y = 6878446,
                            },
                        },
                    },
                },
                new WaypointDesc()
                {
                    linkType      = LinkType.AUTO_LINKING,
                    wrappedCoords = new Point[]
                    {
                        new Point()
                        {
                            point = new PlainPoint()
                            {
                                x = 522578, y = 6861984,
                            },
                        },
                    },
                },
            };
            #endregion

            #region block country
            var blockBelgiumSnippet = new com.ptvgroup.xserver1.XRouteProfile.Profile()
            {
                MajorVersion             = "1",
                MinorVersion             = "0",
                DataCompatibilityVersion = "2",
                Routing = new com.ptvgroup.xserver1.XRouteProfile.Routing()
                {
                    MajorVersion = "2",
                    MinorVersion = "0",
                    Algorithm    = new com.ptvgroup.xserver1.XRouteProfile.Algorithm()
                    {
                        GeographicRestrictions = new com.ptvgroup.xserver1.XRouteProfile.GeographicRestrictions()
                        {
                            ForbiddenCountry = new List <com.ptvgroup.xserver1.XRouteProfile.ForbiddenCountry>()
                            {
                                new com.ptvgroup.xserver1.XRouteProfile.ForbiddenCountry()
                                {
                                    CountryCode = "32",
                                },
                            },
                        },
                    },
                },
            };
            var normallyThroughBelgiumWps = new WaypointDesc[]
            {
                new WaypointDesc()
                {
                    linkType      = LinkType.AUTO_LINKING,
                    wrappedCoords = new Point[]
                    {
                        new Point()
                        {
                            point = new PlainPoint()
                            {
                                x = 510724, y = 6734625,
                            },
                        },
                    },
                },
                new WaypointDesc()
                {
                    linkType      = LinkType.AUTO_LINKING,
                    wrappedCoords = new Point[]
                    {
                        new Point()
                        {
                            point = new PlainPoint()
                            {
                                x = 290832, y = 6514732,
                            },
                        },
                    },
                },
            };
            #endregion

            #region emissions
            var emmisionSnippet = new com.ptvgroup.xserver1.XRouteProfile.Profile()
            {
                MajorVersion             = "1",
                MinorVersion             = "0",
                DataCompatibilityVersion = "2",
                Routing = new com.ptvgroup.xserver1.XRouteProfile.Routing()
                {
                    MajorVersion = "2",
                    MinorVersion = "0",
                    Vehicle      = new com.ptvgroup.xserver1.XRouteProfile.Vehicle()
                    {
                        Physical = new com.ptvgroup.xserver1.XRouteProfile.Physical()
                        {
                            Drive = new com.ptvgroup.xserver1.XRouteProfile.Drive()
                            {
                                DriveType = "MOTORIZED",
                                Emissions = new com.ptvgroup.xserver1.XRouteProfile.Emissions()
                                {
                                    EmissionClass = "EURO_6",
                                },
                                Engine = new com.ptvgroup.xserver1.XRouteProfile.Engine()
                                {
                                    BioFuelRatio    = "0",
                                    FuelConsumption = "32.6",
                                    FuelType        = "DIESEL",
                                }
                            }
                        }
                    },
                },
            };
            var emmisionWps = new WaypointDesc[]
            {
                new WaypointDesc()
                {
                    linkType      = LinkType.AUTO_LINKING,
                    wrappedCoords = new Point[]
                    {
                        new Point()
                        {
                            point = new PlainPoint()
                            {
                                x = 735099, y = 6755798,
                            },
                        },
                    },
                },
                new WaypointDesc()
                {
                    linkType      = LinkType.AUTO_LINKING,
                    wrappedCoords = new Point[]
                    {
                        new Point()
                        {
                            point = new PlainPoint()
                            {
                                x = 1350798, y = 6074131,
                            },
                        },
                    },
                },
            };

            var emmissionsRlo = new ResultListOptions()
            {
                emissions = new EmissionType()
                {
                    emissionLevel = EmissionLevel.BASIC,
                },
                hbefaType = new HBEFAType()
                {
                    version = HBEFAVersion.HBEFA_3_2,
                },
                cenEmissionConfiguration = new CENEmissionConfiguration()
                {
                    cenVersion = CENVersion.CEN_2012,
                    fleetSpecificAverageFuelConsumption          = 32.6,
                    fleetSpecificAverageFuelConsumptionSpecified = true,
                },
            };
            #endregion

            using (var xroute = new XRouteWSClient())
            {
                //var binding = xroute.Endpoint.Binding as BasicHttpBinding;
                //binding.Security.Mode = BasicHttpSecurityMode.Transport;
                //binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
                //binding.MaxReceivedMessageSize = 1234567890;
                //xroute.ClientCredentials.UserName.UserName = "******";
                //xroute.ClientCredentials.UserName.Password = "";
                //xroute.Endpoint.Address = new EndpointAddress("https://xroute-tln-eu-n.cloud.ptvgroup.com/xroute/ws/XRoute");

                ExtendedRoute extendedRoute = null;

                Console.WriteLine(blockBelgiumSnippet.ToSnippet());

                extendedRoute = xroute.calculateExtendedRoute(normallyThroughBelgiumWps, null, null, rlo, cio, cc);
                Console.WriteLine($"Withouth \"block belgium\" snippet the distance is {extendedRoute.route.info.distance}. It goes through {string.Join(",", extendedRoute.route.wrappedSegments.Select(s => s.iuCode).Distinct())}");

                cc.wrappedProperties[0].value = blockBelgiumSnippet.ToSnippet();
                extendedRoute = xroute.calculateExtendedRoute(normallyThroughBelgiumWps, null, null, rlo, cio, cc);
                Console.WriteLine($"Withouth \"block belgium\" snippet the distance is {extendedRoute.route.info.distance}. It goes through {string.Join(",", extendedRoute.route.wrappedSegments.Select(s => s.iuCode).Distinct())}");

                Console.WriteLine();
                Console.WriteLine(emmisionSnippet.ToSnippet());

                cc.wrappedProperties[0].value = emmisionSnippet.ToSnippet();
                extendedRoute = xroute.calculateExtendedRoute(emmisionWps, null, null, emmissionsRlo, cio, cc);
                Console.WriteLine($"Emmisison distance {extendedRoute.route.info.distance}. Fleet based co2eTank2Wheel = {(extendedRoute.route.cenEmissions.fleetSpecific as CENEmissions2012).co2eTank2Wheel}. HBEFA based co2eTank2Wheel = {(extendedRoute.route.cenEmissions.basedOnHBEFA as CENEmissions2012).co2eTank2Wheel}. Pure HBEFA carbonDioxide = {extendedRoute.route.emissions.carbonDioxide} ");

                Console.WriteLine();
                Console.WriteLine(adrSnippet.ToSnippet());

                cc.wrappedProperties[0].value = adrSnippet.ToSnippet();
                extendedRoute = xroute.calculateExtendedRoute(tunnelWps, null, null, rlo, cio, cc);
                Console.WriteLine($"With tunnel code {adrSnippet.Routing.Vehicle.Load.TunnelRestrictionCode} the distance is {extendedRoute.route.info.distance}.");

                adrSnippet.Routing.Vehicle.Load.TunnelRestrictionCode = "D";
                cc.wrappedProperties[0].value = adrSnippet.ToSnippet();
                extendedRoute = xroute.calculateExtendedRoute(tunnelWps, null, null, rlo, cio, cc);
                Console.WriteLine($"With tunnel code {adrSnippet.Routing.Vehicle.Load.TunnelRestrictionCode} the distance is {extendedRoute.route.info.distance}.");

                adrSnippet.Routing.Vehicle.Load.TunnelRestrictionCode = "C";
                cc.wrappedProperties[0].value = adrSnippet.ToSnippet();
                extendedRoute = xroute.calculateExtendedRoute(tunnelWps, null, null, rlo, cio, cc);
                Console.WriteLine($"With tunnel code {adrSnippet.Routing.Vehicle.Load.TunnelRestrictionCode} the distance is {extendedRoute.route.info.distance}.");

                adrSnippet.Routing.Vehicle.Load.TunnelRestrictionCode = "B";
                cc.wrappedProperties[0].value = adrSnippet.ToSnippet();
                extendedRoute = xroute.calculateExtendedRoute(tunnelWps, null, null, rlo, cio, cc);
                Console.WriteLine($"With tunnel code {adrSnippet.Routing.Vehicle.Load.TunnelRestrictionCode} the distance is {extendedRoute.route.info.distance}.");

                adrSnippet.Routing.Vehicle.Load.TunnelRestrictionCode = "NONE";
                cc.wrappedProperties[0].value = adrSnippet.ToSnippet();
                extendedRoute = xroute.calculateExtendedRoute(tunnelWps, null, null, rlo, cio, cc);
                Console.WriteLine($"With tunnel code {adrSnippet.Routing.Vehicle.Load.TunnelRestrictionCode} the distance is {extendedRoute.route.info.distance}.");
            }
            Console.ReadLine();
        }
Example #3
0
        private void DealerSearch(System.Windows.Point point)
        {
            Cursor = Cursors.Wait;
            mapControl.SetMapLocation(point, 12, srid);
            reachableObjectLayer.Shapes.Clear();
            isochroneLayer.Shapes.Clear();

            var waypoint = new WaypointDesc()
            {
                linkType      = LinkType.NEXT_SEGMENT,
                wrappedCoords = new XRoute.Point[]
                {
                    new XRoute.Point()
                    {
                        point = new PlainPoint()
                        {
                            x = point.X,
                            y = point.Y,
                        },
                    },
                },
            };

            var expansionDesc = new ExpansionDescription()
            {
                expansionType   = ExpansionType.EXP_TIME,
                wrappedHorizons = new int[] { 900 },
            };

            var options = new ReachableObjectsOptions()
            {
                expansionDesc      = expansionDesc,
                linkType           = LinkType.NEXT_SEGMENT,
                routingDirection   = RoutingDirectionType.FORWARD,
                geodatasourceLayer = XDealerSample.Properties.Settings.Default.GeoDataSource,
            };

            var cc = new CallerContext()
            {
                wrappedProperties = new CallerContextProperty[]
                {
                    new CallerContextProperty()
                    {
                        key = "CoordFormat", value = "PTV_MERCATOR"
                    },
                    new CallerContextProperty()
                    {
                        key = "Profile", value = "carfast"
                    },
                }
            };

            var isoOptions = new IsochroneOptions()
            {
                expansionDesc          = expansionDesc,
                isoDetail              = IsochroneDetail.POLYS_ONLY,
                polygonCalculationMode = PolygonCalculationMode.NODE_BASED,
            };

            ReachableObjects foundObjects = null;
            Isochrone        isochrone    = null;

            using (var xRouteClient = new XRouteWSClient())
            {
                try
                {
                    foundObjects = xRouteClient.searchForReachableObjects(waypoint, null, null, options, null, cc);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(
                        "Exception while searching for objects.\n\nException type: " + exception.GetType().ToString() +
                        "\nMessage: " + exception.Message);
                    Cursor = null;
                    return;
                }
                try
                {
                    isochrone = xRouteClient.calculateIsochrones(waypoint, null, isoOptions, cc);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(
                        "Exception while calculating isochrone.\n\nException type: " + exception.GetType().ToString() +
                        "\nMessage: " + exception.Message);
                    Cursor = null;
                    return;
                }
            }

            foreach (var foundObject in foundObjects.wrappedReachableObject)
            {
                var ball = new Ball()
                {
                    Height  = 10,
                    Width   = 10,
                    Tag     = [email protected],
                    ToolTip = "",
                    Color   = Colors.Blue,
                };
                ball.ToolTipOpening += ball_ToolTipOpening;

                var winPoint = new System.Windows.Point()
                {
                    X = [email protected],
                    Y = [email protected],
                };
                ShapeCanvas.SetLocation(ball, winPoint);
                reachableObjectLayer.Shapes.Add(ball);
            }

            var linearRing = new NetTopologySuite.Geometries.LinearRing(
                isochrone.wrappedIsochrones[0].polys.lineString.wrappedPoints
                .Select(p => new GeoAPI.Geometries.Coordinate(p.x, p.y))
                .ToArray()
                );

            linearRing.Normalize();

            var geom = new NetTopologySuite.Geometries.Polygon(linearRing);

            var bufferedGeom = geom.Buffer(100);
            var polygon      = new MapPolygon()
            {
                Points  = new PointCollection(bufferedGeom.Boundary.Coordinates.Select(c => new System.Windows.Point(c.X, c.Y))),
                Fill    = new SolidColorBrush(Colors.AliceBlue),
                Opacity = 0.75,
                Stroke  = new SolidColorBrush(Colors.DarkSlateGray)
            };

            isochroneLayer.Shapes.Add(polygon);

            Cursor = null;
        }
Example #4
0
        private void calcualteRouteButton_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor = Cursors.WaitCursor;
                routeLayer.Shapes.Clear();
                using (var xlocate = XWSClientFactory.GetXLocateWSClient(Properties.Settings.Default.XLocate, token))
                    using (var xroute = XWSClientFactory.GetXRouteWSClient(Properties.Settings.Default.XRoute, token))
                    {
                        // geocode for the from and to city
                        var addresses = new Address[]
                        {
                            new Address()
                            {
                                city = fromCityTextBox.Text
                            },
                            new Address()
                            {
                                city = toCityTextBox.Text
                            },
                        };
                        var addressResponse = xlocate.findAddresses(addresses, null, null, null, null);
                        // if from not found, abort
                        if (addressResponse[0].wrappedResultList == null || addressResponse[0].wrappedResultList.Length == 0)
                        {
                            MessageBox.Show("From city not found");
                            return;
                        }
                        // if to not found, abort
                        if (addressResponse[1].wrappedResultList == null || addressResponse[1].wrappedResultList.Length == 0)
                        {
                            MessageBox.Show("To city not found");
                            return;
                        }

                        // create waypointdesc for call to xroute
                        var wps     = new List <WaypointDesc>();
                        var startWp = new WaypointDesc()
                        {
                            linkType      = LinkType.AUTO_LINKING,
                            wrappedCoords = new XServers.XRoute.Point[]
                            {
                                new XServers.XRoute.Point()
                                {
                                    point = new XServers.XRoute.PlainPoint()
                                    {
                                        x = addressResponse[0].wrappedResultList[0].coordinates.point.x,
                                        y = addressResponse[0].wrappedResultList[0].coordinates.point.y,
                                    },
                                },
                            },
                        };
                        wps.Add(startWp);

                        // is there is a row select in the datagrid, take the id to use a a combined transport intermidiate
                        if (combinedTransportDataGridView.SelectedRows.Count > 0)
                        {
                            var combinedWp = new WaypointDesc()
                            {
                                combinedTransportID = (combinedTransportDataGridView.SelectedRows[0].DataBoundItem as ResultCombinedTransport).id,
                                viaType             = new ViaType()
                                {
                                    viaType = ViaTypeEnum.COMBINED_TRANSPORT,
                                },
                            };
                            wps.Add(combinedWp);
                        }

                        var endWp = new WaypointDesc()
                        {
                            linkType      = LinkType.AUTO_LINKING,
                            wrappedCoords = new XServers.XRoute.Point[]
                            {
                                new XServers.XRoute.Point()
                                {
                                    point = new XServers.XRoute.PlainPoint()
                                    {
                                        x = addressResponse[1].wrappedResultList[0].coordinates.point.x,
                                        y = addressResponse[1].wrappedResultList[0].coordinates.point.y,
                                    },
                                },
                            },
                        };
                        wps.Add(endWp);
                        var rlo = new ResultListOptions()
                        {
                            polygon = true
                        };

                        // use 40t profile for truck routing
                        var cc = new XServers.XRoute.CallerContext()
                        {
                            wrappedProperties = new XServers.XRoute.CallerContextProperty[]
                            {
                                new XServers.XRoute.CallerContextProperty()
                                {
                                    key = "Profile", value = "40T",
                                },
                            },
                        };

                        var route = xroute.calculateRoute(wps.ToArray(), null, null, rlo, cc);

                        // paint the route
                        var line = new Ptv.XServer.Controls.Map.Layers.Shapes.MapPolyline()
                        {
                            MapStrokeThickness = 4,
                            Stroke             = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Brown),
                            Points             = new System.Windows.Media.PointCollection(),
                        };
                        foreach (var plainPoint in route.polygon.lineString.wrappedPoints)
                        {
                            line.Points.Add(new System.Windows.Point(plainPoint.x, plainPoint.y));
                        }
                        routeLayer.Shapes.Add(line);
                        map.WrappedMap.ZoomToAll();
                    }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, exception.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor = null;
            }
        }