Project and Display Raster Data
To project or unproject regularly-spaced raster data that is associated with a geographic or map reference object, you must first create a coordinate grid that matches the size of the raster. Use different grid creation functions depending on which way you are projecting. When you project latitude-longitude coordinates tox-ycoordinates, create a grid using thegeographicGrid
function. When you unprojectx-ycoordinates to latitude-longitude coordinates, create a grid using theworldGrid
function.
After transforming the raster data, you can display it on a map using visualization functions such asmapshow
andgeoshow
. Usemapshow
for projectedx-ycoordinates andgeoshow
for unprojected latitude-longitude coordinates.
Project Raster Data
To project data that is associated with a geographic raster reference object, first create a grid of latitude-longitude coordinates for each point in the raster. Then, project the geographic coordinates tox-ymap coordinates.
For example, import elevation raster data as an array and a geographic cells reference object. Get the latitude-longitude coordinates for each point in the raster by using thegeographicGrid
function.
[Z,R] = readgeoraster('n39_w106_3arc_v2.dt1'); [lat,lon] = geographicGrid(R);
Now that you have your grid, select a map projection to use when projecting the coordinates. For this example, create aprojcrs
object for UTM zone 13 in the northern hemisphere. Then, project the latitude-longitude coordinates tox-ycoordinates.
p = projcrs(32613); [x,y] = projfwd(p,lat,lon);
Display the projected raster as a surface by callingmapshow
and specifying thex-ycoordinates and elevation array. Add axis labels and apply a colormap appropriate for elevation data.
图mapshow (x, y, Z,'DisplayType','surface') xlabel('x (meters)') ylabel('y (meters)') demcmap(Z)
If the geographic CRS of the latitude-longitude coordinates does not match the geographic CRS of the projected CRS, then the projected coordinates may be inaccurate. You can find the geographic CRS of aprojcrs
object or a geographic raster reference object by querying theirGeographicCRS
properties.
p.GeographicCRS.Name
ans = "WGS 84"
R.GeographicCRS.Name
ans = "WGS 84"
The DTED file used in this example is courtesy of the US Geological Survey.
Unproject Raster Data
To unproject data that is associated with a map raster reference object, first create a grid ofx-ycoordinates for each point in the raster. Then, unproject thex-ymap coordinates to geographic coordinates.
For example, import an image of Boston as an array and a map cells reference object. Get information about the map projection as aprojcrs
object by querying theProjectedCRS
property of the reference object.
[Z,R] = readgeoraster('boston.tif'); p = R.ProjectedCRS;
Get thex-ycoordinates for each point in the raster by using theworldGrid
function.
(x, y) = worldGrid (R);
Unproject thex-ycoordinates to latitude-longitude coordinates by using theprojinv
function and specifying theprojcrs
object and coordinate grid.
[lat,lon] = projinv(p,x,y);
Display the unprojected image by callinggeoshow
and specifying the latitude-longitude coordinates and image array. By default,geoshow
displays coordinates using a Plate Carrée projection. Then, add axis labels.
figure geoshow(lat,lon,Z) xlabel('Longitude (degrees)') ylabel('Latitude (degrees)')