// This method will update the output parameter value with the additional area field.
        public void UpdateParameters(IArray paramvalues, IGPEnvironmentManager pEnvMgr)
        {
            m_Parameters = paramvalues;

            // Retrieve the input parameter value
            IGPValue parameterValue = m_GPUtilities.UnpackGPValue(m_Parameters.get_Element(0));

            // Get the derived output feature class schema and empty the additional fields. This will ensure you don't get duplicate entries.
            IGPParameter3    derivedFeatures = (IGPParameter3)paramvalues.get_Element(2);
            IGPFeatureSchema schema          = (IGPFeatureSchema)derivedFeatures.Schema;

            schema.AdditionalFields = null;

            // If we have an input value, create a new field based on the field name the user entered.
            if (parameterValue.IsEmpty() == false)
            {
                IGPParameter3 fieldNameParameter = (IGPParameter3)paramvalues.get_Element(1);
                string        fieldName          = fieldNameParameter.Value.GetAsText();

                // Check if the user's input field already exists
                IField areaField = m_GPUtilities.FindField(parameterValue, fieldName);
                if (areaField == null)
                {
                    IFieldsEdit fieldsEdit = new FieldsClass();
                    IFieldEdit  fieldEdit  = new FieldClass();
                    fieldEdit.Name_2 = fieldName;
                    fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                    fieldsEdit.AddField(fieldEdit);

                    // Add an additional field for the area values to the derived output.
                    IFields fields = fieldsEdit as IFields;
                    schema.AdditionalFields = fields;
                }
            }
        }
Esempio n. 2
0
        /*
         * Called each time the user changes a parameter in the tool dialog or Command Line.
         * This updates the output data of the tool, which extremely useful for building models.
         * After returning from UpdateParameters(), geoprocessing calls its internal validation routine checkng that a given set of parameter values
         * are of the appropriate number, DataType, and value.
         * This method will update the output parameter value with the unique field.
         */
        public void UpdateParameters(IArray paramvalues, IGPEnvironmentManager pEnvMgr)
        {
            m_Parameters = paramvalues;

            // Retrieve the input parameter value
            IGPValue parameterValue = m_GPUtilities.UnpackGPValue(m_Parameters.get_Element(0));

            // Retrieve the unique field parameter value
            IGPParameter3 fieldNameParameter = (IGPParameter3)paramvalues.get_Element(3);

            // Get the output feature class schema and empty the additional fields. This will ensure
            // you don't get dublicate entries.
            IGPParameter3    outputFeatures = (IGPParameter3)paramvalues.get_Element(2);
            IGPFeatureSchema schema         = (IGPFeatureSchema)outputFeatures.Schema;

            schema.AdditionalFields = null;

            // If we have an unique field value, create a new field based on the unique field name the user entered.
            if (fieldNameParameter.Value.IsEmpty() == false)
            {
                string fieldName = fieldNameParameter.Value.GetAsText();

                IField      uniqueField = m_GPUtilities.FindField(parameterValue, fieldName);
                IFieldsEdit fieldsEdit  = new FieldsClass();
                fieldsEdit.AddField(uniqueField);

                IFields fields = fieldsEdit as IFields;
                schema.AdditionalFields = fields;
            }
        }