Weather Perl Program
UPDATE 280135ZAUG2009: made some massive improvements!
So I found some inspiration to start coding today and ended up writing a pretty cool little Perl program that takes a latitude/longitude coordinate,
goes through a large list of ZIP codes and finds
the ZIP code nearest the provided grid coordinate. Then it uses the Weather::Google
Perl module to find the current conditions for that grid.
- Make it faster. Right now it loops through every single ZIP code no matter how far away they are. What I'm thinking is I will partition the US into
chunks and do a quick guess of what region you fall into, then subpartition that as well. If I split the US into 10 chunks, then split those into 10 more
subchunks, you should see a performance gain of almost 10^2.
- Make it an AJAX web application. I keep looking at AJAX webapps and thinking how cool they look, then I try to follow the W3Schools manual and give up.
Can it really be that hard, or am I just a born quitter? In any case, I want this to be a cool webapp.
- Support MGRS/UTM coordiates. This means conversions, which shouldnt' be too hard, which means some loss of precision. The database I'm using isn't
perfect anyways so it'll have to suffice.
- As indicated at the top of the page, I did indeed make this idea into a webapp.
- MGRS and UTM are now supported through the use of Geo::Coordinates::UTM.
users simply won't have input validation, but the webapp will be otherwise fully available for them.
- I spent a lot of time working on optimization. My original plan for an algorithm seemed beautiful in my head, but it just wasn't working the way I wanted
in practice so I ended up breaking the database into chunks by state. The master database contains a list
of each state with the average latitude and longitude for ZIP codes in that state. If this algorithm sounds like a hackjob to you - it is. But it
seems to be working so far. Please let me know if you find a way to trick it.
- The webapp removes support for Weather::Google. I know, I liked Weather::Google too, but I ran into some problems and got to thinking. That thinking made
me realize that instead of pulling weather data for the user I could instead provide some links to weather websites. I only have
Weather.com, NOAA, AccuWeather,
and Google being generated right now. If there's a good weather website you think should be listed let me know.
Original Version: Download. I use Strawberry Perl on my Windows computer. You'll probably need to use CPAN to
install Weather::Google and
Second Version: Download. This one requires Geo::Coordinates::UTM
and maintains the dependencies from the previous program. This distribution also includes new, smaller databases and the Perl program I wrote to generate those small databases.
Chris Michels page on latitude/longitude distance calculation was helpful in creating this program.