Cant get ArcGIS 10.3.1 “topo to raster” to work in python script

2494
10
08-15-2016 10:18 AM
GeoffreyRawling
New Contributor

I copied the sample python script from this webpage and modified for my own data and paths.

Topo to Raster—Help | ArcGIS for Desktop 

# Name: TopoToRaster_Ex_02.py
# Description: Interpolates a hydrologically correct surface 
#    from point, line, and polygon data.
# Requirements: Spatial Analyst Extension

# testing topo to raster gcr

# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Set environment settings
env.workspace = "D:/clovis_portales/cp_spatial/hydrology/water_level_analysis_v7_py"

# Set local variables
##inPointElevations = TopoPointElevation(['wells_in.shp', 'usgs_wl'])

inContours = TopoContour(['rwl_krg_cntr_smth.shp', 'CONTOUR'])

# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

# Execute TopoToRaster
outTTR = TopoToRaster(inContours)

### Save the output 
##outTTR.save("D:/clovis_portales/cp_spatial/hydrology/water_level_analysis_v7_py/ttrout03")

I keep getting the following errors:

Traceback (most recent call last):
  File "D:\clovis_portales\cp_spatial\hydrology\water_level_analysis_v7_py\ord_krige_2010_2015_wls_v2_for_question_post.py", line 25, in <module>
    outTTR = TopoToRaster(inContours)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\sa\Functions.py", line 2777, in TopoToRaster
    out_contour_error_feature)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\sa\Utils.py", line 53, in swapper
    result = wrapper(*args, **kwargs)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\sa\Functions.py", line 2753, in Wrapper
    out_contour_error_feature)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\geoprocessing\_base.py", line 504, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
RuntimeError: Object: Error in executing tool

It doesnt work with point or contour data. Topo to raster works fine with same data and paths when using the GUI in arc toolbox

thanks in advance for any help

Geoff

Tags (2)
0 Kudos
10 Replies
XanderBakker
Esri Esteemed Contributor

If I look at the code of example 2 at Topo to Raster—Help | ArcGIS for Desktop , I notice that they are using "PointElevation" instead of "Pointelevation". This difference might be something that could create the error.

When using the TopoContour—Spatial Analyst module | ArcGIS for Desktop and TopoPointElevation—Spatial Analyst module | ArcGIS for Desktop classes and using the sample code from those pages. your code would be something like:

import arcpy
import os

# set workspace (still think the path is very long)
ws = "D:\\clovis_portales\\cp_spatial\\hydrology\\water_level_analysis_v7_py"
arcpy.env.workspace = ws

# check out license
arcpy.CheckOutExtension("Spatial")
arcpy.CheckOutExtension("3D")

# set to overwrite outputs
arcpy.env.overwriteOutput = True

# Topo inputs (assuming all input data is store in the ws)
inPointElevations = arcpy.sa.TopoPointElevation([["usgs_CR_wells_w_good_2010_2015_wls_matching_T_08_wells_33_rise_removed.shp","usgs_wl"]])
inContours = arcpy.sa.TopoContour([["rwl_krg_cntr_smth.shp","CONTOUR"]])

# Execute TopoToRaster
outTopoToRaster = arcpy.TopoToRaster_3d([inPointElevations, inContours])

# save the result
outRaster = "wl_surf_smth_kgr_cntrs_and_points.tif"
outTopoToRaster.save(os.path.join(ws, outTopoToRaster))‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I still believe you should shorten the names of your paths and input data, since this may also be a cause for errors.