Proof of Concept 911 Viewer

This post is more than 2 years old.

About two weeks ago a fellow techie in town clued me in a web page run by my local government that posted the latest 911 information. This is filtered to just traffic information but still it was pretty fascinating to watch. I contacted them to see if they had a non-HTML version but, of course, I never heard back. (Is it just me or do most sites just freaking ignore contacts??) I decided to see if I could play with this data a bit and get a 'clean' view of the data. Here is what I came up with.

First I needed a way to parse the data on the page. It seemed to follow a pretty standard format. The table always had four columns and the data seemed to be published in a consistent manner. For the heck of it I decided to create a Yahoo Pipe to parse the HTML. This was completely unnecessary, but it was fun, and that's all that matters. Unfortunately I seem to have lost the pipe online, but the URL still works. (Edit in 20220 - sorry - no it doesn't.)

select * from html where (url="http://67.32.159.27/webcad/webcad.asp" and xpath='//table[@border="0"]/tr[@bgcolor="#FFFF99"]') or (url="http://67.32.159.27/webcad/webcad.asp" and xpath='//table[@border="0"]/tr[@bgcolor="#99FF99"]'

As you can see, I use the core URL for the page and then grab the table rows. Since the table rows alternate colors I check for both. Again, this is a bit silly. ColdFusion can easily XPath too. But I figured, what the heck?

The next step was to loop over the JSON result and parse out the data. For the most part this was trivial - I just had to account for - and remove - a few weird high ASCII characters that got in there somehow. Once that was done, I checked my database to see if a report with the same time, address, and type already existed. If not, I did an insert. As all of this is pretty rudimentary I assume folks don't want to see the code. Let me know if otherwise. I set that up as a scheduled task to run every 5 minutes. I also wrote a quick CFM that made use of my Google Geolocator CFC. This parses addresses with no longitude/latitude information, looks it up, and updates the database.

So I let this run for a week or so and then created my first report using CFMAP. My first report simply got all the data and mapped it:

As you would expect, everything occurs over a street, and occur over streets I can promise you are pretty busy. The code for this is rather simple - get all the data (with a mild bit of cleanup) and select a custom icon based on the 911 incident type:


<cfquery name="getdata">
select	longitude, latitude, type, incidenttime
from data
where
	(longitude !='' and latitude != '')
	<!--- fixes one bad row --->
	and longitude < -88
	and incidenttime is not null
</cfquery>

<cfoutput>#getdata.recordcount# items.</cfoutput>

<cfmap centeraddress="Lafayette, LA" width="900" height="900" zoomlevel="12" showcentermarker="false">

	<cfloop query="getdata">
		<cfif findNoCase("vehicle accident", type)
		or
			  findNoCase("stalled vehicle", type)>
			<cfset icon = "icons/car.png">
		<cfelseif findNoCase("traffic control", type)
		or
				  findNoCase("traffic signal", type)>
			<cfset icon = "icons/stop.png">
		<cfelseif findNoCase("fire", type)>
			<cfset icon = "icons/fire.png">
		<cfelseif findNoCase("hazard", type)>
			<cfset icon = "icons/hazard.png">
		<cfelse>
			<cfset icon ="">
		</cfif>

		<cfmapitem latitude="#latitude#" longitude="#longitude#" markerwindowcontent="#type#<br/>#dateFormat(incidenttime)# #timeFormat(incidenttime)#" markericon="#icon#">
	</cfloop>

</cfmap>

So this was kinda neat... but I wanted to see something else. I thought - what if we could take this data, and plot it over time. I took a look at the Google Map API and reviewed how to add, and remove, markers. I then whipped up jQuery and ColdFusion code to "group" my reports into hours. I then set it up so that it would run a block of data every second or two. The result? A "movie" of 911 activity:

http://www.raymondcamden.com/demos/2015/traffic.swf (warning, large Flash movie)

I stopped the Jing recording after a few days, but obviously it goes on to today. You can see, sometimes, some obvious upswings at rush hour. Not surprising, of course, but fun as heck to watch. Unfortunately I've run out of time so I'll post the code to this demo tomorrow.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for HERE Technologies. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by cf_gal posted on 1/20/2010 at 4:15 AM

This is awesome...great job! Especially the ability to view the events over time. Thanks for sharing this. I'm looking forward to viewing the sample code.

Comment 2 by figital posted on 1/20/2010 at 4:24 AM

Nice job Ray. Looks like you'll be getting some tweetage.

Comment 3 by t0nic posted on 1/20/2010 at 6:24 AM

I can image the discussion at the police department: "Hey, we can do this? Why don't we have this in the station?!"

Comment 4 by Simon posted on 1/20/2010 at 6:34 AM

Google maps. The modern day graph.

Comment 5 by teaman posted on 1/20/2010 at 6:43 AM

This is great Ray! This should have application to lots of scenarios. I would also love to see what your Google Geolocator CFC does. Any chance of posting that code, too?

Comment 6 by Raymond Camden posted on 1/20/2010 at 8:24 AM

Glad yall liked it.

@teaman: Here is the CFC: http://googlegeocode.riafor...

Comment 7 by Gary Gilbert posted on 1/20/2010 at 2:48 PM

Hey Ray pretty cool idea. I can image it's much easier to digest the data in the form of a map than in a simple color coded table.

Its a pitty that the 911 folks simply ignore inquiries..

Comment 8 by Lola LB posted on 1/20/2010 at 5:02 PM

Wow . . . this is cool! This could be very useful in disaster situations, as an aid for decision makers to decide where best to allocate their resources.

Comment 9 by Connor Middleton posted on 1/20/2010 at 8:06 PM

Awesome job Ray, can't wait to learn from your code.

Comment 10 by John Gag posted on 1/20/2010 at 9:24 PM

I wonder if any other areas have similiar data available. This looks like something pretty fun to play with :)

Comment 11 by Don Blaire posted on 1/20/2010 at 10:08 PM

Enjoyed this post. Sure would like to learn more from your code. Could you share the full code for this?

Comment 12 by Raymond Camden posted on 1/20/2010 at 10:10 PM

Planning on it. Have a small blog post around noon, and will do the code post later in the afternoon. I'm also considering a basic AIR application.

Comment 13 by Raymond Camden posted on 1/21/2010 at 4:27 AM
Comment 14 by Tim posted on 5/12/2010 at 8:38 PM

Working on a similar project, but would like to default a specific mapped item to "showmarkerwindow". Setting this attribute to "true" doesn't seem to do much of anything. Clicking the marker brings up the markerwindowcontent, but I want this to display onLoad.

Any thoughts? CF or google issue?

Comment 15 by Raymond Camden posted on 5/13/2010 at 5:30 AM

I'd probably look at the Google Maps API to see if you can force it on.

Comment 16 by Bernhard posted on 10/2/2012 at 9:51 PM

Hi there,
I ran into the same issue. Set showmarkerwindow to true but it doesn't show the marker window onLoad. Any news on that? It would be nice if it'd be possible to set some certain markers to show the window content onLoad.

Thank u very much and have a nice time
Bernhard