0

I currently have a raster that has a Geographic Coordinate System but no Projected Coordinate System, which I need to have.

I am using Python and trying to use ArcPy's "ProjectRaster_Management" feature.

So first I have this:

input_directory = 'C:\\Users\\lavendarfire\\files'
arcpy.env.workspace = input_directory
rasters = arcpy.ListRasters("*.hdf")
raster = rasters[0] (just testing one raster)
output_file_name = raster[:-4] + '_test' + ".tif"
input_file_name = "C:\\Users\\lavendarfire\\files\\input.hdf"

and then this:

arcpy.ProjectRaster_management(input_file_name, output_file_name, "PROJCS['World_Mollweide',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['World_Mollweide'],PARAMETER['false_easting',0],PARAMETER['false_northing',0],PARAMETER['central_meridian',0],UNIT['Meter',1.0]]")

This gives me an error.

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in ProjectRaster(in_raster, out_raster, out_coor_system, resampling_type, cell_size, geographic_transform, Registration_Point, in_coor_system, vertical)
  11441         return retval
  11442     except Exception as e:
> 11443         raise e
  11444 
  11445 @gptooldoc('RegisterRaster_management', None)

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in ProjectRaster(in_raster, out_raster, out_coor_system, resampling_type, cell_size, geographic_transform, Registration_Point, in_coor_system, vertical)
  11438     from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject
  11439     try:
> 11440         retval = convertArcObjectToPythonObject(gp.ProjectRaster_management(*gp_fixargs((in_raster, out_raster, out_coor_system, resampling_type, cell_size, geographic_transform, Registration_Point, in_coor_system, vertical), True)))
  11441         return retval
  11442     except Exception as e:

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py in <lambda>(*args)
    509         val = getattr(self._gp, attr)
    510         if callable(val):
--> 511             return lambda *args: val(*gp_fixargs(args, True))
    512         else:
    513             return convertArcObjectToPythonObject(val)

ExecuteError: ERROR 000622: Failed to execute (Project Raster). Parameters are not valid.
ERROR 000628: Cannot set input into parameter out_coor_system.

What am I doing wrong while writing World_Mollweide?

The Projected Coordinate systems PDF from ArcGIS states that the name for what I want can be referred to as "World_Mollweide" 54009 https://desktop.arcgis.com/en/arcmap/latest/map/projections/pdf/projected_coordinate_systems.pdf

7
  • Even the formatting here in is GIS SE shows that the double-quotes in front of World and after Mollweide are not escaped. This is a place for Python's triple-quote technique.
    – Vince
    Commented Feb 16, 2023 at 21:14
  • Thanks for the suggestion Vince. I tried it and it didn't change anything. I saw in this post this person succesfully used ProjectRaster_management and did not have to use triple quotes. Very odd. gis.stackexchange.com/questions/269540/… Commented Feb 16, 2023 at 21:22
  • As a new user, please take the Tour, which emphasizes the importance of asking One question per Question. Please choose one error as the focus of this Question. You should include the exact error message in the body of the Question.
    – Vince
    Commented Feb 16, 2023 at 21:26
  • OK Vince, that got me a step closer. I fixed the quote from a " to a ' and that seemed to help. Now I am getting a different error. "ExecuteError: Error 000622: Failed to Execute (Project Raster). Parameters are not valid. Error 00068. Cannot set input into parameter out_coor_system. Will do, sorry about that Vince. And Thank you. Commented Feb 16, 2023 at 21:27
  • I think the quote (") characters are required in that format. The best way to script things the first time is to run the command from the UI, then "Copy as Python snippet" from the Geoprocessing Results page for that command.
    – Vince
    Commented Feb 16, 2023 at 21:29

1 Answer 1

0

I was able to extract the correct Mollweide info by finding an example tif with the spatial reference I needed and extracting it.

examplefile = "C:Users\\lavendarfire\\files\\example.tif"
projtext=arcpy.Describe(examplefile).spatialReference.exporttostring()
print(projtext)

"PROJCS['World_Mollweide',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Mollweide'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],UNIT['Meter',1.0]];-18040200 -9020200 249642444.505632;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision]]"

It did reproject my raster, but incorrectly since my input has no spatial reference. So figuring that out will be my next step.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.