I am working on launching the GenerateNearTable using the ArcObjects Assembly method. I have the advanced license (10.1), so the tool is available. The code to launch geoprocessing is:
Private Sub generateNearTable(ByRef FeatureLayer)
'Grab the feature class for the GP tool
Dim lcount As Long = 10
Dim closest As Boolean = False
'Setup the geoprocessor
Dim gp As ESRI.ArcGIS.Geoprocessor.Geoprocessor = New ESRI.ArcGIS.Geoprocessor.Geoprocessor
Dim neartable As GenerateNearTable = New GenerateNearTable()
neartable.in_features = FeatureLayer
neartable.near_features = FeatureLayer
neartable.out_table = "C:\Users\jlaura\Desktop\test4" ' Hard code to test.
neartable.closest = closest
neartable.closest_count = lcount 'This should be a parameter
Dim addtomap As Boolean = gp.AddOutputsToMap
gp.SetEnvironmentValue("workspace", "C:\Users\jlaura\Desktop\test")
gp.TemporaryMapLayers = False
gp.AddOutputsToMap = False
Try
gp.Execute(neartable, Nothing)
returnmessages(gp)
Catch ex As Exception
returnmessages(gp)
End Try
End Sub
This is causing an error 99999. The results are being returned to the results tab, so I am able to double click on the failed tool and run it successfully via ArcMap. New to ArcObjects, so I'm definitely missing something obvious.
- Do I need to check out a license like I would with ArcPy?
- Am I parameterizing in a strange way?
- Do I need to pass the dataset (IDataset) instead of the featureclass? #This failed when I tried it, but perhaps I missed something…
As an extension (that I can open as a new question if people think it is too disconnected) – to programatically set the output table, can I generate an empty, 'fieldless' standalone table and let the tool handle writing.
Updated Code:
Private Sub generateNearTable(ByVal distlayer, ByVal knn, ByVal DistanceTableOut)
Dim FeatureLayer = GetFLayerByName(distlayer)
Dim NearFeatureLayer = GetFLayerByName(distlayer) 'Fails if I use this.
'Setup Params
Dim lcount As Long = knn
Dim closest As Boolean = False
'Setup the geoprocessor
Dim gp As New ESRI.ArcGIS.Geoprocessor.Geoprocessor
Dim genneartable As GenerateNearTable = New GenerateNearTable()
'Setup the Gp Environment
Dim addtomap As Boolean = gp.AddOutputsToMap
gp.TemporaryMapLayers = False
gp.AddOutputsToMap = True 'Add the derived table to the map doc.
gp.OverwriteOutput = True
'Set Params
genneartable.in_features = FeatureLayer
genneartable.near_features = "C:\Users\jlaura\Desktop\Zunil\Zunil_secondaries_proj.shp"
genneartable.out_table = DistanceTableOut
genneartable.closest = closest
genneartable.closest_count = lcount 'This should be a parameter
'Execute
Try
gp.Execute(genneartable, Nothing)
If gp.MessageCount > 0 Then
For count As Integer = 0 To gp.MessageCount - 1
MsgBox(gp.GetMessage(count), MsgBoxStyle.OkCancel, "Working")
Next
End If
Catch ex As Exception
End Try
End Sub
EDIT:
I am doing something wrong with the feature layer inputs. By hard coding the path to the shapefiles I am able to successfully run the tool. Back to the drawing board, re: featurelayer access.
EDIT2: The tools runs properly if the featurelayer is passed for the in_features
and hard coded for the near_features. In this case should I be reaccessing the feature layer from the input?
Best Answer
Edited (for the sake of others in a similar situation):
There are a few things you should be checking:
1) You're passing in a string for the
neartable.closest_count
variable when it requires a Long data type. Try this:Also, the
neartable.closest
variable is being passed a String when it expects a Boolean (ALL = True).2) Are you sure what you are passing in is actually an IFeatureLayer?
3) Why are you getting the FeatureClass from the FeatureLayer if you're never using that variable?
4) Your input features and near features are the same - is this what you want?
5) You might consider setting all of the GeoProcessor properties, especially the EnvironmentValue:
6) An Events Listener (as mentioned by Kirk) can provide important information
7) Does the output table that you are trying to create already exist?