Add weather to Trimble Maps Routes

This tool can be used to add weather forecast data to a Trimble Maps Route.

Trimble Route Endpoint

POST /route[?depart_time=YYYYmmdd.HHMM]

This endpoint accepts “application/json” requests with a body that contains a JSON response object from the Trimble Maps Route API that with both report types:

  "__type": "RoutePathReport:http://pcmiler.alk.com/APIs/v1.0"
  "__type": "DirectionsReport:http://pcmiler.alk.com/APIs/v1.0"

This will return a JSON response with the following structure with a data point for each waypoint in the RoutePathReport. Times are matched to the DirectionsReport leg estimated times:

{
  routes:[
    {
      points: "...", // encoded polyline
      valid_times: [...],
      rt: [...],
      rc: [...],
      t: [...],
      wspd: [...],
      wdir: [...],
      snod: [...],
      prate: [...],
    }
  ]
}

The valid_times variable is a list of UTC timestamps (seconds since epoch) that represents the best time estimate of arrival at waypoint given the information in the Trimble Maps response.

The points variable is a polyline encoded string Google Maps polyline information. This can be decoded to a list of lat/lon points that will match the lat/lon points in the RoutePathReport.

Example

Download the file res.json and issue the following curl command from a terminal:

curl -H "Content-Type: application/json" -d "@res.json" https://routecast.acmeaom.com/route > route_forecast.json

Route From Points

A route is most simply a list of [lat, lon, time]. This endpoint can be used to query a route using a JSON array of [lat,lon,time] arrays where the time value in the array is time from departure so the first point should start at time 0. depart_time is an optional query parameter in the format YYYYmmdd.HHMM UTC, default value is current time.

POST /route_from_points[?depart_time=YYYYmmdd.HHMM]

Example

With a current time of Wed 03 Aug 2022 18:27:08 UTC you should see the following output:

temperature will be 17.6678 C when you arrive at point [40.272097, -105.556849] at 20220803 18:27:00
temperature will be 18.319 C when you arrive at point [40.275028, -105.564764] at 20220803 19:13:40
temperature will be 18.7466 C when you arrive at point [40.270215, -105.578737] at 20220803 20:00:20
temperature will be 17.6446 C when you arrive at point [40.268147, -105.587308] at 20220803 20:37:00
temperature will be 11.2602 C when you arrive at point [40.267442, -105.611906] at 20220803 21:00:20

Route from cached driving directions route

If you’ve used /driving_route to lookup a route, you can submit this route object to /route_from_route for a forecast lookup.

/driving_route will return an object with the following structure:

Error codes from /driving_route:

HTTP Code Reason
460 Route lookup from map engine failed
461 Route mapping failed/route too short

Route from session

When you make a call to /driving_route a session with the origin/destination will be saved. You can use the session_id to get updates to the route without passing around the route object with the following endpoint:

/route_from_session?session_id={session_id}

Example

Azure maps adjusts route estimates based on current traffic conditions. You can use the session id to get an updated route status based on a current position and optionally save this new current position as the starting point for your session:

/route_status?session_id={session_id}&current_point={lat,lon}[&update_session=true]&[route_through=true]

This will use the destination saved in the session with the current_point as the start point and return the Azure maps route summary data as follows:

/route_status and /route_from_session will return 403 if the session id is no longer valid.

If update_session is included then the session will be updated with current_point as the origin for subsequent calls to /route_from_session. By default update_session is not included, the session will not be updated.

If route_through is included the route will attempt to match the exact route that is stored in the session by routing through a selection of way points. By default route_through is not included and the route will be queried with only current_point to the destination in the session and the resulting route may be different than the route saved in the session.

Data Dictionary

Variable Type Definition
rt array Road Temperature (C)
rc array Road Condition (0-10)
t array Air Temperature (C)
wspd array Wind Speed (m/s)
wdir array Wind Direction (0-360)
snod array Snow Depth (m)
prate array Precip Rate (m/s)
points encoded str Polyline encoded string of route points
valid_times array Timestamp of weather forecast, derived from DirectionsReport (seconds since epoch)
ptype array Precip Type 1=Wet,2=Mix,3=Frozen
delay_risk array Delay risk score decimal 0-3
rc_colors array Colors for the road condition values that match the table below

Road Condition Types

Code Value
DRY 0
WET_SNOW 1
WET_MELT 2
WET_RAIN 3
WET_PREV 4
MIXED_FRZR 5
MIXED_SNOW 6
MIXED_MELT 7
FRZ_SNOW 8
FRZ_PREV 9
FRZ_BLKICE 10
Code Definition
WET_SNOW “Wet due to snow melting on contact”
WET_MELT “Wet due to melting snow”
WET_RAIN “Wet due to rain”
WET_PREVIOUS_RAIN “Patches of wet due to previously fallen rain”
MIXED_FREEZING_RAIN “Mixed (or slushy) conditions due to freezing rain”
MIXED_SNOW “Mixed due to snow beginning to freeze”
MIXED_MELT “Mixed due to slushy melting snow”
FROZEN_SNOW “Frozen from snow accumulating”
FROZEN_PREV_PRECIP “Patches of frozen from snow that fell previously”
FROZEN_BLKICE “Potential for patches black ice (melted snow with refreezing)
Color Code Value
“#ffffff” DRY 0
“#90EE90” WET_SNOW 1
“#32CD32” WET_MELT 2
“#008000” WET_RAIN 3
“#006400” WET_PREV 4
“#800080” MIXED_FRZR 5
“#9932CC” MIXED_SNOW 6
“#EE82EE” MIXED_MELT 7
“#87CEFA” FRZ_SNOW 8
“#00BFFF” FRZ_PREV 9
“#d3d3d3” FRZ_BLKICE 10