Main Content

mapresample

Resample planar map raster

Since R2025a

    Description

    B = mapresample(A,RA,RB) resamples the planar map raster A, which uses the raster reference RA, so that the output planar map raster B is referenced to the target raster reference RB.

    example

    B = mapresample(A,RA,RB,method) specifies the interpolation method. By default, the function uses linear interpolation.

    example

    Examples

    collapse all

    Read raster data into the workspace as an array and a map cells reference object. The raster is of size 2881-by-4481.

    [A,RA] = readgeoraster("boston.tif");

    Create the target reference object by making a copy of the original reference object. Specify a new raster size by changing the RasterSize property of the target reference object.

    RB = RA;
    RB.RasterSize = [480 747];

    Resample the raster data. The resampled raster is of size 480-by-747.

    B = mapresample(A,RA,RB);

    Read raster data into the workspace as an array and a map cells reference object. The raster has world x-limits in the range [310380, 320730] and world y-limits in the range [4901880, 4916040].

    [A,RA] = readgeoraster("MtWashington-ft.grd",OutputType="double");

    Create the target reference object by making a copy of the original reference object. Specify new world xy-coordinates by changing the XWorldLimits and YWorldLimits properties of the target reference object.

    RB = RA;
    RB.XWorldLimits = [312000 320000];
    RB.YWorldLimits = [4903000 4911000];

    Resample the raster data.

    B = mapresample(A,RA,RB);

    Read two basemap images into the workspace. The images cover similar areas of interest.

    • The image from the "satellite" basemap is a medium-resolution image. The height and width of each pixel is approximately 2500 meters.

    • The image from the "landcover" basemap is a coarse-resolution image. The height and width of each pixel is approximately 5000 meters.

    [A1,R1,attrib1] = readBasemapImage("satellite",[32 49],[-125 -102],14);
    [A2,R2,attrib2] = readBasemapImage("landcover",[32 49],[-125 -102],5);

    Verify that the images use the same type of coordinate system.

    isequal(R1.CoordinateSystemType,R2.CoordinateSystemType)
    ans = logical
       1
    
    

    Verify that the images use the same projected coordinate reference system.

    isequal(R1.ProjectedCRS,R2.ProjectedCRS)
    ans = logical
       1
    
    

    Resample the medium-resolution image to match the resolution of the coarse-resolution image.

    resampledA1 = mapresample(A1,R1,R2);

    Note that the resampled image and the coarse-resolution image have the same size.

    whos resampledA1 A2
      Name               Size                Bytes  Class    Attributes
    
      A2               514x523x3            806466  uint8              
      resampledA1      514x523x3            806466  uint8              
    

    Read an indexed image into the workspace as an array, a map cells reference object, and a colormap.

    [A,RA,cmap] = readgeoraster("oahu_landcover.img");

    Create the target reference object by copying the original reference object and changing the raster size.

    RB = RA;
    RB.RasterSize = [404 507];

    Resample the raster using nearest-neighbor interpolation.

    B = mapresample(A,RA,RB,"nearest");

    Input Arguments

    collapse all

    Planar map raster, specified as an M-by-N or M-by-N-by-P numeric or logical array.

    Raster reference for A, specified as a MapCellsReference object or MapPostingsReference object.

    The ProjectedCRS properties of RA and RB must be equal, unless one of the ProjectedCRS properties is empty.

    Target raster reference, specified as a MapCellsReference object or MapPostingsReference object. The resampled raster B is referenced to RB.

    The ProjectedCRS properties of RA and RB must be equal, unless one of the ProjectedCRS properties is empty.

    Interpolation method, specified as one of these options:

    • "linear" — Linear interpolation. The interpolated value at a query point is based on linear interpolation of the values at neighboring points. This method is sometimes called bilinear interpolation.

    • "nearest" — Nearest-neighbor interpolation. The interpolated value at a query point is the value of the nearest point. This method is useful for resampling indexed images.

    • "cubic" — Cubic interpolation. The interpolated value at a query point is based on cubic interpolation of the values at neighboring points. This method is sometimes called bicubic interpolation.

    Output Arguments

    collapse all

    Resampled planar map raster, returned as a numeric or logical array. B is referenced to the target raster reference RB. The data type of B matches the data type of A.

    Elements of the resampled raster that are outside the area defined by the original raster depend on the data type of B:

    • When B uses the single or double data type, the elements are NaN values.

    • When B uses an integer or logical data type, the elements are 0 values.

    Tips

    • To resample a raster in geographic coordinates, use the georesample function.

    • To perform antialiasing when shrinking a raster, resize the raster by using the mapresize function.

    Version History

    Introduced in R2025a