Maptitude GISDK Help

Routing.Path

 

Objects of this class encapsulate data about a path through a set of stops calculated by the Routing.Router class.

 

Note

This function requires a HERE streets layer included with a Maptitude Country Package.  For a list of available Country packages, please visit https://www2.caliper.com/store/product/maptitude-country-package/HERE country packages

 

Constructor

 

Routing.Path

 

 

Properties

 

Name

Type

Contents

PathDisplayWidth

int

Width of line style

PathDisplayColor

rgb

Line color

PathDisplayLinestyle

style

Line style

Coords

 

Returns an array of coords for the path through all the stops

Value

real

The total value of the variable that was minimized during path calculation. i.e. if the Minimize property on the Router object was set to "Time" then this value represents the total driving time for the path in minutes, else if Minimize was set to "Distance" then it represents the total length of the Path in the current map units

Time

real

Trip time/duration, including rest and night stay, with default work day start and end time defined in Routing.Router

Distance

real

Total length of the path in the current map units

Links

 

Returns an array of link IDs for the path through all the stops. Each item has the following options

 

ID

int

Link ID

 

Direction

int

In direction of topology (1) or reverse (0)

 

Split

real

proportion of link travelled (between 0 and 1.0)

Stops

 

Returns An array of option arrays describing the ordered stops along the path. Each item has the following options:

 

Location

coord

The location of the stop snapped to the closest link

 

Index

int

The index in the original set of stops represented by this item

 

Note

This function is requires the HERE streets layer included with a Maptitude Country Package.  For a list of avaliable Country packages, please visit https://www2.caliper.com/store/product/maptitude-country-package/HERE country packages

 

Methods

 

DisplayPath()

Displays a path annotation on the current map.

 

ClearPathDisplay()

Removes path annotations.

 

Examples

 

GISDK

 

// Generate a shortest path via 5 routing points and display on the current map window

Macro "RoutingExample1"

   on error do

       ShowMessage(GetLastError())

       return()

   end

   p1.Coordinate = Coord(-71259994, 42298892)

   p1.StopDuration = 30

   p1.StopName = "Babson College"

  

   p2.Coordinate = Coord(-71250024, 42341178)

   p2.StopName = "Lasell College"

   p2.StopDuration = 120

  

   p3.Coordinate = Coord(-71187232, 42298633)

   p3.StopDuration = 43

   p3.StopName = "Mount Ida College"

   p4.Coordinate = Coord(-71197377, 42340143)

   p4.StopName = "Boston College"

   p5.Coordinate = Coord(-71310381, 42298016)

   p5.StopName = "Wellesley College"

   RoutingPoints = {p1, p2, p3, p4, p5}

   router = CreateObject("Routing.Router")

      

   router.Minimize = "Time"

   router.IncludeRestStops = true

   router.TimeBetweenRests = 5

   router.RestStopDuration = 20

   router.FuelPrice = 3.29

   router.SingleThreaded = true

      

   // Modify speed factor by link tyoe 1: slow, 4: Normal, 7: fast

   router.MajorHighwaySpeedLevel  = 4

   router.SecondaryHighwaySpeedLevel  = 4

   router.LocalHighwaySpeedLevel = 4

   router.ArterialSpeedLevel = 4

   router.LocalRoadSpeedLevel = 4

   spOpts = null

   spOpts.Fix = "First"

   spOpts.Loop = True

   path = router.Calculate(RoutingPoints, spOpts)

   if path.Error then

       Throw(router.ErrorMessage)

   // create a report

   ret = router.CreateReport({PathObj: path, OpenReport: true,

                              FileName: GetRandFileName("*.xlsx")})

   if ret.Error then Throw(ret.ErrorMessage)

   //    ret = router.ExportToExcel({FileName: GetTempFileName("*.xlsx"), OpenExcel: true})

   //    if ret.Error then Throw(ret.ErrorMessage)   

  // Display path on current map

   path.PathDisplayWidth = 60

      

   shared cc_Colors

   path.PathDisplayColor = cc_Colors.Red

   path.DisplayPath()

//    path.ClearPathDisplay()

endmacro

// simple path from an origin coordinate to a destination coordinate

