User inputs for FeatClass and CoordSys ???

740
5
04-25-2020 09:25 PM
AbelPerez
Occasional Contributor III

Trying to work my way through my first add-in. One thing I am struggling with is user inputs. I have a DockPane where the user can input a path to their output feature class and the coordinate system of the output.

The user can input their desired data either by typing in the textbox or using the browse functions to fill that in for them. My struggle is to convert the contents of the textbox to usable objects.

For example, after the user either types in their coordinate system or uses the CoordSysDialog to choose it then how do I convert the result to a SpatialReference object? 

Same thing with the output feature class. From the textbox how do I determine if the feature class is a shapefile or a feature class in a geodb?

What are the best practices for these types of inputs? I see them in the ArcGIS Pro geoprocessing tools so there must be some way to validate each one and the proper type.

0 Kudos
5 Replies
ModyBuchbinder
Esri Regular Contributor

If you try to create a new geoprocessing tool just write it in Python and add it to a toolbox. When you set your paramaters you can define paramater as FeatureClass or coordinate system and the tool framework will to almost everything for you.

If you create some input form in DockPane you will have to work much harder to get the same elevl of functionality.

Have Fun

0 Kudos
AbelPerez
Occasional Contributor III

That's a no go. All my logic is in .NET.

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi Abel,

To check feature class path for existing is very simple:

                        Item currentItem = ItemFactory.Instance.Create(featureClassPath, ItemFactory.ItemType.PathItem);

                        if (!LayerFactory.Instance.CanCreateLayerFrom(currentItem)) {

                           // Invalid path

                        }

To determine if the feature class is a shapefile or a feature class in a geodb you need to check WorkspaceFactory value from CIMStandardDataConnection class or from layer:

https://community.esri.com/message/920599-best-way-to-determine-the-full-path-of-a-featurelayer-if-i...

To check spatial reference you need to try create it. Which method use to create you must decide yourself.

https://github.com/esri/arcgis-pro-sdk/wiki/ProSnippets-Geometry

0 Kudos
AbelPerez
Occasional Contributor III

Gintautas Kmieliauskas‌ thanks for the input. I have some implemented code that was a hack based on the extension of the file in the path. However I will give your suggestion a try since that seems to be more SDK based.

0 Kudos
AbelPerez
Occasional Contributor III

Gintautas Kmieliauskas‌ I looked at your samples and don't think this will work. My process is as follows:

1.  Run a standard ESRI gp tool "management.CreateFishnet". The tool will throw an exception if invalid geodb path or folder do not exist so the user can provide a geodb feature class or a shapefile feature class path for use as OUTPUT to the tool.

2. After the gp tool finishes I then iterate through each feature and modify the geometry. This is custom code so it doesn't exist as an ESRI gp tool. In order for me to do this I need to know the type of the output feature class so i can open it. I need to use FileSystemConnectionPath for shapefiles and FileGeodatabaseConnectionPath for a geodb feat class. The example assumes you have a layer with a feature class attached to it.

0 Kudos