0

I have an ArcPy script that extracts a stream network from any chunk of terrain. It takes the terrain and if it's in a GCS, it projects it to the correct UTM zone prior to further processing. Though the projection is accomplished successfully, it's failing to successfully perform the fill sink operation. Here is the code in question.

out_raster = r"in_memory\utm_{}".format(utm_grid_name)
utm_projected_terrain = arcpy.ProjectRaster_management(dted, out_raster, projection_string)
arcpy.AddMessage('Done reprojecting raster.')

arcpy.CheckOutExtension("Spatial")

#do the fill
outfill = Fill(utm_projected_terrain)
arcpy.AddMessage('Done with fill sinks')

I keep this in memory because this workstation has 128gb RAM, it's more efficient and quicker to perform the analysis here. The terrain file size is anywhere from around 35-100mb.

Here is the error I'm getting; strangely it seems to do with Spatial Reference:

Traceback (most recent call last):
  File"C:\Temp\PyCharmProjects\Hydro\stream-network-extractor.py", line 81, in <module>
    outfill = Fill(utm_projected_terrain)
  File "c:\arcgis\pro\Resources\arcpy\arcpy\sa\Functions.py", line 2307, in Fill
    z_limit)
  File "c:\arcgis\pro\Resources\arcpy\arcpy\sa\Utils.py", line 53, in swapper
    result = wrapper(*args, **kwargs)
  File "c:\arcgis\pro\Resources\arcpy\arcpy\sa\Functions.py", line 2303 in Wrapper
    z_limit)
  File c:\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 496, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 999999: Something unexpected caused the tool to fail.  Please refer to the error help for potential solutions, or contact Esri Technical Support http://esriurl.com/support.
No spatial reference exists.
Failed to execute (Fill).
Failed to execute (StreamOrderExtractor).

So this mystifies me because when I run the reprojection script on its own, in the in_memory environment, I get a good result, there is a spatial reference, no errors in the output. Why is Fill failing?

  • have you tried running the fill on out_raster rather than utm_projected_terrain? I don't think the management tools write outputs the same way that spatial analyst tools do. – Lovette Oct 25 '18 at 19:06
  • I'll give it a shot and report back, thanks for the suggestion – auslander Oct 25 '18 at 19:09
  • 1
    arcpy.Raster is missing. – FelixIP Oct 25 '18 at 19:15
  • 1
    Can you check whether you can manually run the output_raster in any geoprocessing tools, outside the arcpy script? Not just the Fill tool, maybe even a generate hillshade/slope. Just to make sure the arcpy.ProjectRaster_management() is outputing it correctly. Can you load the raster in ArcGIS Pro/ArcMap and view it correctly? – Sorin RUSU Oct 25 '18 at 20:12
  • 1
    I was going to suggest qgis as a viable alternative, and you will also be freed from any licensing fees. Glad to hear the script is working in SAGA – Sorin RUSU Oct 26 '18 at 5:28
0

After a lot of research, I sorted this out. It turns out that it had to do with the way I was creating the initial raster. Even though the script was saying there was a "raster object" as the initial input, and even though the projection generated a correctly referenced raster in standalone mode, I had to integrate the following in my code. I list it here to close the question because it fixed my problem; perhaps it is a helpful tip to someone else in the future.

Instead of issuing a Spatial Reference string, I had to get a Spatial Reference object:

sr = arcpy.SpatialReference()
sr.factoryCode = epsg # the EPSG code for the correct UTM zone, pulled earlier
sr.create()

Now I can do:

utm_grid_name = arcpy.CreateScratchName("utm_")
utm_projected_terrain = arcpy.ProjectRaster_management(dted, utm_grid_name, sr)

And all the algebra works from that point on.

Lesson learned: be 100% sure that a valid layer/filetype/dataset is being generated for input.

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.