Main Content

geocrop

Crop geographic raster

Since R2020a

Description

example

[B,RB] = geocrop(A,RA,latlim,lonlim) crops the raster specified by A and raster reference RA and returns the cropped raster B and raster reference RB. The returned raster is cropped to geographic limits in degrees close to those specified by latlim and lonlim.

To clip vector data represented by a point, line, or polygon shape in geographic coordinates, use the geoclip function instead.

Examples

collapse all

Crop a geographic raster and display the cropped raster on a map.

First, load elevation raster data and a geographic cells reference object for the Korean peninsula. Then, crop the raster to the limits specified by latlim and lonlim.

load korea5c
latlim = [34.25 38.72]; 
lonlim = [125.85 129.92];
[B,RB] = geocrop(korea5c,korea5cR,latlim,lonlim);

Display the cropped raster as a surface on a map. Apply a colormap appropriate for elevation data using the demcmap function.

worldmap(latlim,lonlim)
geoshow(B,RB,'DisplayType','surface')
demcmap(B)

Shift the longitude limits of a raster with limits that span 360 degrees using the geocrop function. Then, display the shifted data as a surface on a map.

First, load elevation raster data for the world and a geographic cells reference object. Then, shift the longitude limits of the raster from [0, 360] to [-180, 180].

load topo60c
latlim = topo60cR.LatitudeLimits;
[B,RB] = geocrop(topo60c,topo60cR,latlim,[-180 180]);

Compare the rasters by querying their LongitudeLimits properties.

topo60cR.LongitudeLimits
ans = 1×2

     0   360

RB.LongitudeLimits
ans = 1×2

  -180   180

Display the shifted data as a surface on a map. Move the meridian labels to the bottom of the map using the mlabel function. Specify meridian labels to display using the MLabelLocation property. Then, apply a colormap appropriate for topographic data using the demcmap function. Note that the shifted longitude limits appear at the edges of the map.

worldmap(RB.LatitudeLimits,RB.LongitudeLimits)
geoshow(B,RB,'DisplayType','surface')
mlabel('south')
setm(gca,'MLabelLocation',-180:90:180)
demcmap(B)

Input Arguments

collapse all

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

Raster reference for A, specified as a GeographicCellsReference object or GeographicPostingsReference object.

Latitude limits, specified as a two-element numeric vector of the form [slat nlat], where slat is the southernmost limit in degrees and nlat is the northernmost limit in degrees.

Longitude limits, specified as a two-element numeric vector of the form [wlon elon], where wlon is the westernmost limit in degrees and elon is the easternmost limit in degrees.

Output Arguments

collapse all

Cropped geographic raster, returned as a numeric or logical array. The data type and size of B matches the data type and size of A.

If the limits specified by latlim and lonlim do not intersect the raster specified by A and RA, then B is empty.

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

The exact latitude and longitude limits of RB do not match the limits specified by latlim and lonlim, unless they coincide with a cell boundary or posting location. Otherwise, the limits of RB are slightly larger than latlim and lonlim.

If the limits specified by latlim and lonlim do not intersect the raster specified by A and RA, then RB is empty.

Version History

Introduced in R2020a