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绘制地图内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
X 关闭
X 关闭
- 15G资费不大降!三大运营商谁提供的5G网速最快?中国信通院给出答案
- 2联想拯救者Y70发布最新预告:售价2970元起 迄今最便宜的骁龙8+旗舰
- 3亚马逊开始大规模推广掌纹支付技术 顾客可使用“挥手付”结账
- 4现代和起亚上半年出口20万辆新能源汽车同比增长30.6%
- 5如何让居民5分钟使用到各种设施?沙特“线性城市”来了
- 6AMD实现连续8个季度的增长 季度营收首次突破60亿美元利润更是翻倍
- 7转转集团发布2022年二季度手机行情报告:二手市场“飘香”
- 8充电宝100Wh等于多少毫安?铁路旅客禁止、限制携带和托运物品目录
- 9好消息!京东与腾讯续签三年战略合作协议 加强技术创新与供应链服务
- 10名创优品拟通过香港IPO全球发售4100万股 全球发售所得款项有什么用处?