Select to view content in your preferred language

Getting table from MakeQueryTable Geoprocessing result

2013
12
Jump to solution
09-02-2023 09:56 AM
AndreasMarth
Emerging Contributor

I am creating a table using the following code.

public async Task MakeQueryTable() {

    var created = await QueuedTask.Run(() => {
        
        bool tableCreated = false;
        string featureClassPath = @"c:\temp\test.gdb\in_featureclass";
        string tablePath = @"c:\temp\test.gdb\in_datatable";

        var valueArray = Geoprocessing.MakeValueArray(featureClassPath + ";" + tablePath, "queryTable", "USE_KEY_FIELDS", null,
            "in_featureclass.OBJECTID #; in_featureclass.ID #; in_featureclass.NAME #; in_datatable.ID #; in_datatable.NAME",
            "in_featureclass.ID = in_datatable.ID And in_featureclass.NAME = in_datatable.NAME");
        
        // Execute the task and DO NOT add the table to the current map!
        Task<IGPResult> gp_result = Geoprocessing.ExecuteToolAsync("management.MakeQueryTable", valueArray, flags: GPExecuteToolFlags.None);

        IGPResult makeTableResult = gp_result.Result;
        // makeTableResult now contains the name "queryTable"

        // Trying to open the table via 
        string newTablePath = @"c:\temp\test.gdb\" + makeTableResult.ReturnValue;

        // Opening this table leads to an error not able to open this table, because it dous not exist in Filegeodatabase

        // If you use GPExecuteToolFlags.AddOutputsToMap in ExecuteToolAsync then you can reference the table in the map
        var newStandaloneTable = MapView.Active.Map.GetStandaloneTablesAsFlattenedList().Where((l) => l.Name == "queryTable").FirstOrDefault() as StandaloneTable;

        return tableCreated;
    });
}

I used the option GPExecuteToolFlags.None, because the result is just a temporary table.

After executing the code, I found no way to get the table object from the GP-Result.

There is a workaround. When you add the table to the active map, the you can find the table there.

var newStandaloneTable = MapView.Active.Map.GetStandaloneTablesAsFlattenedList().Where((l) => l.Name == "queryTable").FirstOrDefault() as StandaloneTable;

 

Is there a way to get the table object without adding the result to the active map?

 

 

 

 

0 Kudos
12 Replies
AndreasMarth
Emerging Contributor

Hi,

thank you for your answer, but FeatureClassToFeatureClass creates a new Dataset and therefore the full path ist returned and you can open the newly created FeatureClass with the path returned by GPResult. MakeQueryTable works different and returns only a table Name and I have found no way so far to reference this table without adding the result table to the active map and then search for the table in the map.

0 Kudos
KenBuja
MVP Esteemed Contributor

Instead of using the geoprocessor to make the query table, can you use a query definition to make the query table from the geodatabase using the OpenQueryTable method?

0 Kudos
AndreasMarth
Emerging Contributor

Hi KenBuja,

this is not the solution for my original question, but using the OpenQueryTable method is a perfect workaround for me.  Thank you so much for your help and have a good day.

0 Kudos