Main Content

worldToDiscrete

Convert planar world coordinates to discrete subscripts

Description

[I,J] = worldToDiscrete(R,xWorld,yWorld) calculates the discrete row and column subscripts I and J for the world coordinates xWorld and yWorld based on the relationship defined by the raster reference object R.

The interpretation of I and J depend on the RasterInterpretation property of R.

  • 'cells'I and J are the row and column subscripts of the raster cells or image pixels.

  • 'postings'I and J are the row and column subscripts of the nearest posting point sample.

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

Raster reference, specified as a MapCellsReference or MapPostingsReference object.

x-coordinates in the world coordinate system, specified as a numeric array. The size of xWorld must match the size of yWorld.

Data Types: single | double

y-coordinates in the world coordinate system, specified as a numeric array. The size of yWorld must match the size of xWorld.

Data Types: single | double

Output Arguments

collapse all

Row indices, returned as an array of integers. I is the same size as yWorld.

For an m-by-n raster and world coordinates that are within the raster bounds, the values of I are in the range [1, m].

If the kth input coordinates (xWorld(k),yWorld(k)) fall outside the raster bounds in the world coordinate system, then the function sets the corresponding subscripts I(k) and J(k) to NaN values.

Data Types: double

Column indices, returned as an array of integers. J is the same size as xWorld.

For an m-by-n raster and world coordinates that are within the raster bounds, values of J are in the range [1, n].

If the kth input coordinates (xWorld(k),yWorld(k)) fall outside the raster bounds in the world coordinate system, then the function sets the corresponding subscripts I(k) and J(k) to NaN values.

Data Types: double

Version History

Introduced in R2013b