ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

ArcGIS Pro二次开发属性更新,把所有选择的ID为1

2020-03-13 22:00:12  阅读:346  来源: 互联网

标签:MessageBox Dialogs Show Pro Desktop ArcGIS Framework 二次开发


        public void UpdateValues()
        {
            //  This sample is intended for use with a featureclass with a default text field named "Description".
            //  You can replace "Description" with any field name that works for your dataset

            // Check for an active mapview
            if (MapView.Active == null)
            {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("No MapView currently active. Exiting...", "Info");
                return;
            }

            QueuedTask.Run(() =>
            {

                // Get the layer selected in the Contents pane, and prompt if there is none:
                if (MapView.Active.GetSelectedLayers().Count == 0)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("No feature layer selected in Contents pane. Exiting...", "Info");
                    return;
                }
                // Check to see if there is a selected feature layer
                var featLayer = MapView.Active.GetSelectedLayers().First() as FeatureLayer;
                if (featLayer == null)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("A feature layer must be selected. Exiting...", "Info");
                    return;
                }
                // Get the selected records, and check/exit if there are none:
                var featSelectionOIDs = featLayer.GetSelection().GetObjectIDs();
                if (featSelectionOIDs.Count == 0)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("No records selected for layer, " + featLayer.Name + ". Exiting...", "Info");
                    return;
                }
                // Ensure there are values in the two edit boxes
               

                // Get the name of the attribute to update, and the value to set:
                string attributename = "ID";
                attributename = attributename.ToUpper();
                string setvalue = "1";

                // Display all the parameters for the update:
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Here are your update parameters:  " +
                    "\r\n Layer: " + featLayer.Name +
                    "\r\n Attribute name: " + attributename +
                    "\r\n Number of records: " + Convert.ToString(featSelectionOIDs.Count) +
                    "\r\n Value to update: " + Convert.ToString(setvalue), "Update");

                try
                {
                    // Now ready to do the actual editing:
                    // 1. Create a new edit operation and a new inspector for working with the attributes
                    // 2. Check to see if a valid field name was chosen for the feature layer
                    // 3. If so, apply the edit

                    //
                    var inspector = new ArcGIS.Desktop.Editing.Attributes.Inspector(true);
                    inspector.Load(featLayer, featSelectionOIDs);
                    if (inspector.HasAttributes && inspector.Count(a => a.FieldName.ToUpper() == attributename.ToUpper()) > 0)
                    {
                        inspector[attributename] = setvalue;
                        var editOp = new EditOperation();
                        editOp.Name = "Edit " + featLayer.Name + ", " + Convert.ToString(featSelectionOIDs.Count) + " records.";
                        editOp.Modify(inspector);
                        editOp.ExecuteAsync();

                        ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Update operation completed.", "Editing with Inspector");
                    }
                    else
                    {
                        ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("The Attribute provided is not valid. " +
                            "\r\n Ensure your attribute name is correct.", "Invalid attribute");
                        // return;
                    }
                }
                catch (Exception exc)
                {
                    // Catch any exception found and display a message box.
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Exception caught while trying to perform update: " + exc.Message);
                    return;
                }
            });
        }
        protected override void OnClick()
        {

            UpdateValues();



        }

来自:https://developers.arcgis.com/labs/pro/edit-attribute-data/

标签:MessageBox,Dialogs,Show,Pro,Desktop,ArcGIS,Framework,二次开发
来源: https://www.cnblogs.com/gisoracle/p/12489339.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有