macro "RoutingExample3"

   on error do

       ShowMessage(GetLastError())

       return()

   end

   // Example near Newton, MA

   OriginCoord = Coord(-71206120, 42321660)

   DestCoord =  Coord(-71164968, 42331357)

   // StopTimes = {30, 20, null, 25}

      

   router = CreateObject("Routing.Router")

      

   router.Minimize = "Time"

   router.FuelPrice = 3.29

   path = router.CalculatePath(OriginCoord, DestCoord)

   if path.Error then Throw(path.ErrorMessage)

      

   // create a report

   ret = router.CreateReport({PathObj: path, OpenReport: true})

   if ret.Error then

       Throw(ret.ErrorMessage)

   // Display path on current map

   path.PathDisplayWidth = 60

  

   shared cc_Colors

   path.PathDisplayColor = cc_Colors.Red

   path.DisplayPath()

   //path.ClearPathDisplay()

endmacro       

 

macro "CalculateTimeDistance"

   on error do

       ShowMessage(GetLastError())

       return()

   end

   finder = CreateObject("Data.Finder")

   finder.SetRegion()

   args.silent = true

   args.address = "407 Marlborough Street"

   args.city = "Boston MA"

   p1 = finder.Find("ADDRESS", args)

   args.silent = true

   args.address = "1172 Beacon Street"

   args.city = "Newton MA"

   p2 = finder.Find("ADDRESS", args)

   myRouter = CreateObject("Routing.Router")

   myRouter.Minimize = "Time"

   myRouter.MajorHighwaySpeedLevel  = 1

   myRouter.SecondaryHighwaySpeedLevel  = 1

   myRouter.LocalHighwaySpeedLevel = 1

   myRouter.ArterialSpeedLevel = 1

   myRouter.LocalRoadSpeedLevel = 1

   path = myRouter.CalculatePath(p1.Coord, p2.Coord)

   if path = null then ShowMessage("Error: " + myRouter.ErrorMessage)

   time = path.Time

   dist = path.Distance

   // ShowArray({time, dist})

endmacro

 

 

VBA

 

Attribute VB_Name = "Module1"

Option Compare Database

Option Explicit

  

Function CreatePath() As Integer

   Dim p As Variant

   Dim u, dk As Variant

   Dim units As String

   Dim opt As Variant

  

   On Error GoTo Error_handler:

  

   Set dk = CreateObject("Maptitude.AutomationServer")

  

   p = dk.RunMacro("GetProgram")

   dk.RunMacro "SetMapUnits", "Miles"

   units = dk.RunMacro("GetMapUnits", Null)

  

   Dim dP1, dP2, dP3, dP4, dP5

   Set dP1 = CreateObject("Scripting.Dictionary")

   Set dP2 = CreateObject("Scripting.Dictionary")

   Set dP3 = CreateObject("Scripting.Dictionary")

   Set dP4 = CreateObject("Scripting.Dictionary")

   Set dP5 = CreateObject("Scripting.Dictionary")

  

   With dP1

       .Add "Coordinate", dk.RunMacro("Coord", -71259994, 42298892)

       .Add "StopDuration", 30

       .Add "StopName", "Babson College"

   End With

  

   With dP2

       .Add "Coordinate", dk.RunMacro("Coord", -71250024, 42341178)

       .Add "StopDuration", 30

       .Add "StopName", "Lasell College"

   End With

  

   With dP3

       .Add "Coordinate", dk.RunMacro("Coord", -71187232, 42298633)

       .Add "StopDuration", 30

       .Add "StopName", "Mount Ida College"

   End With

   With dP4

       .Add "Coordinate", dk.RunMacro("Coord", -71197377, 42340143)

       .Add "StopDuration", 30

       .Add "StopName", "Boston College"

   End With

   With dP5

       .Add "Coordinate", dk.RunMacro("Coord", -71310381, 42298016)

       .Add "StopDuration", 30

       .Add "StopName", "Wellesley College"

   End With

  

  

   Dim P1, P2, P3, P4, P5

  

   P1 = CreateOptFromDictionary(dP1)

   P2 = CreateOptFromDictionary(dP2)

   P3 = CreateOptFromDictionary(dP3)

   P4 = CreateOptFromDictionary(dP4)

   P5 = CreateOptFromDictionary(dP5)

  

   Dim RoutingPoints

  

   RoutingPoints = Array(P1, P2, P3, P4, P5)

   RoutingPoints = Array(P1, P2)

   Dim router

  

   Set router = dk.CreateObject("Routing.Router", "")

   router.Set "Minimize", "Time"

   router.Set "IncludeRestStops", True

   router.Set "TimeBetweenRests", 5

   router.Set "RestStopDuration", 20

   router.Set "FuelPrice", 3.29

    

   Dim spOpts

