Sunday, February 22, 2015

Create Fields Collection Esri ArcObjects Snippets - Series

Esri ArcObjects Snippets - Series

Create Fields Collection



 // create field collection for table  
 public IFields createFieldsCollectionForTable() throws Exception {  
      // Create a new fields collection.  
      IFields fields = new Fields();  
      // Cast for IFieldsEdit to modify the properties of the fields  
      // collection.  
      IFieldsEdit fieldsEdit = (IFieldsEdit) fields;  
      // Set the FieldCount to the total number of fields to be created.  
      fieldsEdit.setFieldCount(2);  
      // Create the ObjectID field.  
      IField fieldUserDefined = new Field();  
      // Cast for IFieldEdit to modify the properties of the new field.  
      IFieldEdit fieldEdit = (IFieldEdit) fieldUserDefined;  
      fieldEdit.setAliasName("FID");  
      fieldEdit.setName("ObjectID");  
      fieldEdit.setType(esriFieldType.esriFieldTypeOID);  
      // Add the new field to the fields collection.  
      fieldsEdit.setFieldByRef(0, fieldUserDefined);  
      // Create the text field.  
      fieldUserDefined = new Field();  
      fieldEdit = (IFieldEdit) fieldUserDefined;  
      fieldEdit.setLength(30); // Only string fields require that you set the  
                                         // length.  
      fieldEdit.setName("Owner");  
      fieldEdit.setType(esriFieldType.esriFieldTypeString);  
      // Add the new field to the fields collection.  
      fieldsEdit.setFieldByRef(1, fieldUserDefined);  
      return fields;  
 }  




This code has been made using ESRI Resources and other Help Content and is provided here just for educational purpose.

No comments:

Post a Comment