Articles

All the roads in Canada

In Uncategorized on May 6, 2013 by Matt Grande

If you’re just here for the image, click here (10638×9101, 1.17MB). If you want more information, please read on!

I recently saw a map of Oregon containing only the roads, and nothing more.  I thought it was really interesting how you could see where the population centres and natural features (lakes, mountains, etc) were.  I decided to try something with Canada.

The first challenge was finding a dataset containing all the roads in Canada. Luckily, it was on StatsCanada’s website, but it took longer than expected to find.

I opted for the GML format, since it’s the one I’m most familiar with.  The full file is a fairly large 1.9GB.  Here’s a sample of one road, Wilcox Street in Hamilton, Ontario:

<gml:featureMember>
<fme:lrnf000r12g_e gml:id="id00987e75-8fb2-4224-8e82-f2b97dd86307">
<fme:NGD_UID>4677289</fme:NGD_UID>
<fme:NAME>Wilcox</fme:NAME>
<fme:TYPE>ST</fme:TYPE>
<fme:CSDUID_L>3525005</fme:CSDUID_L>
<fme:CSDNAME_L>Hamilton</fme:CSDNAME_L>
<fme:CSDTYPE_L>C</fme:CSDTYPE_L>
<fme:CSDUID_R>3525005</fme:CSDUID_R>
<fme:CSDNAME_R>Hamilton</fme:CSDNAME_R>
<fme:CSDTYPE_R>C</fme:CSDTYPE_R>
<fme:PRUID_L>35</fme:PRUID_L>
<fme:PRNAME_L>Ontario</fme:PRNAME_L>
<fme:PRUID_R>35</fme:PRUID_R>
<fme:PRNAME_R>Ontario</fme:PRNAME_R>
<fme:CLASS>23</fme:CLASS>
<gml:curveProperty>
<gml:LineString srsName="_FME_0" srsDimension="2">
<gml:posList>7197110.1 878145.377099998 7197136.3143 878156.274300002</gml:posList>
</gml:LineString>
</gml:curveProperty>
</fme:lrnf000r12g_e>
</gml:featureMember>

The most important piece of information in there, for my purposes, is the <gml:posList> tag.  In this case, the data is stored as pairs of Eastings & Northings.  This means that for the above road, it travels from 7197,110 metres East and 878,145 metres North of the origin to 7,197,136 metres East and 878,156 metres North of the origin.

I decided to write a script to extract only the data I needed.  Essentially:

if (line.StartsWith("<gml:posList>"))
{
    outputFile.WriteLine(line);
}

This brought the file size from 1.9GB to 448MB, and the number of lines from 49,352,141 to 1,983,127.

With this smaller file, I could parse each data point to find the boundries.  This helped me determine the file size to use.  I used a ratio of 500 metres per pixel which, I felt, gave a good balance between detail and file size (although it is quite large, still).

Now that I had all the boundaries and all the points, I was able to plot them on an image using .Net’s graphics library.  A few dozen lines of code, and a few seconds of processing, and I had my map.

Code will be relased on my BitBucket shortly. Stay tuned!

Articles

HamOntFire – Visualizing @HFS_Incidents

In .Net, Hamilton on January 14, 2013 by Matt Grande Tagged: , , , , ,

Awhile back, I came across the @HFS_Incidents twitter account. It broadcasts all of the calls that Hamilton Fire Services responds to.

Being an Open Data guy, I was pretty happy to see this, but I thought Twitter wasn’t the best format. If I see an event, I might have no idea where it refers to. “0 Block GERTRUDE ST” isn’t helpful unless you already know where Gertrude Street is.  I also thought that this might be a good opportunity to get my hands dirty with Google Maps, Web Sockets, the Twitter API, and image generation.

The format of the tweets was pretty easy to parse, so I decided to throw together a few services and map the data out. And with that, HamOntFire was born.

At a high level, here’s what’s happening:

  • SuperWebSocket is constantly polling the Twitter API for new tweets
  • When new tweets are found…
    • I parse the data into an object (mostly to get the address into a Google-appropriate format)
    • I geocode the location using Google’s Geocoding API
    • I store the data in RavenDB
    • The event is pushed to the browser
  • The browser displays the tweets using Google Maps.

This was all fairly easy, with one exception: Both RavenDB and SuperWebSocket are dependent on Json.Net (Newtonsoft’s fantastic Json parser which has become the de facto standard), but each required very different versions (=4.0.8 and &ge;4.5.4, respectively). After some research, I discovered that this was easy to take care of in .Net, thanks to binding redirects:

</pre>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.6.0.0" newVersion="4.0.8.0" />
 </dependentAssembly>
<pre>

This says “For any versions of Newtonsoft.Json between v0.0.0.0 and 4.6.0.0, just use version 4.0.8.0.”

Once that was taken care of, everything else was a piece of cake.

