找回密码
 注册
Simdroid-非首页
查看: 92|回复: 1

获取气象天气的Matlab代码(自写,能运行)

[复制链接]
发表于 2014-2-13 14:42:12 | 显示全部楼层 |阅读模式 来自 天津
%function read_weatherNET
%Author: Sqliu
%Date:2014-2-10
clc;
clear;
close all;
try
   xDoc=xmlread('http://flash.weather.com.cn/wmaps/xml/tianjin.xml');
   xRoot = xDoc.getDocumentElement;
   schemaURL = ...
   char(xRoot.getAttribute('dn'));
   allListItems = xDoc.getElementsByTagName('city');
   for k=0:allListItems.getLength-1
       thisListItem = allListItems.item(k);
       childNode= thisListItem.getAttribute('pyName');
       citynametemp=char(childNode);
       pyNameT{k+1}=citynametemp;       %区县名称
      
       childNode= thisListItem.getAttribute('stateDetailed');
       citynametemp=char(childNode);
       stateDetailT{k+1}=citynametemp;   %晴雨阴霾雾
      
       childNode= thisListItem.getAttribute('temNow');
       citynametemp=char(childNode);
       temperaNowT{k+1}=citynametemp;    %即时温度
      
       childNode= thisListItem.getAttribute('windDir');
       citynametemp=char(childNode);
       windDirT{k+1}=citynametemp;       %风向
      
       childNode= thisListItem.getAttribute('windPower');
       citynametemp=char(childNode);
       windPowerT{k+1}=citynametemp;     %风力
      
       childNode= thisListItem.getAttribute('humidity');
       citynametemp=char(childNode);
       humidityT{k+1}=citynametemp;      %湿度
      
       childNode= thisListItem.getAttribute('time');
       citynametemp=char(childNode);
       timeT{k+1}=citynametemp;          %发布时间
   end
catch
    error('网络读取错误,请检查网络连通及数据下载情况。');
end
%=================
city={'蓟县';'宝坻区';'武清区';'宁河县';'北辰区';'市 区';'西青区';'东丽区';'静海县';'汉沽区';'塘沽区';'津南区';'大港区'};
cityxy=[117.4,40.0
     117.3,39.6
     117.0,39.4
     117.7,39.3
     117.1,39.2
     117.1,39.1
     117.0,39.0
     117.3,39.1
     116.9,38.8
     117.8,39.2
     117.6,38.9
     117.3,38.9
     117.3,38.7];
%========
for k=1:allListItems.getLength
     switch pyNameT{k}
         case 'jixian'
             city2{k,1}=city{1};
             cityxy2(k,:)=cityxy(1,:);
         case 'baodi'
             city2{k,1}=city{2};
             cityxy2(k,:)=cityxy(2,:);
         case 'wuqing'
             city2{k,1}=city{3};
             cityxy2(k,:)=cityxy(3,:);
         case 'ninghe'
             city2{k,1}=city{4};
             cityxy2(k,:)=cityxy(4,:);
         case 'beichen'
             city2{k,1}=city{5};
             cityxy2(k,:)=cityxy(5,:);
         case 'shizhongxin'
             city2{k,1}=city{6};
             cityxy2(k,:)=cityxy(6,:);
         case 'xiqing'
             city2{k,1}=city{7};
             cityxy2(k,:)=cityxy(7,:);
         case 'dongli'
             city2{k,1}=city{8};
             cityxy2(k,:)=cityxy(8,:);
         case 'jinghai'
             city2{k,1}=city{9};
             cityxy2(k,:)=cityxy(9,:);
         case 'hangu'
             city2{k,1}=city{10};
             cityxy2(k,:)=cityxy(10,:);
         case 'tanggu'
             city2{k,1}=city{11};
             cityxy2(k,:)=cityxy(11,:);
         case 'jinnan'
             city2{k,1}=city{12};
             cityxy2(k,:)=cityxy(12,:);
         case 'dagang'
             city2{k,1}=city{13};
             cityxy2(k,:)=cityxy(13,:);
     end
end
current_t=datestr(clock,'yyyy-mm-dd HH:MM:SS');
h=figure('position',[200 50 550 670],...
'Name',['程序当前时间:' current_t],'NumberTitle','off','Color','w','resize','off');
axes('Position',[0.10  0.04  0.8  0.93]);
hold on
plot(cityxy2(:,1),cityxy2(:,2),'o','Markersize',4,'MarkerFaceColor','g');
%text(cityxy2(:,1)+0.02,cityxy2(:,2),city2);
text(116.7,40.2,['天气更新时间 ' timeT{1}], 'color','b','FontWeight','bold','Fontsize',14);
text(116.7,38.45,'天津市各区县即时温度及风力风向', 'color','b','FontWeight','bold','Fontsize',17);
%s=shaperead('tj_mp\tianjin.shp');
%hh=mapshow(s,'color',[105/255 101/255 76/255]);
axis off
%=============================
winddirection={'北风';'东北风';'东风';'东南风';'南风';'西南风';'西风';'西北风'};
winddirec2=[0 45 90 135 180 225 270 315];
winddirec2=(-90-winddirec2)*pi/180;
for k=1:allListItems.getLength
     tempPower=windPowerT{k};
     windPowerT2(k)=str2num(tempPower(1));
     switch windDirT{k}
         case '北风'
            winddirec3(k)=winddirec2(1);
         case '东北风'
            winddirec3(k)=winddirec2(2);  
         case '东风'
            winddirec3(k)=winddirec2(3);
         case '东南风'
            winddirec3(k)=winddirec2(4);   
         case '南风'
            winddirec3(k)=winddirec2(5);
         case '西南风'
            winddirec3(k)=winddirec2(6);  
         case '西风'
            winddirec3(k)=winddirec2(7);
         case '西北风'
            winddirec3(k)=winddirec2(8);
     end
end
winddirec4=round(winddirec3*180/pi);
winddirec4=mod(winddirec4,360);
windpx=windPowerT2.*cos(winddirec3);
windpy=windPowerT2.*sin(winddirec3);
windpx=windpx';
windpy=windpy';
x1=[cityxy2(:,1)
    117.6];
x2=[cityxy2(:,2)
    38.7];
x3=[windpx
    3];
x4=[windpy
    0];
quiver(x1,x2,x3,x4,'color','m','LineWidth',2);
%text(117.58,38.65,'比例:西风3级','color',[43/255 140/255 86/255],'FontWeight','bold','Fontsize',12);
text(117.58,38.65,'比例:西风3级','color','m','FontWeight','bold','Fontsize',12);
for k=1:1:length(temperaNowT)
    temperaNowTT{k}=strcat(temperaNowT{k},'°');
end
text(cityxy2(:,1)+0.02,cityxy2(:,2),temperaNowTT,...
    'color','r','FontWeight','bold','Fontsize',16);
text(116.8,40,stateDetailT{6},'FontWeight','bold','Fontsize',50,'EdgeColor','c');

评分

1

查看全部评分

 楼主| 发表于 2014-2-13 14:48:45 | 显示全部楼层 来自 天津
Simdroid开发平台
最近折腾些气象的信息,没有现成可用,就从气象局网站读取,以上是程序,供参考。经纬度坐标去了小数位,shp地图也没提供,原谅。
效果:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-7-5 12:00 , Processed in 0.029366 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表