I am trying to use the .NET wrapper for the ContourList geoprocessing tool by reading in a text file and then supplying the necessary properties. Everything works when I use the wrapper for the Contour tool so I know my code basically works. But when I switch to the ContourList tool and try to set the .contour_values property (instead of the .contour_interval and .base_contour properties of the Contour tool), it fails. The list of contour values coming in from the text file is a single line of comma delimited numbers. I can't figure out how to interpret that line so that the tool will take it. Public Function ContourRaster(ByVal sSourcePath As String, ByVal sInterval As String, ByVal sBase As String, ByVal sList As String) As String
Try
'calculates contours from the input raster and then applies symbology
Dim gp As ESRI.ArcGIS.Geoprocessor.Geoprocessor = New ESRI.ArcGIS.Geoprocessor.Geoprocessor()
Dim contour As ESRI.ArcGIS.SpatialAnalystTools.Contour = New ESRI.ArcGIS.SpatialAnalystTools.Contour()
Dim conlist As ESRI.ArcGIS.SpatialAnalystTools.ContourList = New ESRI.ArcGIS.SpatialAnalystTools.ContourList()
Dim sSourceDir As String
Dim sOutName As String
Dim sOutPath As String
'tried some different kinds of arrays
Dim lList As New List(Of Double)
Dim darray As IDoubleArray = New DoubleArray
Dim parameters As IVariantArray = New VarArray
fso = CreateObject("Scripting.FileSystemObject")
sSourceDir = fso.GetParentFolderName(sSourcePath) 'gets parent folder of the base file or folder
sOutName = fso.GetBaseName(sSourcePath) 'gets the base file (w/o extension) or folder (esri grid)
sOutPath = sSourceDir & "\" & sOutName & "_cnt.shp"
If sList = "" Then
With contour
.in_raster = sSourcePath
.out_polyline_features = sOutPath
.contour_interval = sInterval
.base_contour = sBase
End With
gp.Execute(contour, Nothing)
Else
parameters.Add(Convert.ToDouble(sList.Split(",")(0)))
parameters.Add(Convert.ToDouble(sList.Split(",")(1)))
With conlist
.in_raster = sSourcePath
.out_polyline_features = sOutPath
'I have tried to set contour_values to the incoming string as well as a variety of arrays
.contour_values = parameters
End With
gp.Execute(conlist, Nothing)
End If
'return the outputs parameter to what it was
gp.AddOutputsToMap = bDefOutputs
'return the path to the contours data source
ContourRaster = sOutPath
Catch e As Exception
Shuterdown(e)
End Try
End Function