使用matlab绘制地图
生活随笔
收集整理的這篇文章主要介紹了
使用matlab绘制地图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 創建 axes
- worldmap
- 加載數據
- shaperead
- load
- 顯示地圖元素
- geoshow
- plotm 畫線
- 格式、屬性控制
- makesymbolspec
- setm
- 當把東經西經換成小數表示時,北正南負、東正西負
創建 axes
worldmap
%1 ax = worldmap('France') %2 ax = worldmap({'Africa','India'}) %3 ax = worldmap([25 50],[-130 -65]); %4 load korea % Map of terrain elevations in Korea ax = worldmap(map, refvec);加載數據
shaperead
%1 S = shaperead(FILENAME) returns an N-by-1 structure array, %2 S = shaperead(filename,Name,Value, ...) %3 [S, A] = shaperead(...)S An N-by-1 geographic data structure array containing an element for each non-null, spatial feature in the shapefile. A An N-by-1 attribute structure array, A, parallel to array S.常用內置文件
| usastatelo | 美國州行政區域劃分 | Polygon |
| landareas | 世界的陸地形狀 | Polygon |
| worldcities | 世界城市 | Point |
| worldrivers | 世界河流 | Line |
| worldlakes | 世界湖泊 | Polygon |
參數
| UseGeoCoords | true、false | 默認false,此時結構體中用X,Y表示坐標;若為true,結構體中用Lat、Lon表示坐標。 |
| BoundingBox | [xmin,ymin;xmax,ymax] for map coordinates, [lonmin,latmin;lonmax,latmax] for geographic coordinates |
數據結構
| Lines | ‘Color’, ‘LineStyle’, ‘LineWidth’, and ‘Visible.’ |
| Points or Multipoints | ‘Marker’, ‘Color’, ‘MarkerEdgeColor’,‘MarkerFaceColor’,‘MarkerSize’, and ‘Visible.’ |
| Polygons | ‘FaceColor’, ‘FaceAlpha’, ‘LineStyle’, ‘LineWidth’, ‘EdgeColor’, ‘EdgeAlpha’, and ‘Visible.’ |
load
- load coast
顯示地圖元素
geoshow
- 第一個參數是ax和不是ax的區別
- 數據是Polygon、Point、Line
- 畫線——數據是以經度數組、緯度數組
- 畫點 —— 數據是以經度數組、緯度數組
例
TowerLon = -74.0; %經度坐標 TowerLat = 40.43;%緯度坐標 %用紅色標記繪制%埃菲爾鐵塔 geoshow(TowerLat, TowerLon, 'Marker','.','MarkerEdgeColor','red','MarkerSize',10)plotm 畫線
- h = plotm(lat,lon)displays projected line objects on the current map axes.
- h = plotm(lat,lon,linetype) where linetype is a linespec that specifies the line style.
- h = plotm(lat,lon,PropertyName,PropertyValue,...) allows the specification of any number of property name/property value pairs for any properties recognized by the MATLAB line function except for XData, YData, and ZData.
格式、屬性控制
makesymbolspec
construct vector symbolization specification
SYMBOLSPEC = makesymbolspec(GEOMETRY,RULE1,RULE2,...RULEN)
- GEOMETRY is one of ‘Point’, ‘MultiPoint’, ‘Line’, ‘Polygon’, or ‘Patch’
- To create a rule that applies to all features, a default rule, use the
following syntax for RULEN:
{'Default',Property1,Value1,Property2,Value2,...,PropertyN,ValueN} - To create a rule that applies to only features that have a particular
value or range of values for a specified attribute, use the following
syntax:
{AttributeName,AttributeValue,Property1,Value1,... Property2,Value2,...,PropertyN,ValueN}
AttributeValue and ValueN can each be a two element vector, [low
high], specifying a range. If AttributeValue is a range, ValueN may
or may not be a range.
allowable values for PropertyN
| Lines | ‘Color’, ‘LineStyle’, ‘LineWidth’, and ‘Visible.’ |
| Points or Multipoints | ‘Marker’, ‘Color’, ‘MarkerEdgeColor’,‘MarkerFaceColor’,‘MarkerSize’, and ‘Visible.’ |
| Polygons | ‘FaceColor’, ‘FaceAlpha’, ‘LineStyle’, ‘LineWidth’, ‘EdgeColor’, ‘EdgeAlpha’, and ‘Visible.’ |
example:
%1 blueRoads = makesymbolspec('Line',{'Default','Color',[0 0 1]}); %2 roadColors = makesymbolspec('Line',{'CLASS',2,'Color','r'},...{'CLASS',3,'Color','g'},...{'CLASS',6,'Color','b'},...{'Default','Color','k'}); %3 lineStyle = makesymbolspec('Line',{'CLASS',[1 3],'LineStyle','-.'},...{'CLASS',[4 6],'LineStyle',':'});例二:
clear all ax = worldmap([25 50],[-130 -65]); states = shaperead('usastatelo.shp', 'UseGeoCoords', true);% 準備顏色數據 data = zeros(numel(states),3) for i = 1:numel(states)data(i,:)=[1 1 1] * i/51 end% 繪制 faceColors = makesymbolspec('Polygon',{'INDEX',[1 numel(states)], 'FaceColor',data}) geoshow(ax, states,'SymbolSpec', faceColors) % geoshow(ax, states)結果:
setm
- 設置坐標原點 setm(ax, ‘Origin’, [20 30])
總結
以上是生活随笔為你收集整理的使用matlab绘制地图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle 查看考试成绩,oracle
- 下一篇: 狂神 Git