Friday, September 11, 2015

Fetching environmental data from Meso West API version 2

In few months the MesoWest group will depreciated their MesoWest data API version 1 and fully moving over version 2. The Meso West data API 2 have been in the production for most of this year. The API v2 has significantly faster and more useful than version 1 and well as increased response time and availability including accumulated precipitation, simple station statistics, and climatological data requests.

Here is the code snippet to extract data variables using jQuery in JSON format. 
 $.getJSON('http://api.mesowest.net/v2/stations/nearesttime?callback=?',  
      {  
           state:'ca',  
           county:'Los Angeles,San Diego,',  
           latestobs:1,  
           status:'active',  
           token:'API_TOKEN_PROVIDED_BY_MESOWEST_GROUP',  
           within:15, //Observations with in past 15 min  
           vars:'air_temp,relative_humidity,wind_speed,wind_direction',  
           obtimezone:'local'  
      },  
      function (data)  
      {                       
        for(var i=0;i<data.STATION.length;i++)  
           {       
                //check if all stations contain all the observation we need  
                if((data.STATION[i].OBSERVATIONS.hasOwnProperty("air_temp_value_1"))&& (data.STATION[i].OBSERVATIONS.hasOwnProperty("wind_speed_value_1"))&&  
                     (data.STATION[i].OBSERVATIONS.hasOwnProperty("wind_direction_value_1"))&&(data.STATION[i].OBSERVATIONS.hasOwnProperty("relative_humidity_value_1")))  
                {  
                     var stn = data.STATION[i];  
                     var dat = stn.OBSERVATIONS;  
                     var stnInfo =stn.NAME.toUpperCase();  
                     var elev=parseInt(stn.ELEVATION);                                                         
                     //displaying air temperature from all stations   
                     console.log(Math.round(dat.air_temp_value_1.value));                          
                }  
           }  
  })  
 .done(function()  
 {  
 })  
 .fail(function()  
 {  
      alert("Could not access the MesoWest Data!");  
 });  


0 comments :

Post a Comment

 

© 2011 GIS and Remote Sensing Tools, Tips and more .. ToS | Privacy Policy | Sitemap

About Me