Convert latitude-longitude coordinates to pixel coordinates
[row, col ] = latlon2pix(R,lat,lon)
[row, col ] = latlon2pix(R,lat,lon) calculates
R is either a 3-by-2 referencing matrix that transforms
intrinsic pixel coordinates to geographic coordinates, or a geographic
raster reference object.
vectors or arrays of matching size. The outputs
the same size as
be in degrees.
Longitude wrapping is handled in the following way: Results
are invariant under the substitution
lon = lon +/- n * 360 where
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).