You can check out the site for yourself here, and check out the code on BitBucket here.

Post Script: I’m also trying to come up with other statistics to display on the Stats page. If you can think of any, please let me know!

Articles

CoderCamp

In Uncategorized on November 23, 2012 by Matt Grande Tagged:

So I haven’t really talked much about CoderCamp.  I think it’s high time that I do.

What is CoderCamp?

CoderCamp is an unconference in the same spirit as BarCamp. We started organizing them in Hamilton in response to demand for a more skill-building and code-focused event for software developers to attend. StartupDrinks allows us to get to know one another andDemoCamp allows us show off what we’ve built and get feedback from the community, but we were missing an event that’s for coders and focused on software development.

CoderCamp is for developers to learn techniques and technologies from one another in a casual setting. We meet to talk about coding, to learn from each other, and get better at what we do in the process. You don’t have to give a talk to attend, but we welcome you to come, talk and share what you know as well.

Can you dumb it down a bit?

Nerds get together and watch short, usually about five minute, presentations about programming, technology, etc.  It’s a good time.

Sounds awesome.  When’s the next one?

As of this writing, December 6 at Chester’s Beers of The World, in Gore Park.  We usually meet at 6:30 and get started at 7.  If December 6 has come & gone, check out codercamp.org for more info.

I have something cool to present!

Cool!  Contact myself, or one of the other organizers.  If you don’t know any of us, just show up with your demo! There’s always room for more!

See you December 6!

Articles

Grande.Pluralizer is finally properly open source.

In Uncategorized on September 6, 2012 by Matt Grande

I’ve finally put my Pluralization engine onto a DVCS.  This will make many people happy.

I’ve chosen to put it on BitBucket.  This will make many people unhappy.

I chose BB over GitHub for two reasons:

  1. BB seems better at Mercurial support (I prefer Hg to Git, but that’s another topic altogether)
  2. I prefer BB’s UI.  I seem to be in the minority on this one, but I find BB to be nicer to use.

So, if you like Grande.Pluralizer, please download it from BitBucket.  If you come across any errors, or things you would like to see, either issue a pull request or add it to the issue tracker.

Have fun!

https://bitbucket.org/mattgrande/grande.pluralizer

Articles

Doors Open Hamilton 2012

In Hamilton on May 1, 2012 by Matt Grande Tagged: , ,

Man, it’s been a long time since I’ve posted.  I’ve got other stuff that I could post, but I need to pretty it up for mass consumption yet.

Anyway, back to content.  I was surprised and dismayed that the Doors Open Hamilton website didn’t have a map of the featured sites on it.  So I created one. Check it out here.

Update: I’ve been mentioned on Raise The Hammer! Life Goal: Complete.

Articles

Thoughts on REST: Who gives a shit?

In .Net on August 9, 2010 by Matt Grande Tagged: , ,

I feel like I’ve come to a new understanding of REST.

I’ve long been an evangelical supporter of REST. I’ve felt that Controllers should have, at most, the Seven Actions (List, Show, Edit, Update, New, Create, Delete).

But no longer…

I’m currently working on a project that had a normal, everyday requirement. Purchase Orders can be edited, and they can also be closed. From the Pure-REST point-of-view, I have two options: A convoluted Update action that does two things or a creating a specific PurchaseOrderClose controller that does one highly-specific thing.

Instead, I opted to do something terrible and dangerous…

I added a Close method to my PurchaseOrder controller. I added a custom route (/PurchaseOrders/{id}/Close). The world didn’t explode, and the API is still easy to understand.

It’s a simple lesson, but one that’s often hard-learned: To every rule, there is always an exception. Always err on the side of cleaner code.

/// <summary>
/// This is it.  This is the one that will infect your soul, curve your spine,
/// and keep the country from winning the war. 
/// </summary>
public ActionResult Close(int id)
{
	var po = _poRepository.Close(id);
	return View(po);
}

Articles

Some Simple NUnit Code Snippets

In .Net on November 11, 2009 by Matt Grande Tagged: , , , ,

I decided to learn how to write code snippets and wrote a couple quick ones to help out my NUnit testing. You can grab them here.

What’s in these snippets?

Just a couple quick & easy Assert completers. Hopefully these will help you learn how to write your own (better) snippets.

  • ae – Assert.AreEqual(expected, actual);
  • ait – Assert.IsTrue(true);
  • aif – Assert.IsFalse(false);

How to install snippets

Copy and paste the XML from the link above and save it in a file with the extension .snippet. I’d recommend saving it in the default code snippets folder (C:\Users\lskywalker\Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets). Then, in Visual Studio, go to Tools -> Code Snippets Manager…, and click Add. Navigate to the file you saved, and you’re done!

Neat! Where can I learn more?

Everything I learned, I learned from the MSDN articles about code snippets.

Good luck, and happy coding.

Follow

Get every new post delivered to your Inbox.