Is it possible to specify fields to create feature class with?

2945
6
01-30-2017 04:00 AM
MaxMax2
Occasional Contributor II

Wiki page on the ArcGIS Pro SDK github states that all schema creation and modification operations such as creating tables and feature classes, creating and modifying fields, enabling attachments, and so on, need to be performed using the Geoprocessing API.

Now let's imagine that you develop a tool that takes FGDB feature class, does some magic with its features and writes result to shapefile. But you want the output feature class will have exactly the same fields as the input one. OK, you are going to use Create Feature Class geoprocessing tool for that, passing the input feature class as template parameter. But if input fields contains those which name consist of more than 10 characters, you will get an error.

Is it possible to take input fields, correct them (or do any other actions) and pass modified fields to the method that creates a feature class?

The only workaround I see now is to create feature class without template and then add each field one by one with Add Field geoprocessing tool. But it is obviously bad solution since it is very slow when working with a lot of fields. It is sad to know that DDL in ArcGIS Pro SDK is much less flexible than in ArcObjects

6 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

 You are correct the DDL (Data Definition Language) which is used to define different structures of a database is not part of the ArcGIS Pro API.  So currently you have to use GeoProcessing tasks to manipulate Feature Classes and their structure.  I tried the workflow that you described and used a File Geodatabase Feature Class as a template for a new FGDB Feature Class.  I also made sure that my 'template Feature Class' contained field names with more than 10 characters.  However, I didn't experience the truncation of the attribute names that you described above nor did I get any errors.  I then used the 'Feature Class To Shapefile' GeoProcessing task which truncated my field names to 10 characters which is the length limit for shape file field names.  I was also able to use the 'Alter Field' GeoProcessing task to change field names with names longer than 10 characters without getting any errors.

0 Kudos
MaxMax2
Occasional Contributor II

Hi Wolfgang,

Thanks for reply.

I wrote:

Now let's imagine that you develop a tool that takes FGDB feature class, does some magic with its features and writes result to shapefile.

So you need to use FGDB feature class as a template for a new shapefile. Shapefile doesn't allow field names longer than 10 characters so shapefile cannot be created with fields that violate this rule. In addition to this scenario I can provide another one: FGDB feature class with a GUID field used as a template for a new shapefile. You will get an error from Create Feature Class tool (ERROR 999999: Error executing function) since fields of this type are not supported by shapefiles.

Tools like Feature Class to Feature Class and Feature Class to Shapefile are not an option. I need to create new feature class rather than transfer existing feature class to the new destination.

I can provide many real scenarios where fields must be processed somehow prior to create feature class with them. The point of my post is the ability to specify fields need to be exist in the ArcGIS Pro SDK. Even if Create Feature Class tool will not fail on scenarios described above the problem will remain for some tasks. Example of such task: you need to create mapping between input fields and output fields. If Create Feature Class tool will automatically correct field names it will be impossible in general to determine origin fields for the fields in new feature class since:

  1. output field names differ from the input ones;
  2. there is no guarantee that order of fields in output feature class is the same as in the input one.

I believe that creation of an empty feature class and then adding fields one by one with Add Field tool is bad solution. Is it recommended workflow for described task?

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

 You are correct in your assessment of these limitations.  Needless to say some limitations are coming from limitations of the Shapefile standard, like the field name length and the GUID data type.  To get your workflow done I can only suggest to create a FGDB feature class template that works around these Shapefile limitations by using field names shorter than 10 characters and changes the data types to Shapefile supported types (i.e. GUID turns into a text field).  In this scenario field names shouldn't differ anymore (allowing you to map those fields) and you shouldn't get a '999999 error' for unsupported field types. 

0 Kudos
MaxMax2
Occasional Contributor II

Hi Wolfgang,

But how can I create a feature class template with corrected fields if there is no possibility to specify fields collection in Create Feature Class tool? What you've suggested is: to create a feature class with corrected fields I need create feature class with corrected fields. It's recursion!

Well, it seems that there is no good solution for the described task at now. I hope that Pro SDK team will do something to make SDK more flexible and appropriate for such common tasks as creation of feature class with specified fields.

I'm not a fan of the conception that all DDL operations must be performed through geoprocessing. But it seems that this decision of the Pro SDK team will not be changed... At least can you provide a tool that will be able to add multiple fields at once in the next release of SDK (something like Add Fields)?

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

 Sorry, but I misunderstood your workflow requirements, I was under the impression that your Shapefile schema is somewhat predictable (hence the template reference) and not totally dynamic.  My suggested workflow would only work if your Shapefile output always contains data of the same type like for example tax parcels, streets, or utility data and depending on your output schema type you could then use a template to generate the required Shapefile.  If your output Shapefile is totally dynamic and is depending on an unknown input schema then this will not work.  I had already relayed your workflow requirements to our product engineers and they are still checking on various GeoProcessing task input parameter options to see if schema creation can be made easier with the current release of ArcGIS Pro.  If we find a better option (over adding one field at a time) we add the answer on this thread, but I also added your 'add multiple fields' tool to our requirement list of the next release. 

MaxMax2
Occasional Contributor II

Thank you, Wolfgang. I will be waiting for the next Pro SDK release

0 Kudos