/// <summary> Create the route layer. </summary> /// /// <param name="map">Map control to attach to.</param> /// <param name="xRouteUrl"> URL of xRoute server. </param> /// <param name="user"> User name. </param> /// <param name="password"> Password. </param> public RouteLayer(WpfMap map, string xRouteUrl, string user, string password) : base("Route") { Map = map; xRouteClient = Route.CreateXRouteClient(xRouteUrl, user, password); WayPoint.WayPointMouseRightButtonDown += ShowWayPointContextMenu; Reset(); }
/// <summary> /// Factory for the of the xServer generated client class granting access to the xRoute server. /// If xServers are used on an Azure environment, authentication data has to be integrated when /// requests are made. /// </summary> /// <param name="xUrl">The xServer base url. </param> /// <returns></returns> public static XRouteWSClient CreateXRouteClient(string xUrl) { string completeXServerUrl = XServerUrl.Complete(xUrl, "XRoute"); var binding = new BasicHttpBinding { ReceiveTimeout = new TimeSpan(0, 0, 30), SendTimeout = new TimeSpan(0, 0, 30), OpenTimeout = new TimeSpan(0, 0, 30), CloseTimeout = new TimeSpan(0, 0, 30), MaxReceivedMessageSize = int.MaxValue }; var endpoint = new EndpointAddress(completeXServerUrl); var client = new XRouteWSClient(binding, endpoint); if (!XServerUrl.IsXServerInternet(completeXServerUrl)) { return(client); } binding.Security.Mode = BasicHttpSecurityMode.Transport; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; client.ClientCredentials.SetConfiguredToken(); return(client); }
/// <summary> /// Creates the route. /// </summary> /// <param name="layer">The route layer the route belongs to.</param> /// <param name="client">Web service API of xRoute. </param> public Route(RouteLayer layer, XRouteWSClient client) { this.layer = layer; timer.Tick += Timer_Elapsed; finalPolyline = new RoutePolylineWithDragAndDrop(layer, this); previewPolyline = new RoutePolylineWithDragAndDrop(layer); xRoute = client; }
public Route CalcRoute(double lat1, double lon1, double lat2, double lon2) { var xRoute = new XRouteWSClient(); if (xRoute.ClientCredentials != null) { xRoute.ClientCredentials.UserName.UserName = "******"; xRoute.ClientCredentials.UserName.Password = "******"; } return(xRoute.calculateRoute(new[] { new WaypointDesc { wrappedCoords = new[] { new XRouteServiceReference.Point { point = new PlainPoint { x = lon1, y = lat1 } } } }, new WaypointDesc { wrappedCoords = new[] { new XRouteServiceReference.Point { point = new PlainPoint { x = lon2, y = lat2 } } } } }, null, null, new ResultListOptions { polygon = true }, new CallerContext { wrappedProperties = new[] { new CallerContextProperty { key = "CoordFormat", value = "OG_GEODECIMAL" } } } )); }
/// <summary> /// Factory for the of the xServer generated client class granting access to the xRoute server. /// If xServers are used on an Azure environment, authentication data has to be integrated when /// requests are made. /// </summary> /// <param name="xUrl">The xServer base url. </param> /// <param name="user"> User name. </param> /// <param name="password"> Password. </param> /// <returns> xRoute API based on Web Services. </returns> public static XRouteWSClient CreateXRouteClient(string xUrl, string user, string password) { var completeXServerUrl = XServerUrl.Complete(xUrl, "XRoute"); var binding = new BasicHttpBinding { ReceiveTimeout = new TimeSpan(0, 0, 30), SendTimeout = new TimeSpan(0, 0, 30), OpenTimeout = new TimeSpan(0, 0, 30), CloseTimeout = new TimeSpan(0, 0, 30), MaxReceivedMessageSize = int.MaxValue }; var endpoint = new EndpointAddress(completeXServerUrl); var client = new XRouteWSClient(binding, endpoint); if (!XServerUrl.IsXServerInternet(completeXServerUrl)) { return(client); } binding.Security.Mode = BasicHttpSecurityMode.Transport; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; client.ClientCredentials.UserName.UserName = user; client.ClientCredentials.UserName.Password = password; // increase message size (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = 4 << 20; (client.Endpoint.Binding as BasicHttpBinding).ReaderQuotas.MaxBytesPerRead = 4 << 20; // set timeouts client.Endpoint.Binding.SendTimeout = TimeSpan.FromMilliseconds(5000); client.Endpoint.Binding.ReceiveTimeout = TimeSpan.FromMilliseconds(10000); return(client); }
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(); }
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; }