Main Content

geographicToDiscrete

Transform geographic to discrete coordinates

Description

[I,J] = geographicToDiscrete(R,lat,lon) returns the indices corresponding to geographic coordinates lat and lon in geographic 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 elevation data [1] for a region in Colorado as an array and a GeographicPostingsReference object. Find the indices of the posting point nearest to the latitude and longitude of South Boulder Peak, which are 39.9539 and -105.2992 degrees, respectively.

[Z,R] = readgeoraster('n39_w106_3arc_v2.dt1');
[I,J] = geographicToDiscrete(R,39.9539,-105.2992)
I = 
56
J = 
842

The result means that the posting point closest to the geographic coordinates is in row 56 and column 842 of the array.

[1] The elevation data used in this example is from the U.S. Geological Survey.

Input Arguments

collapse all

Geographic raster, specified as a GeographicCellsReference or GeographicPostingsReference object.

Latitude coordinates, specified as a numeric array.

Data Types: single | double

Longitude coordinates, specified as a numeric array. lon is the same size as lat.

Data Types: single | double

Output Arguments

collapse all

Longitude indices, returned as an array of integers. I is the same size as lat.

For an m-by-n raster, 1 ≤ Im, except for points ( lat(k), lat(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

Latitude indices, returned as an array of integers. J is the same size as lat.

For an m-by-n raster, 1 ≤ Jnexcept for points ( lat(k), lat(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