mergetiles
Description
Examples
Merge Raster Tiles
Import adjacent raster tiles, merge the tiles into a single raster, and display the merged raster on a map.
Read four DTED tiles into the workspace. The tiles form a quadrangle with latitudes from 39 to 41 degrees and longitudes from –107 to –105 degrees. For each use of the readgeoraster
function, the first output is an array that contains elevation values, and the second output is a reference object that contains spatial referencing information.
[A1,R1] = readgeoraster("w106/n39.dt0",OutputType="double"); [A2,R2] = readgeoraster("w106/n40.dt0",OutputType="double"); [A3,R3] = readgeoraster("w107/n39.dt0",OutputType="double"); [A4,R4] = readgeoraster("w107/n40.dt0",OutputType="double");
Merge the tiles into one raster.
[B,RB] = mergetiles(A1,R1,A2,R2,A3,R3,A4,R4);
Create a map and display the merged raster as a surface. Apply a colormap that is appropriate for elevation data. Then, add a labeled color bar.
usamap(B,RB) geoshow(B,RB,DisplayType="surface") demcmap(B) c = colorbar; c.Label.String = "Elevation (m)";
This example uses modified data from the US Geological Survey.
Merge Data with Missing Tiles
The mergetiles
function requires the input raster tiles to form a filled quadrangle or rectangle. If your data has missing tiles, then you can fill the gaps with values that represent missing data.
Read three DTED tiles into the workspace:
w106/n39.dt0
has latitudes from 39 to 40 degrees and longitudes from –106 to –105 degrees.w106/n40.dt0
has latitudes from 40 to 41 degrees and longitudes from –106 to –105 degrees.w107/n39.dt0
has latitudes from 39 to 40 degrees and longitudes from –107 to –106 degrees.
[A1,R1] = readgeoraster("w106/n39.dt0",OutputType="double"); [A2,R2] = readgeoraster("w106/n40.dt0",OutputType="double"); [A3,R3] = readgeoraster("w107/n39.dt0",OutputType="double");
The tiles are bound by a quadrangle with latitudes from 39 to 41 degrees and longitudes from –107 to –105 degrees. However, the quadrangle is missing the tile with latitudes from 40 to 41 degrees and longitudes from –107 to –106.
To merge the three DTED tiles by using the mergetiles
function, you can create a fourth tile of NaN
values that accounts for the missing data. If the NaN
function does not support the data type of your tiles, such as uint8
values in tiles of RGB data, then you can use numeric values such as 0
s or 1
s.
Spatially reference the tile by making a copy of one of the existing reference objects. Then, change the latitude and longitude limits of the new reference object to match the limits of the missing tile.
Create an array of
NaN
values. Specify the size of the array using the raster size stored in the new reference object.
missingR = R3; missingR.LatitudeLimits = [40 41]; missingR.LongitudeLimits = [-107 -106]; missingA = NaN(missingR.RasterSize);
Merge the DTED tiles and the tile of NaN
values into one raster.
[B,RB] = mergetiles(A1,R1,A2,R2,A3,R3,missingA,missingR);
Create a map and display the merged raster as a surface. Note that the northwest corner of the map is blank. Apply a colormap that is appropriate for elevation data. Then, add a labeled color bar.
figure usamap(B,RB) geoshow(B,RB,DisplayType="surface") demcmap(B) c = colorbar; c.Label.String = "Elevation (m)";
This example uses modified data from the US Geological Survey.
Input Arguments
A1
, An
— Georeferenced image or data grid
numeric or logical matrix | numeric or logical array
Georeferenced image or data grid, specified as an M-by-N numeric or logical matrix or an M-by-N-by-P numeric or logical array.
The data types of the input images or data grids must match.
R1
, Rn
— Spatial reference for image or data grid
GeographicCellsReference
object | GeographicPostingsReference
object | MapCellsReference
object | MapPostingsReference
object
Spatial reference for the image or data grid, specified as a GeographicCellsReference
, GeographicPostingsReference
, MapCellsReference
, or MapPostingsReference
object.
The object types of the input reference objects must match. In addition, the input reference objects must be consistent.
GeographicCellsReference
objects are consistent when the values of theCellExtentInLatitude
,CellExtentInLongitude
,GeographicCRS
,RowsStartFrom
, andColumnsStartFrom
properties match.GeographicPostingsReference
objects are consistent when the values of theSampleSpacingInLatitude
,SampleSpacingInLongitude
,GeographicCRS
,RowsStartFrom
, andColumnsStartFrom
properties match.MapCellsReference
objects are consistent when the values of theCellExtentInWorldX
,CellExtentInWorldY
,ProjectedCRS
,RowsStartFrom
, andColumnsStartFrom
properties match.MapPostingsReference
objects are consistent when the values of theSampleSpacingInWorldX
,SampleSpacingInWorldY
,ProjectedCRS
,RowsStartFrom
, andColumnsStartFrom
properties match.
Output Arguments
B
— Merged image or data grid
numeric or logical matrix | numeric or logical array
Georeferenced image or data grid, returned as an M-by-N numeric or logical matrix or an M-by-N-by-P numeric or logical array.
The data type of B
matches the data type of the input images or
data grids.
RB
— Spatial reference for merged image or data grid
GeographicCellsReference
object | GeographicPostingsReference
object | MapCellsReference
object | MapPostingsReference
object
Spatial reference for the merged image or data grid, returned as a GeographicCellsReference
, GeographicPostingsReference
, MapCellsReference
, or MapPostingsReference
object.
The object type of RB
matches the object type of the input
reference objects.
Tips
To simultaneously read and merge multiple adjacent raster tiles, you can create a custom datastore. For more information about using custom datastores to read and merge multiple tiles, see Merge Multiple Raster Tiles Using Datastore.
Version History
Introduced in R2024a
See Also
Functions
Objects
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)