Introduction

In this tutorial we will build a simple routing application, based on ADAS information and the Telogis.GeoBase.Adas namespace, to display the varying gradients of a road along a route. As an example, in the image below, the red sections of the route indicate an incline (in the direction of travel), the green sections indicate a decline, and the yellow sections indicate that the road is level (that is, within ±0.5°).

 ADAS Data

ADAS Information

ADAS stands for Advanced Driver Assistance Systems. An ADAS data file can be incorporated with the GeoBase platform to provide useful information for both the driver and in-vehicle safety systems, allowing for a more safer driving experience and environment.

Note: ADAS information currently only includes road slope information. Other ADAS information is expected to become available in the future.

The Telogis.GeoBase.Adas namespace provides classes to represent and query ADAS information. Namely:

  • AdasInfo - which represents ADAS information for a street link.
  • AdasQuery - used to obtain ADAS information for a given street link.

AdasInfo

The AdasInfo class provides the following useful properties:

  • LinkID - a unique value identifying the street link
  • Points - a series of measurement points along the street link. The slope of the road at location Points[n] can be found at Slopes[n] (see below).
  • Slopes - each element of the Slopes array describes the slope of the road at the location specified by the corresponding element in the Points array. The slope is measured in degrees: positive values indicate an incline; negative a decline.

AdasQuery

The AdasQuery class provides the QueryLink method to retrieve ADAS information for a given street link; the street link is specified by link ID.

Tutorial Overview

The main purpose of this tutorial is to demonstrate how to use ADAS information with the classes from the Telogis.GeoBase.Adas namespace. We will build a simple routing application, comprising a map control and a fixed route. The route will be displayed on the map with sections of the route colored according to the section's slope. For this tutorial, and to keep things simple, we will use just three colors: a red section of the route indicates an incline, a green section of the route will indicate a decline, and a yellow section will indicate that the road is level, to within ±0.5°.

To retrieve the slope value from a section of the road, we will call the AdasQuery's QueryLink method with the section's link ID, to return an AdasInfo, where, as mentioned above, each element of the Slopes array describes the slope of the road at the location specified by the corresponding element in the Points array.

We will split the tutorial into three steps:

  1. Add a map control
  2. Create a route
  3. Re-color route according to road gradient

Prerequisites

You will need an ADAS data file to complete this tutorial. Sample ADAS data is available in the Sample Data section. Download the NAVTEQ_USA_ADAS_110209-1220_LA_Sample.zip file and place it in the same folder as your map data file.

Step 1 - Add a map control

Open a new instance of Visual Studio, and add geobase.net.dll as a reference.

Add a map control to the form. Rename the map control to 'mapMain', and set the 'Zoom' property to 7. Change the CenterLat, and CenterLon properties to:

  • CenterLat: 34.06411
  • CenterLon: -118.25375


That's all there is to this step.

Step 2 - Create a route

In this section we'll write the code to create:

  • a fixed route
  • a multirepository for the data files (map and ADAS data)
  • a Directions object for the route
  • a renderer list to display the route (and later, the re-colored route) on the map


Before we create the route, change to the code view in Visual Studio, and add the following using statements:

using Telogis.GeoBase;
using Telogis.GeoBase.Routing;
using Telogis.GeoBase.Adas;
using Telogis.GeoBase.Repositories;

Next, add the following code to the Form1 constructor, just after the InitializeComponent() statement. Ensure that your data files are located as per the parameter to the 'new MultiRepository()' statement. In this example, our data files are stored at 'C:\GeoBase\Data'.

//Add start and stop route points
RouteStop rsStart = new RouteStop(new LatLon(34.00102,-118.27779));
RouteStop rsEnd = new RouteStop(new LatLon(34.07787,-118.23342));

