public void UpdateParameters(ESRI.ArcGIS.esriSystem.IArray paramvalues, ESRI.ArcGIS.Geoprocessing.IGPEnvironmentManager pEnvMgr) { try { IGPUtilities3 gpUtilities3 = new GPUtilitiesClass(); IGPValue inputOSMGPValue = gpUtilities3.UnpackGPValue(paramvalues.get_Element(in_osmFeatureClass)); IFeatureClass osmFeatureClass = null; ITable osmInputTable = null; IQueryFilter osmQueryFilter = null; try { gpUtilities3.DecodeFeatureLayer(inputOSMGPValue, out osmFeatureClass, out osmQueryFilter); osmInputTable = osmFeatureClass as ITable; } catch { } try { if (osmInputTable == null) { gpUtilities3.DecodeTableView(inputOSMGPValue, out osmInputTable, out osmQueryFilter); } } catch { } if (osmInputTable == null) { return; } String illegalCharacters = String.Empty; ISQLSyntax sqlSyntax = ((IDataset)osmInputTable).Workspace as ISQLSyntax; if (sqlSyntax != null) { illegalCharacters = sqlSyntax.GetInvalidCharacters(); } // find the field that holds tag binary/xml field int osmTagCollectionFieldIndex = osmInputTable.FindField("osmTags"); // if the Field doesn't exist - wasn't found (index = -1) get out if (osmTagCollectionFieldIndex == -1) { return; } if (((IGPParameter)paramvalues.get_Element(in_attributeSelector)).Altered) { IGPParameter tagCollectionParameter = paramvalues.get_Element(in_attributeSelector) as IGPParameter; IGPMultiValue tagCollectionGPValue = gpUtilities3.UnpackGPValue(tagCollectionParameter) as IGPMultiValue; IGPCodedValueDomain codedTagDomain = tagCollectionParameter.Domain as IGPCodedValueDomain; for (int attributeValueIndex = 0; attributeValueIndex < tagCollectionGPValue.Count; attributeValueIndex++) { string valueString = tagCollectionGPValue.get_Value(attributeValueIndex).GetAsText(); IGPValue testFieldValue = codedTagDomain.FindValue(valueString); if (testFieldValue == null) { codedTagDomain.AddStringCode(valueString, valueString); } } // Get the derived output feature class schema and empty the additional fields. This ensures // that you don't get dublicate entries. // Derived output is the third parameter, so use index 2 for get_Element. IGPParameter3 derivedFeatures = (IGPParameter3)paramvalues.get_Element(out_osmFeatureClass); IGPFeatureSchema schema = (IGPFeatureSchema)derivedFeatures.Schema; schema.AdditionalFields = null; IFieldsEdit fieldsEdit = new FieldsClass(); for (int valueIndex = 0; valueIndex < tagCollectionGPValue.Count; valueIndex++) { string tagString = tagCollectionGPValue.get_Value(valueIndex).GetAsText(); if (tagString != "ALL") { // Check if the input field already exists. string cleanedTagKey = convert2AttributeFieldName(tagString, illegalCharacters); IField tagField = gpUtilities3.FindField(inputOSMGPValue, cleanedTagKey); if (tagField == null) { IFieldEdit fieldEdit = new FieldClass(); fieldEdit.Name_2 = cleanedTagKey; fieldEdit.AliasName_2 = tagCollectionGPValue.get_Value(valueIndex).GetAsText(); fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldEdit.Length_2 = 100; fieldsEdit.AddField(fieldEdit); } } } // Add the additional field to the derived output. IFields fields = fieldsEdit as IFields; schema.AdditionalFields = fields; } //if (inputOSMGPValue.IsEmpty() == false) //{ // if (((IGPParameter)paramvalues.get_Element(in_osmFeatureClass)).HasBeenValidated == false) // { // IGPParameter tagCollectionGPParameter = paramvalues.get_Element(in_attributeSelector) as IGPParameter; // IGPValue tagCollectionGPValue = gpUtilities3.UnpackGPValue(tagCollectionGPParameter); // IGPCodedValueDomain osmTagKeyCodedValues = new GPCodedValueDomainClass(); // if (((IGPMultiValue)tagCollectionGPValue).Count == 0) // { // if (osmTagKeyCodedValues == null) // extractAllTags(ref osmTagKeyCodedValues, osmInputTable, osmQueryFilter, osmTagCollectionFieldIndex, true); // if (osmTagKeyCodedValues != null) // { // tagsParameter = tagCollectionGPParameter as IGPParameterEdit; // tagsParameter.Domain = (IGPDomain)osmTagKeyCodedValues; // } // } // else // { // // let's take the given values and make then part of the domain -- if they are not already // // if we don't do this step then we won't pass the internal validation // IGPCodedValueDomain gpTagDomain = tagCollectionGPParameter.Domain as IGPCodedValueDomain; // if (gpTagDomain != null) // { // if (gpTagDomain.CodeCount == 0) // { // // let's add the value existing in the mentioned multi value to the domain // for (int i = 0; i < ((IGPMultiValue)tagCollectionGPValue).Count; i++) // { // string tagStringValue = ((IGPMultiValue)tagCollectionGPValue).get_Value(i).GetAsText(); // gpTagDomain.AddStringCode(tagStringValue, tagStringValue); // } // ((IGPParameterEdit)tagCollectionGPParameter).Domain = gpTagDomain as IGPDomain; // } // } // } // // Get the derived output feature class schema and empty the additional fields. This ensures // // that you don't get dublicate entries. // // Derived output is the third parameter, so use index 2 for get_Element. // IGPParameter3 derivedFeatures = (IGPParameter3)paramvalues.get_Element(out_osmFeatureClass); // IGPFeatureSchema schema = (IGPFeatureSchema)derivedFeatures.Schema; // schema.AdditionalFields = null; // // Area field name is the second parameter, so use index 1 for get_Element. // IGPMultiValue tagsGPMultiValue = gpUtilities3.UnpackGPValue(paramvalues.get_Element(in_attributeSelector)) as IGPMultiValue; // IFieldsEdit fieldsEdit = new FieldsClass(); // bool extractALLTags = false; // // check if the list contains the "ALL" keyword // for (int valueIndex = 0; valueIndex < tagsGPMultiValue.Count; valueIndex++) // { // if (tagsGPMultiValue.get_Value(valueIndex).GetAsText().Equals("ALL")) // { // extractALLTags = true; // } // } // if (extractALLTags) // { // if (osmTagKeyCodedValues == null) // { // extractAllTags(ref osmTagKeyCodedValues, osmInputTable, osmQueryFilter, osmTagCollectionFieldIndex, false); // } // if (osmTagKeyCodedValues != null) // { // for (int valueIndex = 0; valueIndex < osmTagKeyCodedValues.CodeCount; valueIndex++) // { // // Check if the input field already exists. // string cleanedTagKey = convert2AttributeFieldName(osmTagKeyCodedValues.get_Value(valueIndex).GetAsText(), illegalCharacters); // IField tagField = gpUtilities3.FindField(inputOSMGPValue, cleanedTagKey); // if (tagField == null) // { // IFieldEdit fieldEdit = new FieldClass(); // fieldEdit.Name_2 = cleanedTagKey; // fieldEdit.AliasName_2 = osmTagKeyCodedValues.get_Value(valueIndex).GetAsText(); // fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; // fieldEdit.Length_2 = 100; // fieldsEdit.AddField(fieldEdit); // } // } // } // } // else // { // for (int valueIndex = 0; valueIndex < tagsGPMultiValue.Count; valueIndex++) // { // // Check if the input field already exists. // string cleanedTagKey = convert2AttributeFieldName(tagsGPMultiValue.get_Value(valueIndex).GetAsText(), illegalCharacters); // IField tagField = gpUtilities3.FindField(inputOSMGPValue, cleanedTagKey); // if (tagField == null) // { // IFieldEdit fieldEdit = new FieldClass(); // fieldEdit.Name_2 = cleanedTagKey; // fieldEdit.AliasName_2 = tagsGPMultiValue.get_Value(valueIndex).GetAsText(); // fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; // fieldEdit.Length_2 = 100; // fieldsEdit.AddField(fieldEdit); // } // } // } // // Add the additional field to the derived output. // IFields fields = fieldsEdit as IFields; // schema.AdditionalFields = fields; // } //} } catch { } }