Hack65.View Real-Time Traffic Data on the Road


Hack 65. View Real-Time Traffic Data on the Road

If you have a wireless Internet connection for your car PC, even a slow one, you can get real-time traffic information for any major U.S. city.

Even with all the nifty PC enhancements that you can put in your car, you probably still don't want to sit in traffic on a hot summer day sweating and wasting your time, gas, and money. There are several ways to interface with traffic data so that you can avoid bad traffic and get where you need to go before you or your car overheats.

The easiest way to access traffic data is not via a navigation program, but simply via a web browser. One of the best sites is http://www.traffic.com (see Figure 6-6). This service has sensor networks measuring traffic speeds for most major U.S. cities, and their web site provides an interactive, colorcoded map showing the state of congestion of all the major thoroughfares in a particular city. If you register for their free membership (i.e., trade your email address), you can get even more information, such as the current traffic speed on each freeway segment.

Information on how Traffic.com works can be found at http://www.traffic.com/Mobility/faq.html and http://www.traffic.com/Mobility/data.html.

Traffic.com even provides an RSS feed, updated with close-to-real-time traffic incidents. (If you use this service with the CarBot Player software [Hacks #21 and #59], you can even have the feeds read to you while you drive.)

Traffic.com is not the only good provider of traffic-related information. Not only are there other traffic sites, but the same or similar traffic information is actually available from the national, state, and city Departments of Transportation (DOTs) on their respective web sites. However, the problem with these sites is that there is no standard for how that information is provided or accessed.

Figure 6-6. The Traffic.com web site


Almost all of the traffic sites render traffic conditions as static GIF/JPG images. Some cities report only traffic incident information, while others provide complete real-time traffic flow information. Incidents are useful to know about, but their reports are delayed by the time it takes for the DOT to acknowledge them. Real-time reporting of traffic flow requires special hardware on the streets, and not all cities currently have this equipment. Real-time conditions almost always include incident reports, too. This inconsistency in freely available information has created a market for Traffic.com and other real-time traffic condition data aggregators.

I live near Seattle, and free public access to the city's traffic data is provided through the Washington State Department of Transportation (WSDOT) system. Their web page (http://www.wsdot.wa.gov/traffic/seattle) renders their traffic data and includes a lot of other useful information (Figure 6-7).

Figure 6-7. The WSDOT's Seattle Traffic web page


On this web page, you can:

  • Click on any traffic still/video camera at any major intersection and see a live image of the actual traffic conditions. Some cameras even provide a five-second AVI video of the traffic flow.

  • Click on some suburbs of Seattle and view details of city street traffic conditions.

It is all very well organized and accessible to the average user, and I have not found another home-grown metro traffic site that provides this much detail. Information on how the Seattle system works can be found at http://www.wsdot.wa.gov/traffic/seattle/questions/.

While you can access web-based traffic information directly from your web browser without having to develop any code, you will be limited to the web site's interface and access to information. Furthermore, many of these user-interface factors are not conducive to a car PC environment, especially when you're the driver.

6.5.1. My Traffic Viewer Application

The relatively low resolution of in-car PC screens makes accessing a web-based map (with its large borders and banner advertisements) while on the go inconvenient and distracting. I decided that a better way to view traffic data would be to embed a browser into a custom application that gave me more control over the user interface.

To demonstrate my idea, I wrote Traffic.exe, a C# application that polls Seattle's traffic data via FTP or HTTP and renders that data. You can download the application and its source code at http://www.oreilly.com/catalog/carpchks. As with any C# application, you'll need to have the .NET runtime installed to use it.

Unfortunately, this application (as well as my demo code) is only directly applicable to hacking Seattle's traffic data. However, it should provide valuable insight when it comes time to hack your own city's traffic web site.


Traffic.exe first pulls down an uncolored freeway map that is not populated with any congestion data (Figure 6-8, left). When you click the Process Data button, Traffic.exe retrieves the up-to-the-minute traffic information, decodes it, and appropriately color-codes the map (Figure 6-8, right).

6.5.2. Using Seattle's Raw Data

Custom traffic-monitoring applications would flourish if the information they provided was more standardized. Alas, there's little indication that a nationwide open traffic standard for all cities will be developed anytime soon, so the next best thing may be to directly use the web pages from the existing traffic web sites. Fortunately, a lot of traffic information is freely available on the Web, and with a bit of work it can be formatted for your car PC any way you wantthat's what I did with my Traffic.exe application and the raw data I was able to pull down from the WSDOT web site. This section tells you a little about this data, to help you understand how my program operates, and to help you write your own traffic program.

Figure 6-8. Traffic.exe in action


Seattle's raw traffic data is presented in a proprietary, albeit simple, format. The files can be accessed via either http://images.wsdot.wa.gov/nwflow/wireless/ or ftp://webflow.wsdot.wa.gov. Both of these URLs contain the following identical data files:


webflow.dat

Contains the "occupancy" information for a certain set of loop detector stations. Loop detectors are wire loops, about a meter square, embedded in the road. They are used to detect whether a vehicle is present over that patch of road. This file is an older data file that is about 6 KB in size.


wirelessxxx.dat

Contains the "occupancy" information for a slightly different set of loop detector stations. xxx is a version number that the WSDOT increments from time to time. This file is a newer compressed data file that is about 0.2 KB in size. The basic source code to decompress this file can be found at http://www.wsdot.wa.gov/PugetSoundTraffic/palmflow/huffman.c. (This code will need to be modified a bit before it can be used.)


webflow.sta

Describes each loop detector in webflow.dat.


wirelessxxx.sta

Describes each loop detector in wirelessxxx.dat.


/WebFlowUpdates/SysVert.bmp

A bitmap of the loop stations in webflow.dat.


/WebFlowUpdates/SysVert.XY

(X, Y) polygon coordinates of the loop stations in SysVert.bmp.


webflow.msg

A text file that describes relevant current information (incidents, construction, etc.).

As you can see, wireslessxxx.dat is much smaller than webflow.dat; however, Seattle does not provide .bmp or .XY files for wireslessxxx.dat, so if you want to use wirelessxxx.dat you will have to create your own .bmp and .XY files. For simplicity's sake, the example Traffic.exe application uses the larger webflow.dat file and the relevant .sta, .bmp, and .XY files.

You can use these data files to create your own traffic application. To get the raw data, all you have to do is open an anonymous FTP or HTTP connection to one of the data URLs and download the latest data file(s).

Paul Peavyhouse



    Car PC Hacks
    Car PC Hacks
    ISBN: 0596008716
    EAN: 2147483647
    Year: 2005
    Pages: 131

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net