Sunday 15 October 2017

proj - How to determine latitude longitude point from a pixel within a MODIS tile?


I need to know latitude / longitude of each pixel in a MODIS tile image in HDF in order to reproject from sinusoidal (MODIS) to mercator (Google Maps). I Can read values from HDF in my C++ program, I can reproject with proj4 having latitude / longitude of a point. I found a MODLAND Tile calculator with source code in c++ but it have too many dependences in Linux libraries and I'm programming a Windows aplication. Any suggestion will be appreciated



Answer



The answer depends on whether you're working with a gridded MODIS product or a swath product (such as L1B)?


Gridded: MODIS data products use a sinusoidal grid. As described on the LPDAAC MODIS overview page, the metadata in the HDF file contain information about the projection parameters and upper/left lower/right corner coordinates of the tile you are looking at. I don't use C++ but Python, but the libraries you need are originally C++ anyway (GEOS/OSR and GDAL, Proj4). You can easily set up a coordinate transform. In Python:


from pyproj import Proj


p_modis_grid = Proj('+proj=sinu +R=6371007.181 +nadgrids=@null +wktext')
x, y = p_modis_grid(lon, lat)
# or the inverse, from x, y to lon, lat
lon, lat = p_modis_grid(x, y, inverse=True)

Swath: In case you're using L1B swath products, you get an additional geolocation file (MOD3... or MYD3...) that contains lat/lon in WGS84 for each 1km (at nadir) raster point. If you want the 500m or 250m resolution you may have to interpolate.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...