www.gusucode.com > map 案例源码 matlab代码程序 > map/CreatingDataGridsFromVectorDataExample.m
%% Creating Data Grids from Vector Data % This example shows how to convert vector data to raster data using the % <docid:map_ref.f15-424086> function. The example uses patch data for % Indiana from the |usastatehi| shapefile. For more information, see % <docid:map_ug.f7-10884>. %% % Use |shaperead| to get the patch data for the boundary. % Copyright 2015 The MathWorks, Inc. indiana = shaperead('usastatehi.shp',... 'UseGeoCoords', true,... 'Selector', {@(name)strcmpi('Indiana',name), 'Name'}); inLat = indiana.Lat; inLon = indiana.Lon; %% % Convert the vectors to a regular data grid using |vec2mtx|. Set the grid % density to be 40 cells per degree. Rasterize the boundary and % generate a referencing vector for it. gridDensity = 40; [inGrid, inRefVec] = vec2mtx(inLat, inLon, gridDensity); whos %% % Make a map of the data grid in contrasting colors. figure axesm eqdcyl meshm(inGrid, inRefVec) colormap jet(4) %% % Set up the map limits. [latlim, lonlim] = limitm(inGrid, inRefVec); setm(gca, 'Flatlimit', latlim, 'FlonLimit', lonlim) tightmap %% % Specify the seed point and seed value. To fill (recode) the interior of % Indiana, you need a seed point (which must be identified by row and % column) and a seed value (to be allocated to all cells within the % polygon). Select the middle row and column of the grid and choose an % index value of 3 to identify the territory when calling encodem to % generate a new grid. The last argument (1) identifies the code for % boundary cells, where filling should halt. inPt = round([size(inGrid)/2, 3]); inGrid3 = encodem(inGrid, inPt,1); %% % Clear and redraw the map using the filled grid. meshm(inGrid3, inRefVec) %% % Plot the original vectors on the grid to see how well data was % rasterized. You can use the Zoom tool on the figure window to examine the % gridding results more closely. plotm(inLat, inLon,'k')