Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

  1. Do I need to check out a license like I would with ArcPy?
  2. Am I parameterizing in a strange way?
  3. 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?

share|improve this question
1  
Have you tried registering an events listener, as described here? –  Kirk Kuykendall May 23 '13 at 17:12
    
+1 @KirkKuykendall - this is always good practice. –  Nick Ochoski May 23 '13 at 17:25
add comment

2 Answers 2

up vote 2 down vote accepted

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:

Dim lCount as Long = 10
neartable.closest_count = lCount

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:

GP.SetEnvironmentValue("workspace", "C:\workspacepathgoeshere")

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?

share|improve this answer
    
Altered the code. I'm still getting error code 99999 (extra helpful). Visual Studio is returning A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in ESRI.ArcGIS.Geoprocessor.dll Any thoughts? I'm on 10.1. –  Jay Laura May 23 '13 at 17:01
    
I've edited my answer to include some additional things you should be checking. –  Nick Ochoski May 23 '13 at 17:29
    
Double check all of your inputs - you're passing in two strings when the GP expects a Long and a Boolean. –  Nick Ochoski May 23 '13 at 17:35
    
To answer the questions: (1) Made the change. (2) Yes. (3) I removed that line. I tested both FC and FL. (4) Yes, This is generating a KNN table. (5) Done. (6) Implementing now. I am still seeing the same error, so I'll dig into Kirk's link to look under the hood. –  Jay Laura May 23 '13 at 17:36
    
I made a quick edit that you might have missed - have you double checked both the input Long and Boolean that were being passed strings? –  Nick Ochoski May 23 '13 at 17:38
show 4 more comments

I recently dealt with a similar problem; I wanted to pass an SDE layer as .near_features and it only worked when I passed the layer's path string. Talked to the Esri Support and they came back a few days later and said it was a bug.

Bug number: #NIM102924 Synopsis: Generate Near table geoprocessing tool s "Near Features" parameter doesn't accept FeatureLayer objects when passed from SDE.

A way to work around it until they fix the bug is to pass the layer's name.

ILayer layer = //your layer;
generateNearTable.near_features = layer.name;

This worked for me.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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