Main Content

worldToDiscrete

Transform planar world to discrete coordinates

Description

[I,J] = worldToDiscrete(R,xWorld,yWorld) returns the indices corresponding to world coordinates xWorld and yWorld in map raster R. If R.RasterInterpretation is:

  • 'cells', then I and J are the row and column subscripts of the raster cells (or image pixels)

  • 'postings', then I and J refer to the nearest sample point (posting)

example

Examples

collapse all

Import a GeoTIFF image [1] of Boston as an array and a MapCellsReference object. Find the indices of the cell containing data with world x- and y-coordinates of 776500 and 2956600 survey feet, respectively.

[Z,R] = readgeoraster('boston.tif');
[I,J] = worldToDiscrete(R,776500,2956600)
I = 1212
J = 3714

The result means that the cell center closest to the world coordinates is in row 1212 and column 3714 of the array.

[1] The data used in this example includes material copyrighted by GeoEye, all rights reserved.

Input Arguments

collapse all

Map raster, specified as a MapCellsReference or MapPostingsReference object.

x-coordinates in the world coordinate system, specified as a numeric array.

Data Types: single | double

y-coordinates in the world coordinate system, specified as a numeric array. yWorld is the same size as xWorld.

Data Types: single | double

Output Arguments

collapse all

World x-coordinate indices, returned as an array of integers. I is the same size as xWorld.

For an m-by-n raster, 1 ≤ Im, except for points (xWorld(k), yWorld(k)) that fall outside the bounds of the raster as defined by the function contains. In this case I(k) and J(k) are NaN.

Data Types: double

World y-coordinate indices, returned as an array of integers. J is the same size as yWorld.

For an m-by-n raster, 1 ≤ Im, except for points (xWorld(k), yWorld(k)) that fall outside the bounds of the raster as defined by the function contains. In this case I(k) and J(k) are NaN.

Data Types: double

Version History

Introduced in R2013b