Ejemplo n.º 1
0
        /// <summary>
        /// 添加属性字段
        /// </summary>
        /// <param name="dsTarget"></param>
        /// <param name="newFields"></param>
        /// <returns></returns>
        public static bool AddFields(ITable dsTarget, List <IField> newFields)
        {
            if (dsTarget == null || newFields == null || newFields.Count == 0)
            {
                return(false);
            }

            try
            {
                Geoprocessor geoProcessor = new Geoprocessor();
                foreach (IField field in newFields)
                {
                    ESRI.ArcGIS.DataManagementTools.AddField gpAddField = new ESRI.ArcGIS.DataManagementTools.AddField();
                    gpAddField.in_table   = dsTarget;
                    gpAddField.field_name = field.Name;
                    gpAddField.field_type = GetFieldTypeGpString(field.Type);

                    gpAddField.field_alias = field.AliasName;
                    if (field.Domain != null)
                    {
                        gpAddField.field_domain = field.Domain.Name;
                    }

                    gpAddField.field_is_nullable = field.IsNullable.ToString();
                    gpAddField.field_is_required = field.Required.ToString();
                    gpAddField.field_length      = field.Length;
                    gpAddField.field_precision   = field.Precision;
                    gpAddField.field_scale       = field.Scale;

                    IGeoProcessorResult gpResult = geoProcessor.Execute(gpAddField, null) as IGeoProcessorResult;
                    if (gpResult.Status != esriJobStatus.esriJobSucceeded)
                    {
                        return(false);
                    }
                }
                //System.Runtime.InteropServices.Marshal.FinalReleaseComObject(geoProcessor);


                return(true);
            }
            catch (Exception exp)
            {
                ErrorMessage = exp.Message;
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加属性字段
        /// </summary>
        /// <param name="dsTarget"></param>
        /// <param name="newFields"></param>
        /// <returns></returns>
        public static bool AddFields(ITable dsTarget, List<IField> newFields)
        {
            if (dsTarget == null || newFields == null || newFields.Count == 0)
                return false;

            try
            {
                Geoprocessor geoProcessor = new Geoprocessor();
                foreach (IField field in newFields)
                {
                    ESRI.ArcGIS.DataManagementTools.AddField gpAddField = new ESRI.ArcGIS.DataManagementTools.AddField();
                    gpAddField.in_table = dsTarget;
                    gpAddField.field_name = field.Name;
                    gpAddField.field_type = GetFieldTypeGpString(field.Type);

                    gpAddField.field_alias = field.AliasName;
                    if (field.Domain != null)
                        gpAddField.field_domain = field.Domain.Name;

                    gpAddField.field_is_nullable = field.IsNullable.ToString();
                    gpAddField.field_is_required = field.Required.ToString();
                    gpAddField.field_length = field.Length;
                    gpAddField.field_precision = field.Precision;
                    gpAddField.field_scale = field.Scale;

                    IGeoProcessorResult gpResult = geoProcessor.Execute(gpAddField, null) as IGeoProcessorResult;
                    if (gpResult.Status != esriJobStatus.esriJobSucceeded)
                        return false;
                }
               //System.Runtime.InteropServices.Marshal.FinalReleaseComObject(geoProcessor);

                return true;
            }
            catch(Exception exp)
            {
                ErrorMessage = exp.Message;
                return false;
            }
        }