Matlab繪制中國地圖超全教程詳解
依舊需要用到Mapping Toolbox不會安裝的可以看我上一篇
雖然我們隻讀取shp文件,但需要保證文件夾裡還有shx文件及dbf文件
各省邊界線繪圖
provinces=shaperead('bou2_4l.shp','UseGeoCoords',true); % 繪圖 worldmap('China'); geoshow(provinces)
省份填色圖
provinces=shaperead('bou2_4p.shp','UseGeoCoords',true); % 繪圖 worldmap('China'); faceColors=makesymbolspec('Polygon',{'INDEX',[1 numel(provinces)],'FaceColor',polcmap(numel(provinces))}); geoshow(provinces,'DisplayType','polygon','SymbolSpec',faceColors)
改個顏色:
provinces=shaperead('bou2_4p.shp','UseGeoCoords',true); % 插值定義顏色 C=[222,238,209;126,190,174;144,213,220; 33,118,155;30,69,128;20,49,127]./255; C1(:,1)=interp1(0:5,C(:,1),linspace(0,5,numel(provinces)),'linear')'; C1(:,2)=interp1(0:5,C(:,2),linspace(0,5,numel(provinces)),'linear')'; C1(:,3)=interp1(0:5,C(:,3),linspace(0,5,numel(provinces)),'linear')'; % 繪圖 worldmap('China'); faceColors=makesymbolspec('Polygon',{'INDEX',[1 numel(provinces)],'FaceColor',C1}); geoshow(provinces,'DisplayType','polygon','SymbolSpec',faceColors)
標註省份名稱
provinces=shaperead('bou2_4p.shp','UseGeoCoords',true); % 插值定義顏色 C=[222,238,209;126,190,174;144,213,220; 33,118,155;30,69,128;20,49,127]./255; C1(:,1)=interp1(0:5,C(:,1),linspace(0,5,numel(provinces)),'linear')'; C1(:,2)=interp1(0:5,C(:,2),linspace(0,5,numel(provinces)),'linear')'; C1(:,3)=interp1(0:5,C(:,3),linspace(0,5,numel(provinces)),'linear')'; % 繪圖 worldmap('China'); faceColors=makesymbolspec('Polygon',{'INDEX',[1 numel(provinces)],'FaceColor',C1}); geoshow(provinces,'DisplayType','polygon','SymbolSpec',faceColors) % 讀取首都和省級行政中心位置信息並標記 pnames=shaperead('res1_4m.shp','UseGeoCoords',true); for i=1:numel(pnames) textm(pnames(i).Lat,pnames(i).Lon,pnames(i).NAME, ... 'HorizontalAlignment','center','FontSize',5,'color','k') end
單獨繪制某個省份:
worldmap([42,55],[120,137]); % 從中國省份數據文件中獲取黑龍江省 P=shaperead('bou2_4p.shp','UseGeoCoords',true,... 'Selector',{@(name) strcmp(name,'黑龍江省'),'NAME'}); patchm(P.Lat,P.Lon, [0.5 0.7 0.5])
中國公路交通圖
borders=shaperead('bou1_4p.shp','UseGeoCoords',true); roads=shaperead('roa_4m.shp','UseGeoCoords',true); worldmap('China'); geoshow(borders,'FaceColor',[239,238,234]./255) geoshow(roads,'Color',[250,227,158]./255,'LineWidth',1.5)
中國鐵路交通圖
borders=shaperead('bou1_4p.shp','UseGeoCoords',true); rails=shaperead('rai_4m.shp','UseGeoCoords',true); worldmap('China'); geoshow(borders,'FaceColor',[239,238,234]./255) geoshow(rails,'Color',[.2,.2,.2],'LineWidth',1,'LineStyle','-.')
中國河流圖
borders=shaperead('bou1_4p.shp','UseGeoCoords',true); riversp=shaperead('hyd1_4p.shp','UseGeoCoords',true); riversl=shaperead('hyd1_4l.shp','UseGeoCoords',true); worldmap('China'); geoshow(borders,'FaceColor',[239,238,234]./255) geoshow(riversp,'FaceColor',[127,141,181]./255,'EdgeColor',[127,141,181]./255) geoshow(riversl,'Color',[127,141,181]./255,'LineWidth',1)
組合美化圖
美化圖一
ax=worldmap('China'); setm(ax,'FFaceColor',[153,179,204]./255) % 繪制附近大陸 antarctica = shaperead('landareas.shp', 'UseGeoCoords', true,... 'Selector',{@(name) strcmp(name,'Africa and Eurasia'), 'Name'}); patchm(antarctica.Lat, antarctica.Lon, [0.5 0.7 0.5]) % 繪制中國國界 bordersl=shaperead('bou1_4l.shp','UseGeoCoords',true); geoshow(bordersl,'Color',[.3,.3,.3],'LineWidth',1) bordersp=shaperead('bou1_4p.shp','UseGeoCoords',true); patchm([bordersp.Lat],[bordersp.Lon],[239,238,234]./255); % 繪制河流 riversp=shaperead('hyd1_4p.shp','UseGeoCoords',true); riversl=shaperead('hyd1_4l.shp','UseGeoCoords',true); geoshow(riversp,'FaceColor',[127,141,181]./255,'EdgeColor',[127,141,181]./255) geoshow(riversl,'Color',[127,141,181]./255,'LineWidth',1) % 繪制公路 roads=shaperead('roa_4m.shp','UseGeoCoords',true); geoshow(roads,'Color',[250,227,158]./255,'LineWidth',1.5) tightmap
美化圖二
ax=worldmap('china'); setm(ax,'mapprojection','mercator'); % 繪制國界 bordersl=shaperead('bou1_4l.shp','UseGeoCoords',true); geoshow(bordersl,'Color',[.3,.3,.3],'LineWidth',1) % 繪制省份 colorList=[197,228,212;255,254,216;251,197,221;199,205,231]./255; colorList=repmat(colorList,[250,1]); provinces=shaperead('bou2_4p.shp','UseGeoCoords',true); colorList=colorList(1:numel(provinces),:); faceColors=makesymbolspec('Polygon',{'INDEX',[1 numel(provinces)],'FaceColor',colorList}); geoshow(provinces,'DisplayType','polygon','SymbolSpec',faceColors) % 首都 pnames=shaperead('res1_4m.shp','UseGeoCoords',true); geoshow(pnames(1).Lat,pnames(1).Lon,'DisplayType','point','Marker','p',... 'MarkerEdgeColor',[.8,0,0],'MarkerFaceColor',[.8,0,0]) % 指北針 northarrow('latitude',50,'longitude',80,'scaleratio',.08,'FaceColor',[.4,.4,.4]) % 比例尺 scaleruler on setm(handlem('scaleruler1'), ... 'XLoc',-3.2e6,'YLoc',1.8e6, ... 'MajorTick',0:500:2000,... 'MinorTick',0:40:200,'FontSize',7) scaleruler('units','nm') setm(handlem('scaleruler2'), ... 'XLoc',-3.15e6, ... 'YLoc',1.7e6, ... 'TickDir','down', ... 'MajorTick',0:250:1000,... 'MinorTick',0:40:200,... 'MajorTickLength',km2nm(25),... 'MinorTickLength',km2nm(12.5),'FontSize',7) % 小地圖 h2=axes('pos',[0.67 0.15 0.13 0.2]); worldmap([1 22],[106 122]) setm(h2,'FFaceColor',[197,213,236]./255,'FEdgeColor',[.3,.3,.3],'FLineWidth',1.5) insert1=shaperead('bou2_4l.shp','UseGeoCoords',true); geoshow(insert1,'Color',[.2,.2,.2],'LineWidth',1) insert2=shaperead('bou2_4p.shp','UseGeoCoords',true); geoshow(insert2,'FaceColor','w') mlabel off plabel off gridm off
代碼和數據:
鏈接:https://pan.baidu.com/s/1ZvMTLVElEWgQ3TFOmDXyCg 提取碼:1234
到此這篇關於Matlab繪制中國地圖超全教程詳解的文章就介紹到這瞭,更多相關Matlab繪制地圖內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!