mfwdtran

Project geographic features to map coordinates

Syntax

[x,y] = mfwdtran(lat,lon)
[x,y,z] = mfwdtran(lat,lon,alt)
[...] = mfwdtran(mstruct,...)

Description

[x,y] = mfwdtran(lat,lon) applies the forward transformation defined by the map projection in the current map axes. You can use this function to convert point locations and line and polygon vertices given in latitudes and longitudes to a planar, projected map coordinate system.

[x,y,z] = mfwdtran(lat,lon,alt) applies the forward projection to 3-D input, resulting in 3-D output. If the input alt is empty or omitted, then alt = 0 is assumed.

[...] = mfwdtran(mstruct,...) requires a valid map projection structure as the first argument. In this case, no map axes is needed.

Examples

The following latitude and longitude data for the District of Columbia is obtained from the usastatelo shapefile:

dc = shaperead('usastatelo', 'UseGeoCoords', true,...
    'Selector',{@(name) strcmpi(name,'District of Columbia'),...
    'Name'});
lat = [dc.Lat]';
lon = [dc.Lon]';
[lat lon]

ans =
   38.9000  -77.0700
   38.9500  -77.1200
   39.0000  -77.0300
   38.9000  -76.9000
   38.7800  -77.0300
   38.8000  -77.0200
   38.8700  -77.0200
   38.9000  -77.0700
   38.9000  -77.0500
   38.9000  -77.0700
       NaN       NaN

Before projecting the data, it is necessary to define projection parameters. You can do this with the axesm function or with the defaultm function:

mstruct = defaultm('mercator');
mstruct.origin = [38.89 -77.04 0];
mstruct = defaultm(mstruct);

Now that the projection parameters have been set, transform the District of Columbia data into map coordinates using the Mercator projection:

[x,y] = mfwdtran(mstruct,lat,lon);
[x y]

ans =
   -0.0004    0.0002
   -0.0011    0.0010
    0.0001    0.0019
    0.0019    0.0002
    0.0001   -0.0019
    0.0003   -0.0016
    0.0003   -0.0003
   -0.0004    0.0002
   -0.0001    0.0002
   -0.0004    0.0002
       NaN       NaN
Was this topic helpful?