Main Content

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 thegeographicGridfunction. When you unprojectx-ycoordinates to latitude-longitude coordinates, create a grid using theworldGridfunction.

After transforming the raster data, you can display it on a map using visualization functions such asmapshowandgeoshow. Usemapshowfor projectedx-ycoordinates andgeoshowfor 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 thegeographicGridfunction.

[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 aprojcrsobject 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 callingmapshowand 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)

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

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 aprojcrsobject or a geographic raster reference object by querying theirGeographicCRSproperties.

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 aprojcrsobject by querying theProjectedCRSproperty of the reference object.

[Z,R] = readgeoraster('boston.tif'); p = R.ProjectedCRS;

Get thex-ycoordinates for each point in the raster by using theworldGridfunction.

(x, y) = worldGrid (R);

Unproject thex-ycoordinates to latitude-longitude coordinates by using theprojinvfunction and specifying theprojcrsobject and coordinate grid.

[lat,lon] = projinv(p,x,y);

Display the unprojected image by callinggeoshowand specifying the latitude-longitude coordinates and image array. By default,geoshowdisplays coordinates using a Plate Carrée projection. Then, add axis labels.

figure geoshow(lat,lon,Z) xlabel('Longitude (degrees)') ylabel('Latitude (degrees)')

See Also

Functions

Objects