3

Using ArcGIS 10.3 I'm receiving the dreaded 'ERROR 999999' when attempting to project a geodatabase full of rasters from WGS84_UTM_zone_10N to Nad83_BC_Environment_Albers

import arcpy

InRasterGDB = r"C:\Users\PoirierM\Documents\GISData\LandsatSSTImagery.gdb"
OutRasterGDB = r"C:\Users\PoirierM\Documents\GISData\LandsatSSTImageryAlbers.gdb"
OutCoordSystem = "3005"
ResampleType = "BILINEAR"
CellSize = "30 30"
GeoTransform = "WGS_1984_(ITRF00)_To_NAD_1983"
InCoordSystem = "32610"

arcpy.env.workspace = InRasterGDB

for fname in arcpy.ListRasters():
    print fname
    print OutRasterGDB + "\\"  + fname
    arcpy.ProjectRaster_management(InRasterGDB + "\\" + fname, OutRasterGDB + "\\" + fname, OutCoordSystem, ResampleType, CellSize, GeoTransform, "", InCoordSystem)

This should work, but it returns the following error when run in the Python Window in ArcCatalog:

Runtime error
  Traceback (most recent call last):
   File "<string>", line 16, in <module>
   File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 9009, in ProjectRaster
     raise e ExecuteError: ERROR 999999: Error executing function. Failed to execute (ProjectRaster). 

I can do a single raster manually through either the tool interface or within modelbuilder. Can anyone suggest why it won't work as a Python script?


I've got a working script now - see my (MPoirier) answer below.

  • Cell size "30 30" looks very strange – FelixIP Feb 18 '15 at 19:18
  • @FelixIP I pasted '30 30' in from the python export of modelbuilder to see if it made a difference, originally I was using '30'. I believe either is valid. – MPoirier Feb 18 '15 at 20:06
  • try changing output to folder, not fgdb. Works sometimes for me – FelixIP Feb 18 '15 at 20:12
  • Does the output raster exist? Try set arcpy.env.overwriteOutput = True. Many times this is the cause of error 99999 Error executing function (which really means developer couldn't be bothered writing a true error message so figure it out yourself). Also please double check the GeoTransform, the parameter is very fussy and it has to be spelled exactly right. – Michael Stimson Feb 18 '15 at 22:07
5

I believe the problem might be in your coordinate system definitions -- ref. the Project Raster help page.

The coordinate system to which the input raster will be projected. The default value is set based on the Output Coordinate System environment setting.

Valid values for this parameter are

  • A file with the ".prj" extension (the prj files which ship with ArcGIS can be found in "C:\Program Files\ArcGIS\Coordinate Systems").
  • An existing feature class, feature dataset, raster catalog (basically anything with a coordinate system).
  • The string representation of a coordinate system. These lengthy strings can be generated by adding a coordinate system variable to ModelBuilder, setting the variable's value as desired, then exporting the model to a Python script.

You're giving it WKIDs directly, which isn't listed as an option.

But, you can make a spatial reference via the WKID using the SpatialReference property.

OutCoordSystem = arcpy.SpatialReference(3005)
InCoordSystem = arcpy.SpatialReference(32610)
| improve this answer | |
  • Thanks @Erica, I've been using the more recent documentation link. However the same error is thrown whether I use the arcpy.SpatialReference method or just pasting in the full string representation of the coordinate system from model builder. – MPoirier Feb 18 '15 at 20:00
  • Try running the arcpy.ProjectRaster_management operation on just one raster in the Python window, instead of the loop -- I'm curious if it's breaking because of the variable name in some way, or because of the tool parameters? – Erica Feb 18 '15 at 20:13
  • That doesn't work if I just edit my exisiting code. I have started from scratch and now have a working model which I'll post as a seperate answer. – MPoirier Feb 18 '15 at 22:09
2

Here's a working script. I started from the modelbuilder code for reprojecting a single raster, and incrementally changed inputs to variables testing at each step. Seemingly the only difference between the working script below and my previous non-functioning script is that the variables are defined within the body of the for loop.

I've also added some comments to make things clear.

##Script for looping through a file geodatabase to find rasters and reproject them from WGS_1984_UTM_zone_10N to NAD_1983_BC_Environment_Albers
    ## Matthew Poirier, Last modified February 18th 2015

    # Import arcpy module
    import arcpy

    #Define workspace (geodatabase location)
    InRasterGDB = r"C:\Users\PoirierM\Documents\GISData\LandsatSSTImagery.gdb"
    arcpy.env.workspace = InRasterGDB

    #Loop through list of all rasters in the workspace
    for Ras in arcpy.ListRasters():

    # Local variables for input (optional) and output:
        InRas = "C:\\Users\\PoirierM\\Documents\\GISData\\LandsatSSTImagery.gdb\\" + Ras 
        OutRas = "C:\\Users\\PoirierM\\Documents\\GISData\\LandsatSSTImageryAlbers.gdb\\" + Ras

    # Define the projection strings - could also use string longform copied from modelbuilder script (tested) or an existing .prj file
        InProj = "PROJCS['WGS_1984_UTM_zone_10N',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['false_easting',500000.0],PARAMETER['false_northing',0.0],PARAMETER['central_meridian',-123.0],PARAMETER['scale_factor',0.9996],PARAMETER['latitude_of_origin',0.0],UNIT['Meter',1.0]]"
        OutProj = "PROJCS['NAD_1983_BC_Environment_Albers',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Albers'],PARAMETER['False_Easting',1000000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-126.0],PARAMETER['Standard_Parallel_1',50.0],PARAMETER['Standard_Parallel_2',58.5],PARAMETER['Latitude_Of_Origin',45.0],UNIT['Meter',1.0]]"

    # Specify the geographic datum transformation method to be used
        GeoTran = "WGS_1984_(ITRF00)_To_NAD_1983"

    # Specify the resampling type (bilinear or cubic for continuous data, defaults to nearest)
        ReSample = "BILINEAR"

    # Define the output cell size (defaults to that of the input raster
        CellSize = "30 30"

    # Process: Project Raster - note empty quotes are placeholder for optional 'registration_point' parameter
        arcpy.ProjectRaster_management(InRas, OutRas, OutProj, ReSample, CellSize, GeoTran, "", InProj)
| improve this answer | |
  • The only (real) difference I can see is the spatial references are in WKT format. Erica was absolutely correct in converting the EPSG codes into Esri SpatialReference objects but WKT works too. From an Esri SpatialReference object you can call the method ExportToString() to get the WKT from the EPSG code if that floats your boat. – Michael Stimson Feb 19 '15 at 0:01
  • Note that pasting the spatial references from the working script into the non-working script did not make it work. So while it is a difference, I do not think it is why I was receiving an error. – MPoirier Feb 19 '15 at 0:06
  • Now that is weird! Perhaps there is something else coincidental like a different input raster, a new output database, environment setting... Looking at your original syntax it should work with proper spatial reference objects or WKT strings. – Michael Stimson Feb 19 '15 at 0:51
  • The definitive test of the WKT/WKID options would be test the WKID in this version of the script. I agree overall with Michael that there's something else weird tripping up the original syntax. (All too often, it just comes down to starting over from scratch and somehow that works.) – Erica Feb 19 '15 at 18:41
0

Try passing cell size as one dimension.

like:

CellSize = "30"

Otherwise try testing the script without any of the optional parameters and see what happens.

| improve this answer | |
  • This has no effect -> same error produced. Though '30 30' is a valid input as it is a 30x30 grid (export of modelbuilder model uses this). – MPoirier Feb 18 '15 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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