Main Content

map2pix

(To be removed) Convert map coordinates to pixel coordinates

The map2pix function will be removed in a future release. Use the worldToIntrinsic function instead. For more information, see Compatibility Considerations.

Syntax

[row,col] = map2pix(R,x,y)
p = map2pix(R,x,y)
[...] = map2pix(R,s)

Description

[row,col] = map2pix(R,x,y) calculates pixel coordinates row,col from map coordinates x,y. R is either a 3-by-2 referencing matrix defining a 2-dimensional affine transformation from intrinsic pixel coordinates to map coordinates, or a map raster reference object. x and y are vectors or arrays of matching size. The outputs row and col have the same size as x and y.

p = map2pix(R,x,y) combines row and col into a single array p. If x and y are column vectors of length n, then p is an n-by-2 matrix and each p(k,:) specifies the pixel coordinates of a single point. Otherwise, p has size [size(row) 2], and p(k1,k2,...,kn,:) contains the pixel coordinates of a single point.

[...] = map2pix(R,s) combines x and y into a single array s. If x and y are column vectors of length n, the s should be an n-by-2 matrix such that each row (s(k,:)) specifies the map coordinates of a single point. Otherwise, s should have size [size(X) 2], and s(k1,k2,...,kn,:) should contain the map coordinates of a single point.

Examples

% Find the pixel coordinates for the spatial coordinates 
% (207050, 912900)
[X,cmap] = imread('concord_ortho_w.tif');
R = worldfileread('concord_ortho_w.tfw','planar',size(X));
[r,c] = map2pix(R,207050,912900);

Version History

Introduced before R2006a

expand all

R2023a: Warns

Some functions that accept referencing matrices as input issue a warning that they will be removed in a future release, including the map2pix function. Use a map raster reference object and the worldToIntrinsic function instead. Reference objects have several advantages over referencing matrices.

  • Unlike referencing matrices, reference objects have properties that document the size of the associated raster, its limits, and the direction of its rows and columns. For more information about reference object properties, see the MapPostingsReference and MapCellsReference objects.

  • You can manipulate the limits of rasters associated with reference objects using the mapcrop function.

  • You can manipulate the size and resolution of rasters associated with reference objects using the mapresize function.

  • Most functions that accept referencing matrices as inputs also accept reference objects.

To update your code, first create a reference object for either a raster of cells using the maprefcells function or a raster of regularly posted samples using the maprefpostings function. Alternatively, convert from a referencing matrix to a reference object using the refmatToMapRasterReference function.

Then, replace uses of the map2pix function with the worldToIntrinsic function according to these patterns.

Will Be RemovedRecommended
[row,col] = map2pix(R,x,y);
[col,row] = worldToIntrinsic(R,x,y);
p = map2pix(R,x,y);

If x and y are column vectors:

[col,row] = worldToIntrinsic(R,x,y);
p = [row col];

If row and col have size M-by-N or 1-by-N:

[col,row] = worldToIntrinsic(R,x,y);
p = cat(3,row,col);

[row,col] = map2pix(R,s);

If s has size N-by-2:

[col,row] = worldToIntrinsic(R,s(:,1),s(:,2));