Main Content

geoloc2grid

Convert geolocated data array to regular data grid

Syntax

[Z,R] = geoloc2grid(lat,lon,A,cellsize)

Description

[Z,R] = geoloc2grid(lat,lon,A,cellsize) converts the geolocated data array A, given geolocation points in lat and lon, to produce a regular data grid, Z, and the corresponding raster reference object R. cellsize is a scalar that specifies the width and height of data cells in the regular data grid, using the same angular units as lat and lon. Data cells in Z falling outside the area covered by A are set to NaN.

Examples

collapse all

Load the geolocated data array map1 and grid it to ½-degree cells.

load mapmtx
cellsize = 0.5;
[Z,R] = geoloc2grid(lt1,lg1,map1,cellsize);

Create a figure.

f = figure;
[cmap,clim] = demcmap(map1);
set(f,'Colormap',cmap,'Color','w')

Define map limits.

latlim = [-35 70];
lonlim = [0 100];

Display map1 as a geolocated data array and Z as a regular data grid using subplots.

subplot(1,2,1)
ax = axesm('mercator','MapLatLimit',latlim,...
   'MapLonLimit',lonlim,'Grid','on',...
   'MeridianLabel','on','ParallelLabel','on');
set(ax,'Visible','off')
geoshow(lt1,lg1,map1,'DisplayType','texturemap');

subplot(1,2,2)
ax = axesm('mercator','MapLatLimit',latlim,...
   'MapLonLimit',lonlim,'Grid','on',...
   'MeridianLabel','on','ParallelLabel','on');
set(ax,'Visible','off')
geoshow(Z,R,'DisplayType','texturemap');

Two maps created from the same data set. The map on the left shows the original geolocated data array. The map on the right shows the same data, converted to a regular data grid.

Tips

geoloc2grid provides an easy-to-use alternative to gridding geolocated data arrays with imbedm. There is no need to preallocate the output map; there are no data gaps in the output (even if cellsize is chosen to be very small), and the output map is smoother.

Version History

Introduced before R2006a

expand all