Developers Knowledge Base

WebGIS enables powerful geospatial web applications and services that securely share your organization’s rich geospatial data, and provides tools to deeply examine spatial data and create value added products, on demand.
Showing results for 
Search instead for 
Do you mean 

WebMap Route Service DetermineRoute method VB.Net Code Example

by Anonymous on ‎01-19-2017 08:43 AM - edited on ‎04-13-2017 04:53 AM by Technical Evangelist (1,153 Views)

Introduction

This article provides a sample Route Service program which calculates a route/path using the DetermineRoute method of a WebMap Route Service Instance. The program is a custom VB.NET Web Application. It is essentially a copy of the version 6.1 Route Web Service Example with some minor changes for using a Service Reference with the .NET Framework version 4.0 and higher instead of a Web Reference since Web References are now considered legacy technology.

 

This program assumes the user has already created a Route Service instance and the required Route Service binary files using the RouteDataPub .exe executable. This executable is well-documented in the online documentation at https://hexagongeospatial.fluidtopics.net/book#!book;uri=53add82fbba614c6510f83a909c5c4d9;breadcrumb....

 

This program also assumes that a new and/or empty VB.NET Web project of the user’s choosing has been created. For this test sample, I created an empty VB Web Application project and added the appropriate Service Reference to the existing Route Service Instance. This example also assumes that a Web Form has been added with a button that invokes the Determine Route method processing.  

Development

In the Project/Visual Studio Development Environment, select to add a Service Reference.  I normally open the VS Solution Explorer, right-click on Service Reference in the Solution Explorer Panel, and then select to Add.  The screen print below is how I defined the Service Reference for this example (Note the attached zip file of the Word Document contains any screen prints in addition to the text):

 

Once the Service Reference is added, begin coding the program.

Sample Code

 

'This is the Route Service that was added as a Service Reference.

Imports DemoRouteDataConsumer.RouteServiceReference