//Set repository - this repository will include both map and ADAS data
MultiRepository mr = new MultiRepository(@"C:\GeoBase\Data\");
Repository.CurrentThreadRepository = mr;

//Calculate route			
Route myRoute = new Route(rsStart, rsEnd);

//Get directions
Directions myDirs = myRoute.GetDirections();

//Add directions to map    
RendererList rList = new RendererList();
rList.Add(myDirs);

//Add rendererlist
mapMain.Renderer = rList;

And that concludes step 2. You can build and run the application as it stands so far - you should see a map centered on LA, with a route displayed along the Harbor Freeway, as shown in the image below.

ADAS - route only

Step 3 - Re-color route according to road gradient

In this section we will add the code to re-color the route depending on the road's gradient. This section comprises one class, AdasRenderer, which implements the IMapRenderer interface. To implement the IMapRenderer interface, we will add code for both Render(), and RequiredRenderModes(). RequiredRenderModes() simply tells the renderer when to render our images, within its three-stage render process, onto the map. For this application, we will select rendering to occur 'pre-labelling' - that is, map labels will be placed on the map after we have re-colored the route. The Render method will be responsible for the rest of the work of re-coloring the route according to the slope.

To begin with, add the AdasRenderer class as shown below. Notice that the RequiredRenderModes method has been implemented with the read-only RenderMode property being set to PreLabelling.

public class AdasRenderer : IMapRenderer{

		
	public void Render(Graphics graphics, RenderContext rc) {
	
	}

	public RenderMode RequiredRendermodes {
		get {
			return RenderMode.PreLabelling;
		}
	}
		
}

In section 2, we created a route, and obtained the Directions from that route to display on the map. The Directions class provides a GetDirectionLinks() method from which we can obtain a list of DirectionLinks, and thus providing us with the necessary link IDs that will be used to find, ultimately, the slopes of the individual sections of the route. For that reason, we will need to instantiate the AdasRenderer with these Directions. Add the following code and constructor to the AdasRenderer class:

DirectionLink[] myDirLinks;

public AdasRenderer(Directions dirs){
	myDirLinks = dirs.GetDirectionLinks();
}

The render method will perform the following tasks:

  • set the Pens to be used for coloring the route
  • create a list of link IDs from the direction links
  • create a list of AdasInfo using the list of link IDs
  • derive the direction of the slope for each point of the route from each AdasInfo

All of the following code should be added to the Render() method.

Add the following code to set the Pens to be used for coloring the route. If the slope value is positive, then the section of the route is on an incline, and we'll re-color it red. If the slope value is negative, then we'll re-color the route green to indicate a decline. To indicate that the road is level, we'll re-color the route yellow. For this example, we have chosen an arbitrary value, levelBand, of ±0.5°.

//Set pen's line width
float lineWidth = 15 - (float)rc.Map.Zoom;

//Set band at which gradient is considered level (0.5 degrees in this example)
float levelBand = 0.5F;

//Set pen's colors
Pen inclinePen = new Pen(Color.Red, lineWidth);
Pen declinePen = new Pen(Color.Green, lineWidth);
Pen levelPen = new Pen(Color.Yellow, lineWidth);

Add the following code to create a list of link IDs from the direction links:

HashSet<ulong> linkIds = new HashSet<ulong>();

foreach (DirectionLink link in myDirLinks) {
    if (!linkIds.Contains(link.LinkId)) {
        linkIds.Add(link.LinkId);
    }
}

Create a list of AdasInfo using the list of link IDs:

List<AdasInfo> adasData = new List<AdasInfo>();
foreach (ulong linkID in linkIds) {
	AdasInfo[] info = AdasQuery.QueryLink(linkID);
	adasData.AddRange(info);
}

Derive the direction of the slope for each point of the route from each AdasInfo:

foreach (AdasInfo info in adasData) {
    int nPoints = info.Points.Length;
    Point[] points = new Point[nPoints];
    for (int idx = 0; idx < nPoints; idx++) {
        int x;
        int y;
        rc.Map.LatLontoXY(out x, out y, info.Points[idx]);
        points[idx] = new Point(x, y);
    }

    for (int idx = 1; idx < nPoints - 1; idx++) {
        //Check if slope is within the level band
        if (Math.Abs(info.Slopes[idx]) < levelBand) {
            graphics.DrawLines(levelPen, points);
        } else {
            graphics.DrawLines(info.Slopes[idx] > 0 ? up : down, points);
        }
    }
}

That concludes the coding for the AdasRenderer class. Before we test the application, we still need to tell the map to use our AdasRenderer. Add the following code in the Form1 constructor, just before the 'mapMain.Renderer = rList;' statement.

//Add ADAS Info to renderer list
AdasRenderer ar = new AdasRenderer(myDirs);
rList.Add(ar);

Build and run your application. You will be presented with the screen as shown below. Red sections of the route indicate the road is on a incline; green indicates an decline. If the route is colored neither red or green, then no information is available for that part of the route.

ADAS Complete

Published, Feb 10th 2011, 00:57