Convert latitude-longitude coordinates to pixel coordinates

`[row, col ] = latlon2pix(R,lat,lon)`

`[row, col ] = latlon2pix(R,lat,lon)`

calculates
pixel coordinates `row`

, `col`

from
latitude-longitude coordinates `lat`

, `lon`

.
`R`

is either a 3-by-2 referencing matrix that transforms
intrinsic pixel coordinates to geographic coordinates, or a geographic
raster reference object. `lat`

and `lon`

are
vectors or arrays of matching size. The outputs `row`

and `col`

have
the same size as `lat`

and `lon`

. `lat`

and `lon`

must
be in degrees.

Longitude wrapping is handled in the following way: Results
are invariant under the substitution `lon = lon +/- n * 360`

where `n`

is
an integer. Any point on the Earth that is included in the image or
gridded data set corresponding to `r`

will yield
row/column values between 0.5 and 0.5 + the image height/width, regardless
of what longitude convention is used.

Find the pixel coordinates of the upper left and lower right outer corners of a 2-by-2 degree gridded data set.

R = makerefmat(1, 89, 2, 2); [UL_row, UL_col] = latlon2pix(R, 90, 0) % Upper left [LR_row, LR_col] = latlon2pix(R, -90, 360) % Lower right [LL_row, LL_col] = latlon2pix(R, -90, 0) % Lower left

Note that the in both the 2nd case and 3rd case we get a column value of 0.5, because the left and right edges are on the same meridian and (-90, 360) is the same point as (-90, 0).

Was this topic helpful?