Reprojection of modis products
Posted: Mon Sep 30, 2024 2:52 pm America/New_York
Problem: Reprojecting MOD09A1 MODIS Images with GDAL to Match Google Earth Engine Output
Hi everyone,
I'm encountering an issue while trying to reproduce the output of Google Earth Engine (GEE) using the AppEEARS API for the same MODIS product (MOD09A1.061).
I used a shapefile to define an area of interest and downloaded the image in GEE, saving it as earthengine_image.tif (in EPSG:4326 by default). I performed the equivalent operation in the AppEEARS API but in MODIS sinusoidal projection, the output file was named appeears_image.tif.
As i've seen in some forums discussions, the Earth Engine team believes the modis sinusoidal projection has some error, and therefore they override in their ingestion process. The projection they use is the following:
PROJCS["MODIS Sinusoidal",
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.01745329251994328,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]],
PROJECTION["Sinusoidal"],
PARAMETER["false_easting",0.0],
PARAMETER["false_northing",0.0],
PARAMETER["central_meridian",0.0],
PARAMETER["semi_major",6371007.181],
PARAMETER["semi_minor",6371007.181],
UNIT["m",1.0],
AUTHORITY["SR-ORG","6974"]]
To compare both images, I tried to apply a similar reprojection using GDAL in Python. Below is the code I used to reproject appeears_image.tif into EPSG:4326:
# Python Code
from osgeo import gdal, osr
def correct_modis_projection(input_file, output_file):
# Open the input MODIS image in update mode
dataset = gdal.Open(input_file, gdal.GA_Update)
if dataset is None:
raise RuntimeError(f"Unable to open file: {input_file}")
# Define SR-ORG:6974 spatial reference
override_srs = osr.SpatialReference()
override_srs.ImportFromWkt(
"""PROJCS["MODIS Sinusoidal",
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563],
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PROJECTION["Sinusoidal"],
PARAMETER["false_easting",0.0],
PARAMETER["false_northing",0.0],
PARAMETER["central_meridian",0.0],
UNIT["m",1.0],
AUTHORITY["SR-ORG","6974"]]""")
# Reproject to EPSG:4326
output_srs = osr.SpatialReference()
output_srs.ImportFromEPSG(4326)
gdal.Warp(output_file, dataset, srcSRS=override_srs, dstSRS=output_srs)
dataset = None # Save and close the dataset
# End of Python Code
correct_modis_projection("appeears_image.tif", "earthengine_equivalent_image.tif")
However, even after reprojecting and removing any padding, the resulting image earthengine_equivalent_image.tif does not match the original earthengine_image.tif.
Does anyone have experience with this kind of issue? Could you point out where my approach might be wrong or suggest the correct steps to align the two images?
I don't have much knowledge in GIS, so i would really appreciate if someone could help me reproject any MOD09A1 image to the earthengine equivalent.
The reason i need to do this is to use some masks earth engine have, but without the correct projection, i get shifts and distortions in the output raster image.
Any help would be really appreciated!
Thanks in advance for your help!
Hi everyone,
I'm encountering an issue while trying to reproduce the output of Google Earth Engine (GEE) using the AppEEARS API for the same MODIS product (MOD09A1.061).
I used a shapefile to define an area of interest and downloaded the image in GEE, saving it as earthengine_image.tif (in EPSG:4326 by default). I performed the equivalent operation in the AppEEARS API but in MODIS sinusoidal projection, the output file was named appeears_image.tif.
As i've seen in some forums discussions, the Earth Engine team believes the modis sinusoidal projection has some error, and therefore they override in their ingestion process. The projection they use is the following:
PROJCS["MODIS Sinusoidal",
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.01745329251994328,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]],
PROJECTION["Sinusoidal"],
PARAMETER["false_easting",0.0],
PARAMETER["false_northing",0.0],
PARAMETER["central_meridian",0.0],
PARAMETER["semi_major",6371007.181],
PARAMETER["semi_minor",6371007.181],
UNIT["m",1.0],
AUTHORITY["SR-ORG","6974"]]
To compare both images, I tried to apply a similar reprojection using GDAL in Python. Below is the code I used to reproject appeears_image.tif into EPSG:4326:
# Python Code
from osgeo import gdal, osr
def correct_modis_projection(input_file, output_file):
# Open the input MODIS image in update mode
dataset = gdal.Open(input_file, gdal.GA_Update)
if dataset is None:
raise RuntimeError(f"Unable to open file: {input_file}")
# Define SR-ORG:6974 spatial reference
override_srs = osr.SpatialReference()
override_srs.ImportFromWkt(
"""PROJCS["MODIS Sinusoidal",
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563],
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PROJECTION["Sinusoidal"],
PARAMETER["false_easting",0.0],
PARAMETER["false_northing",0.0],
PARAMETER["central_meridian",0.0],
UNIT["m",1.0],
AUTHORITY["SR-ORG","6974"]]""")
# Reproject to EPSG:4326
output_srs = osr.SpatialReference()
output_srs.ImportFromEPSG(4326)
gdal.Warp(output_file, dataset, srcSRS=override_srs, dstSRS=output_srs)
dataset = None # Save and close the dataset
# End of Python Code
correct_modis_projection("appeears_image.tif", "earthengine_equivalent_image.tif")
However, even after reprojecting and removing any padding, the resulting image earthengine_equivalent_image.tif does not match the original earthengine_image.tif.
Does anyone have experience with this kind of issue? Could you point out where my approach might be wrong or suggest the correct steps to align the two images?
I don't have much knowledge in GIS, so i would really appreciate if someone could help me reproject any MOD09A1 image to the earthengine equivalent.
The reason i need to do this is to use some masks earth engine have, but without the correct projection, i get shifts and distortions in the output raster image.
Any help would be really appreciated!
Thanks in advance for your help!