Find pixel indices in HDF-EOS files based on LatLon coordinates
Updated 15 Jun 2012
This function takes Latitude-Longitude pairs with name of an HDF-EOS file and finds the X-Y indexes of each LatLon pair in the HDF file. The function will work with HDF files which have:
1. Sinusoidal Projection (e.g., MODIS LST Level 3 product);
2. Global Cylindrical Equal-Area Projection or Cylindrical Equal-Area Scalable Earth Grid (EASE)
Important: LatLon pairs must be given in a matrix where first column contains Latitude and the SECOND COLUMN LONGITUDE, while the function will write X as first and Y as the second output. One or more pairs of LatLon coordinates can be given, where each line will contain coordinates of one point. The first two output variables will contain the X and Y indexes with the same order as LatLon inputs. The function is tested with the MODIS LST Level 3 (MOD11A1) and MODIS BRDF/Albedo (MCD43B3) products for proj=1 (Sinusoidal), and AMSR-E Soil Moisture (AMSR_E_L3_DailyLand_V07) product for proj=2 (EASE grid).
LatLon: matrix with two columns: Latitudes and Longitudes
filename: HDF file name (including filepath if file is not in current
proj: Projection type of the HDF file (currently only 1 or 2)
coordX_idx: x indexes of given LatLon coordinate(s) in the given HDF file
coordY_idx: y indexes of given LatLon coordinate(s) in the given HDF file (if
0 is returned by coordX_idx or coordY_idx means the LatLon pair could
not be found in the given image/HDF file).
projType: (string) full name of the given projection type
mdist2point: minimum distance to each point in meters that the function
could work out (should not be bigger than xRes or yRes).
xRes: resolution of the image along x or longitudes (it is always positive)
yRes: resolution of the image along y or latitudes (since Latitudes decrease from UppeLeft to LowerRight corner of an image, this will be a negative value--> note: this is now updated to be always positive).
%download the following file and put it in the current directory:
[coordX_idx,coordY_idx,projType,mdist2point,xRes,yRes] = ...
The returned coordX_idx coordY_idx are indexes of the LST pixels covering 1km^2 in the above coordinates.
First Version: Feb 19 2012 (V01)
Added functionailty: Apr 25 2012 (V02)
Updated: Jun 15 2012
M Sohrabinia (2023). Find pixel indices in HDF-EOS files based on LatLon coordinates (https://www.mathworks.com/matlabcentral/fileexchange/37033-find-pixel-indices-in-hdf-eos-files-based-on-latlon-coordinates), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Inspired: Sinusoidal Projection grid for NASA Level 3 Ocean Biology data
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.