I want to project HDF files (MODIS images) to another coordinate system using ArcPy. The following is the code I wrote:
input_ras="N:\\mod16a2\\MOD16A2.A2001001.h24v05.006.2017068142418.hdf"
out_ras= "\test.tif"
# the coordinate system which is required
out_co="G:\\Rathore\\vic_auto7\\shape_proj.prj"
arcpy.ProjectRaster_management(in_raster=input_raster,out_raster=out_ras,out_coor_system=out_co)
This script produces the following error:
ExecuteError Traceback (most recent call last)
<ipython-input-95-0d17576ef2fe> in <module>()
arcpy.ProjectRaster_management(in_raster=input_ras,out_raster="out_ras,out_coor_system=out_co)
C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py in ProjectRaster(in_raster, out_raster, out_coor_system, resampling_type, cell_size, geographic_transform, Registration_Point, in_coor_system)
9700 return retval
9701 except Exception as e:
-> 9702 raise e
9703
9704 @gptooldoc('RegisterRaster_management', None)
ExecuteError: Failed to execute. Parameters are not valid.
Undefined coordinate system for input dataset.
Failed to execute (ProjectRaster).
I checked the projection of input file and it is:
"PROJCS['Unknown_datum_based_upon_the_custom_spheroid_Sinusoidal',GEOGCS['GCS_Unknown_datum_based_upon_the_custom_spheroid',DATUM['D_Not_specified_based_on_custom_spheroid',SPHEROID['Custom_spheroid',6371007.181,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Sinusoidal'],PARAMETER['false_easting',0.0],PARAMETER['false_northing',0.0],PARAMETER['central_meridian',0.0],UNIT['Meter',1.0]]")
1 Answer 1
The way to resolve this is to put in the full projection of the coordinate system for input dataset as an argument to ProjectRaster_management
:
arcpy.ProjectRaster_management (ifpn, ofpn, "4326", "NEAREST", "#", "#", "#", "PROJCS['Unknown_datum_based_upon_the_custom_spheroid_Sinusoidal',GEOGCS['GCS_Unknown_datum_based_upon_the_custom_spheroid',DATUM['D_Not_specified_based_on_custom_spheroid',SPHEROID['Custom_spheroid',6371007.181,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Sinusoidal'],PARAMETER['false_easting',0.0],PARAMETER['false_northing',0.0],PARAMETER['central_meridian',0.0],UNIT['Meter',1.0]]")
ifpn
and ofpn
are my input and output rasters respectively. If these are already assigned your variables (as you did with input_ras
and out_ras
), you don't need to reassign them within the function.
N:\\mod16a2\\MOD16A2.A2001001.h24v05.006.2017068142418.hdf
to beC:\\temp\\test.hdf
and use that path instead of the one with multiple dots in it?