The Problem: Batch processing of German postal code locations
It struck me just how challenging this would be only a few years ago. I would have first needed to find some sort of German post office guide to even figure out which towns held each of these postal codes, and I would have then needed to find a detailed atlas of Germany to infer the latitude/longitude pairs of each town. Not at all fun.
I. Moving the Excel data to MATLAB
From within MATLAB, I double-clicked on the spreadsheet that my client provided, and MATLAB gave me an interface like what you see at right. (I'm not using actual screenshots of this step since there are other sensitive data on that spreadsheet.) With a few more mouse clicks, I was able to isolate only the column or two that interested me, bring that into MATLAB, and auto-generate a function that makes all future imports from this spreadsheet (if I need them) a breeze. So, my postal codes are in my analysis environment, and I've only been at it for about 2 minutes. So far so good.
One small hiccup that I next encountered was that the postal codes in the Excel spreadsheet were represented as numbers instead of strings. This means that both in Excel and in MATLAB, my postal codes looked like 1097 instead of the '01097' that I wanted. I encounter these cases (where Excel is too clever for its own good and auto-converts the data incorrectly) all the time, and I find it easiest to fix within MATLAB. With one command like:
II. Getting latitude/longitude data from the Google Geocoding API
- Free, within certain usage quotas and licensing requirements that I think I'll meet once the project is finished.
- Global, so that German postal codes are just as easy as any other country's.
- Automated, just a web service like any other.
III. Parsing JSON (with the aid of MATLAB Central)
IV. Putting it all together
I then pressed "run" and made myself some coffee. By the time it was ready, I had my results!
In all, then, it was a fun morning. I just couldn't believe how easy it is in this internet-driven age both to find information that would have been obscure just a few years ago and to pick up the tools and skills needed to access and manipulate this information.