Main Content

cropToBlock

Crop raster reference object to row and column limits of raster

Since R2023b

    Description

    RB = cropToBlock(RA,rowLimits,colLimits) crops a raster reference object that is associated with a block of raster data to the specified row and column limits of the raster. This function is useful for cropping reference objects that are associated with data that does not fit in memory. To read the data, you can use blockedImage (Image Processing Toolbox) objects.

    example

    Examples

    collapse all

    Read a spatially referenced region from raster data that does not fit in memory by:

    1. Creating a blocked image from the data.

    2. Reading a block from the blocked image.

    3. Cropping the raster reference object for the blocked image to the row and column limits of the block.

    Create a blocked image from a GeoTIFF file containing satellite imagery of Boston. Specify the block size in pixels. Then, view the size of the blocked image, expressed using the number of blocks.

    bim = blockedImage("boston.tif");
    bim.BlockSize = [528 528];
    bim.SizeInBlocks
    ans = 1×3
    
         6     9     1
    
    

    Get spatial referencing information, as a raster reference object, from the GeoTIFF file.

    geoInfo = georasterinfo("boston.tif");
    geoRef = geoInfo.RasterReference;

    Read a block and its metadata from the blocked image. Specify the block in the 3rd row and 7th column of the blocked image. Then, extract the subscripts of the first and last elements of the block from the metadata.

    [block,blockInfo] = getBlock(bim,[3 7 1]);
    rowLimits = [blockInfo.Start(1) blockInfo.End(1)];
    colLimits = [blockInfo.Start(2) blockInfo.End(2)];

    Crop the raster reference object to the block. Display the spatially referenced block on a map.

    blockRef = cropToBlock(geoRef,rowLimits,colLimits);
    mapshow(block,blockRef)

    Figure contains an axes object. The axes object contains an object of type image.

    Input Arguments

    collapse all

    Minimum and maximum row limits of the raster data block, specified as a two-element numeric vector of the form [rmin rmax], where rmax is greater than rmin. Specify the limits using discrete coordinates. Discrete coordinates are integer-valued, intrinsic coordinates.

    Minimum and maximum column limits of the raster data block, specified as a two-element numeric vector of the form [cmin cmax], where cmax is greater than cmin. Specify the limits using discrete coordinates. Discrete coordinates are integer-valued, intrinsic coordinates.

    Output Arguments

    collapse all

    Raster reference, returned as a GeographicCellsReference, GeographicPostingsReference, MapCellsReference, or MapPostingsReference object. The object type of RB matches the object type of RA.

    Alternative Functionality

    When the data fits in memory, you can read the data by using the readgeoraster function, and then crop the data by using the geocrop or mapcrop function. The geocrop function accepts limits in geographic coordinates as input. The mapcrop function accepts limits in world coordinates as input.

    Version History

    Introduced in R2023b

    See Also

    Functions

    Objects