Main Content

geotiff2mstruct

Convert GeoTIFF information structure to map projection structure

    Description

    mstruct = geotiff2mstruct(proj) converts the specified GeoTIFF information structure to a map projection structure. This function is useful for creating axesm-based maps from the projection information stored in GeoTIFF files.

    example

    Examples

    collapse all

    Get information about a GeoTIFF file by using the geotiffinfo function. The file contains an image of Boston that is referenced to projected coordinates. The function stores the information in a structure array.

    proj = geotiffinfo("boston.tif");

    Convert the GeoTIFF information structure to a map projection structure by using the geotiff2mstruct function.

    mstruct = geotiff2mstruct(proj);

    Read an overview image of Boston into the workspace as an array and a raster reference object. The overview image is referenced to geographic coordinates.

    A = imread("boston_ovr.jpg");
    R = worldfileread("boston_ovr.jgw","geographic",size(A));

    Create an axesm-based map using the projection stored in the map projection structure. Specify the geographic limits of the map using the limits stored in the reference object. Customize the map by adding labels and graticule lines.

    figure
    latlim = R.LatitudeLimits;
    lonlim = R.LongitudeLimits;
    axesm(mstruct,MapLatlimit=latlim,MapLonlimit=lonlim, ...
        Grid="on",GColor=[0.9 0.9 0.9], ...
        ParallelLabel="on",PLabelLocation=0.025,PLabelRound=-2, ...
        PLineLocation=0.025, ...
        MeridianLabel="on",MLabelLocation=0.025,MLabelRound=-2, ...
        MLineLocation=0.025)
    tightmap

    Display the overview image on the map. The geoshow function projects the geographic coordinates using the map projection structure.

    geoshow(A,R,DisplayType="image")

    Figure contains an axes object. The axes object contains 13 objects of type surface, line, text.

    Get information about a GeoTIFF file by using the geotiffinfo function. The function stores the information in a structure array.

    proj = geotiffinfo("boston.tif");

    Convert the GeoTIFF information structure to a map projection structure by using the geotiff2mstruct function.

    mstruct = geotiff2mstruct(proj);

    Compare the projection stored in the GeoTIFF file to the map projection structure by unprojecting coordinates.

    Specify xy-coordinates using the corner coordinates stored in the GeoTIFF file.

    x = proj.CornerCoords.X;
    y = proj.CornerCoords.Y;

    Get the length unit from the map projection structure. The length unit is survey feet.

    unit = proj.UOMLength
    unit = 
    'US survey foot'
    

    Convert the corner coordinates from survey feet to meters. You must perform this step because the geotiff2mstruct function reports linear values using meters.

    xsf = unitsratio("meter","sf") * x;
    ysf = unitsratio("meter","sf") * y;

    Unproject the coordinates using the GeoTIFF information structure and the map projection structure. Then, verify that the values are equal.

    [latProj,lonProj] = projinv(proj,x,y);
    [latMstruct,lonMstruct] = projinv(mstruct,xsf,ysf);
    
    isequal(latProj,latMstruct)
    ans = logical
       1
    
    
    isequal(lonProj,lonMstruct)
    ans = logical
       1
    
    

    Input Arguments

    collapse all

    GeoTIFF information structure, specified as a structure array returned by the geotiffinfo function. The ModelType field of the structure array must have a value of 'ModelTypeProjected'.

    Output Arguments

    collapse all

    Map projection structure, returned as a structure array with fields identical to the properties of an axesm-based map. For more information about the properties of axesm-based maps, see axesm-Based Map Properties. The map projection structure returned by the geotiff2mstruct function reports linear values using meters.

    Version History

    Introduced before R2006a

    See Also

    Functions