'    spOpts = AddOption("Fix", "First")

'    spOpts.Loop = True

  

   Dim pth, PathRep, repOpts, ret

   Set pth = router.Method("Calculate", RoutingPoints, spOpts)

  

   Set PathRep = CreateObject("Scripting.Dictionary")

   PathRep.Add "PathObj", pth

   PathRep.Add "FileName", "c:\\temp\\zzzPath.xlsx"

   PathRep.Add "OpenReport", True

  

   repOpts = CreateOptFromDictionary(PathRep)

  

   ret = router.Method("CreateReport", repOpts)

 

   CreatePath = 1

Exit Function

Error_handler:

   MsgBox "Path calculation returned an error"

  

End Function

Function CreateOptFromDictionary(dict) As Variant

   Dim nItems, i As Integer

   Dim Key, items

   Dim options

  

   nItems = dict.Count

   i = 0

   ReDim options(nItems - 1, 1)

  

   For Each Key In dict.Keys()

       options(i, 0) = Key

       If TypeOf dict(Key) Is Object  Then

           Set options(i, 1) = dict(Key)

       Else

           options(i, 1) = dict(Key)

       End If

       i = i + 1

   Next

   CreateOptFromDictionary = options

End Function

 

Python

 

# PYTHON 3 Routing Example

import sys

import os

import traceback

import caliperpy

import ctypes

from ctypes.wintypes import HWND, LPWSTR, UINT

_user32 = ctypes.WinDLL('user32', use_last_error=True)

_MessageBoxW = _user32.MessageBoxW

_MessageBoxW.restype = UINT

_MessageBoxW.argtypes = (HWND, LPWSTR, LPWSTR, UINT)

MB_OK = 0

#

# NOTE: *****************************

# Open a map of the USA

#

dk = caliperpy.Gisdk("Maptitude")

 

p = dk.GetProgram()

try:

   dk.SetMapUnits("Miles")

   units = dk.GetMapUnits(None)

   p1 = {"Coordinate": dk.Coord(-71259994, 42298892), "StopDuration": 30,

           "StopName": "Babson College"}

   p2 = {"Coordinate": dk.Coord(-71250024, 42341178), "StopDuration": 30,

           "StopName": "Lasell College"}

   p3 = {"Coordinate": dk.Coord(-71187232, 42298633), "StopDuration": 30,

           "StopName": "Mount Ida College"}

   p4 = {"Coordinate": dk.Coord(-71197377, 42340143), "StopDuration": 30,

           "StopName": "Boston College"}

   p5 = {"Coordinate": dk.Coord(-71310381, 42298016), "StopDuration": 30,

           "StopName": "Wellesley College"}

   RoutingPoints = [p1, p2, p3, p4, p5]

   router = dk.CreateGisdkObject("gis_ui", "Routing.Router")

   router.Minimize =  "Time"

   router.IncludeRestStops = True

   router.TimeBetweenRests = 5

   router.RestStopDuration = 20

   router.FuelPrice = 3.29

   path = router.Calculate(RoutingPoints, None)

   if path is not None:

       time = path.Time

       dist = path.Distance

       ret = router.CreateReport({"PathObj":path, "OpenReport":1,

           "FileName": dk.GetRandFileName("*.xlsx")})

       retOpts = dict(ret)

       if ( not retOpts is None ) and ( 'ErrorMessage' in retOpts ):

           _MessageBoxW(0, retOpts["ErrorMessage"], "Error", MB_OK)

       else:

           _MessageBoxW(0, "Path length: " + str(dist) + " : " + "Path Time: " + str(time),

                       "Information", MB_OK)

   else:

       raise Exception("Please open a map window first")

  

except Exception as Error:

   _MessageBoxW(0, repr(error), "Information", MB_OK)

 

 

See Also:

AddLayerDB

AddTables

Calculate Tables

Caliper.Charts

CC.ModifyTableOperations

CC.Table

Clustering

Data.Finder

Data.Geocoder

PostgreSQLConnect

PostgreSQLCommand

Routing.Bands

Routing.Path

Routing.Router

Table

Utilities.Mail

©2025 Caliper Corporation www.caliper.com