Public Class Form1
    Dim rtResult As Route

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '----------------------------
        '-- Initialize Web Service
        '----------------------------
        Dim wsRoute As New WSIRouteClient() ' This Public class is in the Route Service reference of RouteServiceReference

        '----------------------------
        '-- Get Service Info
        '----------------------------
        Dim rtServiceInfo As ServiceInfo = wsRoute.GetServiceInfo()

        '----------------------------
        '-- Get Dataset Info
        '----------------------------
        Dim rtDataSets() As RouteDatasetInfo = wsRoute.GetAllDatasetInfo()

        '----------------------------
        '— Initialize Route Spec Object
        '----------------------------
        Dim rtSpecification As New RouteSpec

        rtSpecification.DatasetName = rtDataSets(0).Name
        rtSpecification.DistanceUnit = DISTANCEUNITTYPE.METER

        ' The RoutePreference type is case-sensitive and must match what is defined in the configuration file of the Route Service.
        rtSpecification.RoutePreference = "Fastest"

        Dim CoordSystem As String = rtDataSets(0).BBox.SRS ''Use the first coord system you find.
        Dim Language As String = rtDataSets(0).SupportedLanguages(0) '"en-US" 'rtDataSets(0).SupportedLanguages(0)

        '-- Initialize Route Instruction Spec
        rtSpecification.InstructionSpecification = New InstructionSpec
        rtSpecification.InstructionSpecification.ReturnBBox = True
        rtSpecification.InstructionSpecification.ReturnGeometry = True

        '-- Set Avoid List (Optional)
        Dim avoidFeatures(1) As String
        avoidFeatures(0) = "AvoidFeatures"  'One of the avoid lists specified in the Route data configuration file
        Dim av As New AvoidList()
        rtSpecification.AvoidList = av0

        Dim avoidFeatures(-1) As String
        ' One of the avoid lists specified in Route data configuration file
        avoidFeatures(0) = "AvoidFeatures"
        Dim av As New AvoidList()
        av.Feature = avoidFeatures
        defaultRouteSpec.AvoidList = av



        '-- Set Restriction Info (Optional)
        Dim EdgeRestrictions(1) As Restriction
        EdgeRestrictions(0) = New Restriction
        EdgeRestrictions(0).Name = "Speed Limit" 'One of the restrictions specified Route data configuration file
        EdgeRestrictions(0).ROperator = (OPERATORTYPE.GREATERTHAN)
        EdgeRestrictions(0).Value = "55"
        rtSpecification.EdgeRestrictions = EdgeRestrictions
        rtSpecification.ReturnViolatedRestrictions = True
        rtSpecification.ReturnViolatedRestrictionGeometry = True

        '----------------------------
        '-- Generate Route
        '----------------------------

        ' Option 1 - Simple Two-Point route
        '—Start Point
        Dim StartPoint As New PointPropertyType
        StartPoint.Point = New PointType

        With StartPoint.Point
            .srsName = CoordSystem
            .coordinates = New CoordinatesType
            .coordinates.Value = "-96.652231,33.1926575"
        End With

        '—End Point
        Dim EndPoint As New PointPropertyType
        EndPoint.Point = New PointType
        With EndPoint.Point
            .srsName = CoordSystem
            .coordinates = New CoordinatesType
            .coordinates.Value = "-86.632141,40.200702"
        End With

        rtSpecification.ViaPoints = Nothing

        ' Option 2 - Multi-Point route
        '—Start Point

        'Dim StartPoint As New PointPropertyType
        'StartPoint.Point = New PointType

        'With StartPoint.Point
        '    .srsName = CoordSystem
        '    .coordinates = New CoordinatesType
        '    .coordinates.Value = "-96.652231,33.1926575"
        'End With

        ''—End Point
        'Dim EndPoint As New PointPropertyType
        'EndPoint.Point = New PointType
        'With EndPoint.Point
        '    .srsName = CoordSystem
        '    .coordinates = New CoordinatesType
        '    .coordinates.Value = "-86.632141,40.200702"
        'End With

        'Dim viaPoints(3) As PointPropertyType
        'Dim viapt1 As New PointType

        'With viapt1
        '    .srsName = CoordSystem
        '    .coordinates = New CoordinatesType
        '    .coordinates.Value = "-73.96481,40.69932"
        'End With

        'viaPoints(0).Point = viapt1

        'Dim viapt2 As New PointType
        'With viapt2
        '    .srsName = CoordSystem
        '    .coordinates = New CoordinatesType
        '    .coordinates.Value = "-122.67179,45.54883"
        'End With

        'viaPoints(1).Point = viapt2
        'Dim viapt3 As New PointType

        'With viapt3
        '    .srsName = CoordSystem
        '    .coordinates = New CoordinatesType
        '    .coordinates.Value = "-118.13855,33.80260"
        'End With

        'viaPoints(2).Point = viapt3
        'rtSpecification.ViaPoints = viaPoints

        'Complete route specification settings and Set Best Order options
        With rtSpecification
            '.ReturnViolatedRestrictionGeometry = True
            '.ReturnViolatedRestrictions = True
            '.SnapStopsToRestrictedEdges = False
            .ReturnGeometry = True
            .StartPointFixed = False
            .EndPointFixed = False
            .ReturnStopSummary = True
            .GetBestOrder = True
        End With

        'And request the route
        Try
            rtResult = wsRoute.DetermineRoute(rtSpecification, rtStartPoint, rtEndPoint)
            '-- Get Route Summary
            If (rtResult.Summary.Distance IsNot Nothing) Then
                RouteDistanceSumLabel.Text = rtResult.Summary.Distance
            End If

            '-- Get Route Instructions
            For i As Integer = 0 To rtResult.RouteInstructions.GetUpperBound(0)
                If (rtResult.RouteInstructions(i).Instruction IsNot Nothing) Then
                    ListBox1.Items.Add(rtResult.RouteInstructions(i).Instruction)
                End If
            Next i
        Catch ex As Exception
            MsgBox("ERROR - " & ex.Message)
            Exit Sub
        End Try
    End Sub
End Class

 

 

 

 

Overview
Contributors