Doppler Radar

Description:

This is an app that will display the current doppler radar picture for any given zip code.  The images come from the Weather Channel web site.  The size of the image can be toggled between large and small versions.

The program has two methods which do all the work.  The first is GetRadarId().  This method takes the requested zip code and finds the three letter identifier for the image used by the Weather Channel to name the jpg files for the doppler images.  An HttpWebRequest/Response is used to get the raw html.  Then a StreamReader reads the html one line at a time to find the line that contains the required info.

private void GetRadarId(string zip)
{
try{
string url = "http://www.weather.com/weather/local/"+zip;
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create
(url);
HttpWebResponse ws = (HttpWebResponse)wr.GetResponse();
Stream str = ws.GetResponseStream();
StreamReader sr =
new StreamReader(str);
string line = " ";
while(line.IndexOf("mapURLPre") == -1){
line = sr.ReadLine();
}
string[] tokens = line.Split(new char[] {'_'});
radarid = tokens[2].Substring(0,3);
}
catch(Exception ex) {}
}

After the radar id
is found, GetDoppler() downloads the appropriate jpg from the website. The picture box image is created using the static Image.FromStream() method which saves you from having to create a file. 

public void GetDoppler()
{
try{
string url = "http://maps.weather.com/web/radar/us_"+radarid+"_closeradar_"+imagesize+"_usen.jpg";
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse ws = (HttpWebResponse)wr.GetResponse();
Stream str = ws.GetResponseStream();
pictureBox1.Image = Image.FromStream(str);
byte[] inBuf = new byte[100000];
int bytesToRead = (int) inBuf.Length;
int bytesRead = 0;
while (bytesToRead > 0) {
int n = str.Read(inBuf, bytesRead,bytesToRead);
if (n==0)
break;
bytesRead += n;
bytesToRead -= n;
}
this.Text = "Doppler for: " + currentzip;
}
catch(Exception ex){Console.WriteLine(ex.ToString());}
}

This should be used for demonstration purposes only.  The Terms of Use on the Weather Channel website are quite clear about reproduction and redistribution of their copyrighted images.

Requirement:

Requires Beta 2 .NET SDK


Similar Articles