Main Content

defaultm

Create or reset map projection structure

    Description

    mstruct = defaultm(projid) creates a map projection structure using the projection ID projid.

    example

    mstruct = defaultm(mstructIn) resets the map projection structure mstructIn by updating empty and dependent fields. The function updates the origin, flatlimit, flonlimit, maplatlimit, and maplonlimit fields so they are compatible with each other and with the mapprojection field. When the structure represents a UTM or UPS coordinate system, the function also updates the zone field.

    Note

    To set up a map projection structure, you must use the defaultm function twice. These steps show how to set up a map projection structure.

    1. Create a map projection structure with default values by using the syntax defaultm(projid).

    2. Customize the map projection structure by specifying values for fields such as origin, maplatlim, and maplonlim.

    3. Update empty and dependent fields of the map projection structure by using the syntax defaultm(mstructIn).

    example

    Examples

    collapse all

    Create a map projection structure using a Mercator projection. By default, many of the fields are empty.

    mstruct = defaultm("mercator")
    mstruct = struct with fields:
         mapprojection: 'mercator'
                  zone: []
            angleunits: 'degrees'
                aspect: 'normal'
         falsenorthing: []
          falseeasting: []
           fixedorient: []
                 geoid: [1 0]
           maplatlimit: []
           maplonlimit: []
          mapparallels: 0
            nparallels: 1
                origin: []
           scalefactor: []
               trimlat: [-86 86]
               trimlon: [-180 180]
                 frame: []
                 ffill: 100
            fedgecolor: 'default'
            ffacecolor: 'none'
             flatlimit: []
            flinewidth: 2
             flonlimit: []
                  grid: []
             galtitude: Inf
                gcolor: 'default'
            glinestyle: ':'
            glinewidth: 0.5000
        mlineexception: []
             mlinefill: 100
            mlinelimit: []
         mlinelocation: []
          mlinevisible: 'on'
        plineexception: []
             plinefill: 100
            plinelimit: []
         plinelocation: []
          plinevisible: 'on'
             fontangle: 'normal'
             fontcolor: 'default'
              fontname: 'Helvetica'
              fontsize: 10
             fontunits: 'points'
            fontweight: 'normal'
           labelformat: 'compass'
         labelrotation: 'off'
            labelunits: []
         meridianlabel: []
        mlabellocation: []
        mlabelparallel: []
           mlabelround: 0
         parallellabel: []
        plabellocation: []
        plabelmeridian: []
           plabelround: 0
    
    

    Specify the map origin. Then, update empty fields and fields that depend on the map origin, such as the map latitude and longitude limits, by using the defaultm function again.

    mstruct.origin = [0 90 0];
    mstruct = defaultm(mstruct)
    mstruct = struct with fields:
         mapprojection: 'mercator'
                  zone: []
            angleunits: 'degrees'
                aspect: 'normal'
         falsenorthing: 0
          falseeasting: 0
           fixedorient: []
                 geoid: [1 0]
           maplatlimit: [-86 86]
           maplonlimit: [-90 270]
          mapparallels: 0
            nparallels: 1
                origin: [0 90 0]
           scalefactor: 1
               trimlat: [-86 86]
               trimlon: [-180 180]
                 frame: 'off'
                 ffill: 100
            fedgecolor: 'default'
            ffacecolor: 'none'
             flatlimit: [-86 86]
            flinewidth: 2
             flonlimit: [-180 180]
                  grid: 'off'
             galtitude: Inf
                gcolor: 'default'
            glinestyle: ':'
            glinewidth: 0.5000
        mlineexception: []
             mlinefill: 100
            mlinelimit: []
         mlinelocation: 30
          mlinevisible: 'on'
        plineexception: []
             plinefill: 100
            plinelimit: []
         plinelocation: 15
          plinevisible: 'on'
             fontangle: 'normal'
             fontcolor: 'default'
              fontname: 'Helvetica'
              fontsize: 10
             fontunits: 'points'
            fontweight: 'normal'
           labelformat: 'compass'
         labelrotation: 'off'
            labelunits: 'degrees'
         meridianlabel: 'off'
        mlabellocation: 30
        mlabelparallel: 86
           mlabelround: 0
         parallellabel: 'off'
        plabellocation: 15
        plabelmeridian: -90
           plabelround: 0
    
    

    Project coordinates by using a map projection structure instead of an axesm-based map.

    Create a map projection structure for a sinusoidal projection.

    mstruct = defaultm("sinusoid");

    Specify map limits and a reference ellipsoid for the map projection structure. Populate additional fields of the structure based on the map limits by using the defaultm function again.

    mstruct.maplonlimit = [-150 -30];
    mstruct.geoid = referenceEllipsoid("grs80","kilometers");
    mstruct = defaultm(mstruct);

    Load coastline data and trim it to the map limits. Then, project the latitude and longitude coordinates by using the projfwd function and the map projection structure.

    load coastlines
    [lat,lon] = maptriml(coastlat,coastlon,mstruct.maplatlimit,mstruct.maplonlimit);
    [x,y] = projfwd(mstruct,lat,lon);

    Display the projected coordinates in a Cartesian axes.

    figure
    plot(x,y)
    axis equal

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

    Input Arguments

    collapse all

    Projection ID, specified as a character vector or a string scalar.

    This code shows how to list the supported projection IDs in the Command Window by using the maps function.

    m = maps("idlist")

    For more information about supported projection IDs, see Summary and Guide to Projections.

    Data Types: char | string

    Input map projection structure, specified as a structure 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.

    Output Arguments

    collapse all

    Map projection structure, returned as a structure with fields identical to the properties of an axesm-based map. Examples of map projection structure fields include the projection name, angle unit, origin, aspect, false easting, and false northing. For more information about the properties of axesm-based maps, see axesm-Based Map Properties.

    A map projection structure enables you to project and unproject geographic coordinates without creating an axesm-based map. You can project coordinates by using a map projection structure as input with the projfwd or vfwdtran function. You can unproject coordinates by using a map projection structure as input with the projinv or vinvtran function.

    Tips

    • By default, the angle-valued fields of map projection structures are in degrees. If you must work in radians, update the angleunits field of the structure and then reset the structure. This code shows how to update your map projection structure to use radians.

      mstruct = defaultm("mercator");
      mstruct.angleunits = "radians";
      mstruct = defaultm(mstruct);

      Once you update a structure to use radians, you must use radians when you change angle-valued fields such as origin, parallels, maplatlimit, and maplonlimit.

    • You can get a map projection structure from an axesm-based map by using the gcm function. This code shows how to create the same map projection structure by using the defaultm function as from an axesm-based map.

      % Set longitude limits and define reference ellipsoid
      lonlim = [-150 -30];
      ref = referenceEllipsoid("grs80","kilometers");
      
      % Create map projection structure using defaultm
      mstruct1 = defaultm("sinusoid");
      mstruct1.maplonlimit = lonlim;
      mstruct1.geoid = ref;
      mstruct1 = defaultm(mstruct1);
      
      % Create map projection structure from axesm-based map
      abm = axesm("sinusoid","maplonlimit",lonlim,"geoid",ref);
      mstruct2 = gcm(abm);
      f = gcf;
      close(f)
      
      % Compare map structures
      isequal(mstruct1,mstruct2)

    Version History

    Introduced before R2006a

    expand all