Convert standalone table to a feature layer .net sdk

1414
3
01-25-2023 02:31 AM
GISNewbieDev
New Contributor II

 

Hi,

I am working on creating multiple plugin data sources. For the files that are not recognizable by the ArcGIS Pro I have created the custom item and then converting the data source into the feature layer.

I also have some file extensions that are recognizable by the ArcGIS Pro like csv and txt.  In those cases since cant create custom item (which as per documentation even if created will be ignored) so I have created a drag and drop handler and therefore converting them into feature classes. 

But this will not cover the scenarios of converting file into feature layers from places like Add Data dropdown in the Map tab ribbon, Add to current map, Add to new map (in the context menu).  In these scenarios its just adding the file as a standalone table which is by default. But I want to add feature layer as well in these scenarios. 

So now what I am thinking if we can capture certain event and then implement the same. I tried the StandaloneTablesAddedEvent since in all those scenarios, a standalone table is added. But the problem or the blocker I am facing that I am not able to convert standalone table to feature layer then.

StandaloneTablesAddedEvent.Subscribe(OnStandaloneTableAdded);

private void OnStandaloneTableAdded(StandaloneTableEventArgs args)
{

}

Any ideas or help here??

@GKmieliauskas @Wolf @UmaHarano 

 

Tags (1)
0 Kudos
3 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

To make a point feature layer from table you need to execute xy table to point geoprocessing tool.

Code here:

      var sr = MapView.Active.Map.SpatialReference;
      
      var environments = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true);
      var cts = new CancellationTokenSource();

      //Make the GP Tool arg array
      var args = Geoprocessing.MakeValueArray(input_table, outputFC, XField, YField, "", sr);
      //Execute
      _ = await Geoprocessing.ExecuteToolAsync("XYTableToPoint_management", args, environments, cts.Token,
                        (eventName, o) =>
                        {
                          System.Diagnostics.Debug.WriteLine($@"GP event: {eventName}");
                        }, GPExecuteToolFlags.None); //No action is taken, so the new Feature class doesn't get added to the map

 

Your question theme is very similar to this:

https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-feature-layers-using-plugins-for-diffe... 

0 Kudos
GISNewbieDev
New Contributor II

I can have one more use case that can come whether can we access the data of standalone table because I may have to write the custom logic on the columns of the standalone table and then maybe we can use that table in the same way we use in Plugin data sources to create the features. Basically to reuse the plugin approach to create the feature layer using standalone table.

The custom logic is maybe we need to determine whether we can create lines out of those points.

Therefore can we create a custom logic by accessing the data of standalone table and then creating the feature class out of it without any Geoprocessing tool?

@GKmieliauskas 

0 Kudos
GKmieliauskas
Esri Regular Contributor

You can create feature layer from feature class, but not from table. Table doesn't have geometry. You need to create featureclass in memory or project gdb, create features in it using your table data and then you can create feature layer from LayerFactory

0 Kudos