Drawing __matlab Map of China by Matlab

Source: Internet
Author: User
Tags polyline strcmp

How to use Mapshow+shapefile:

%% Mapchina CLC;CLEAR;CLF% shapefile include national boundaries and provincial
fnshp_l= ' E:\ChinaMap\ border and Provincial \bou2_4l.shp ';%shapetype: ' Polyline '
fnshp_p= ' E:\ChinaMap\ border and Provincial \bou2_4p.shp ';%shapetype: ' Polygon ' infol
= Shapeinfo (fnshp_l);
INFOP = Shapeinfo (fnshp_p);
Readl=shaperead (fnshp_l);
Readp=shaperead (fnshp_p);
Subplot (121); Mapshow (READL); title (' Polyline of ")
subplot (122); Mapshow (READP); title (' Polygon of")

Draw the following graphic:

The second method uses the Geoshow+shapefile method:

%% geoshow+shapefile CLC;CLEAR;CLF% shapefile include national boundaries and provincial
fnshp_l= ' E:\ChinaMap\ border and provincial \bou2_4l.shp '; ShapeType: ' polyline '
fnshp_p= ' E:\ChinaMap\ border and Provincial \bou2_4p.shp ';%shapetype: ' Polygon ' Readl=shaperead
( fnshp_l);% there is no name Readp=shaperead (fnshp_p) for each province in the document,
with the name of each province
subplot (121); WorldMap (' China '); Geoshow ( fnshp_l); title (' Polyline of ')
subplot (122); WorldMap (' The ') geoshow (fnshp_p); title (' Polygon of ')
The drawing is as follows:

Note that if the above command is not worldmap, the graph drawn with the first method is the same.

If you only want to show Anhui province, then you can do this:

%bbox=[114,29;120,35];% Anhui's geographical location
%s = Shaperead (fnshp_p, ' BoundingBox ', bbox);
S = Shaperead (fnshp_p);
N=1;
while (N>=1 && N<=numel (S))
    sname=s (n). NAME;
    if (~strcmp (sname, ' Anhui Province '))
        S (n) =[];
        n=n-1;
    End
        n=n+1;
End
Mapshow (S);
The results shown are as follows:

If you are using Geoshow, it is a good idea to convert your data (x,y) coordinates to (Lon,lat):

bbox=[114,29;120,35];% Anhui's geographical location
S = Shaperead (fnshp_p, ' BoundingBox ', bbox, ' usegeocoords ', true);% read only part of the data
n=1 ;
while (N>=1 && N<=numel (S))
    sname=s (n). NAME;
    if (~strcmp (sname, ' Anhui Province '))
        S (n) =[];
        n=n-1;
    End
        n=n+1;
End
WorldMap ([35],[114])%worldmap (Latlim, Lonlim)
geoshow (S)
The map drawn is:

In fact, the above drawing arbitrary map of the province can also be further simplified: Read the Shapefile file using ' selector ' Select the province you want it to:

S = Shaperead (fnshp_p, ' usegeocoords ', true,...
  ' Selector ', {@ (name) strcmp (name, ' Anhui Province '), ' name '};
WorldMap ([35],[114])%worldmap (Latlim, Lonlim)
geoshow (S)

The results drawn are the same as those shown above.

Sometimes we want to modify some of the map's properties, such as the projection method, but using Getm and Setm to implement, see the following example:

S = Shaperead (fnshp_p, ' usegeocoords ', true, ' Selector ', {@ (name) strcmp (name, ' Anhui Province '), ' name '});
Wm=worldmap ([29 35],[114 120]); %worldmap (Latlim, Lonlim)
%getm (WM)% View all attributes of the current map
Setm (WM, ' mapprojection ', ' Eqacylin '); You can use maps to view all map projection modes
gs=geoshow (S);
The drawing is as follows:

If you do not want to use the extra shapefile drawing, the shapefile from Matlab can also:

Wm=worldmap (' World ');
Land=shaperead (' Landareas ', ' usegeocoords ', true);
Geoshow (Wm,land, ' facecolor ', [0.5 0.7 0.5]);
Lakes=shaperead (' Worldlakes ', ' usegeocoords ', true);
Geoshow (Lakes, ' facecolor ', ' Blue ');
Rivers=shaperead (' worldrivers ', ' usegeocoords ', true);
Geoshow (rivers, ' Color ', ' Blue ');
Cities=shaperead (' worldcities ', ' usegeocoords ', true);
Geoshow (cities, ' Marker ', '. ', ' Color ', ' red ');
The results of the drawing are as follows:

An example is given below:

Maps% view the current available map projection way percent of the

import data, the global coastline
load coast

% drawing
axesm Robinson
patchm (Lat,long, ' G ');
 Percent of the Set attribute
Setm (GCA);% View the properties Setm (GCA, ' frame ', ' on ') of all graphics axes (map axes) that can be set now;% to
make frames visible
Getm (GCA, ' frame ');% Use Getm to get the properties of the specified graphics axis
Setm (GCA, ' grid ', ' on ');% to open grid
Setm (GCA, ' mlabellocation ', 60);% longitude scale labels, every 60 degrees
Setm (GCA, ' Meridianlabel ', ' on ');% set longitude tick label visible
Setm (GCA, ' plabellocation ', [ -90:30:90])% longitude tick mark, [ -90:30:90]
Setm (GCA, ' Parallellabel ', ' on ');% set longitude tick mark visible
Setm (GCA, ' mlabelparallel ', ' South ');% place Longitude tick label south, lower  
Setm (GCA, ' Origin ', [0,90,0]);% sets the central position of the map and the axis rotation angle around the center and geocentric points [latitude longitude orientation]

The drawing is as follows:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.