Main Content

geographicToDiscrete

Convert geographic coordinates to discrete subscripts

Description

[I,J] = geographicToDiscrete(R,lat,lon) calculates the discrete row and column subscripts I and J for the geographic coordinates lat and lon 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 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

Raster reference, specified as a GeographicCellsReference or GeographicPostingsReference object.

Latitude coordinates, specified as a numeric array. The size of lat must match the size of lon.

Data Types: single | double

Longitude coordinates, specified as a numeric array. The size of lon must match the size of lat.

Data Types: single | double

Output Arguments

collapse all

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

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

If the kth input coordinates (lat(k),lon(k)) fall outside the raster bounds in the geographic 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 lon.

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

If the kth input coordinates (lat(k),lon(k)) fall outside the raster bounds in the geographic 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