Example #1
0
        public bool AddField(object table, string fieldName, string type)
        {
            try
            {
                ESRI.ArcGIS.Geoprocessor.Geoprocessor    gp       = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                ESRI.ArcGIS.DataManagementTools.AddField addField = new ESRI.ArcGIS.DataManagementTools.AddField();
                addField.in_table          = table;
                addField.field_name        = fieldName;
                addField.field_type        = type;
                addField.field_is_nullable = "NULLABLE";
                addField.field_is_required = "NON_REQUIRED";

                gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle;
                gp.OverwriteOutput = true;
                gp.Execute(addField, null);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Example #2
0
        private bool AddField(ILayer selectedLayer, string fieldName, string type)
        {
            try
            {
                ESRI.ArcGIS.Geoprocessor.Geoprocessor    gp       = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                ESRI.ArcGIS.DataManagementTools.AddField addField = new ESRI.ArcGIS.DataManagementTools.AddField();
                addField.in_table          = AppSingleton.Instance().WorkspacePath + "\\" + type + selectedLayer.Name;
                addField.field_name        = fieldName;
                addField.field_type        = "DOUBLE";
                addField.field_is_nullable = "NULLABLE";
                addField.field_is_required = "NON_REQUIRED";

                gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle;
                gp.OverwriteOutput = true;
                gp.Execute(addField, null);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        private void TransForm(string Inputfile, string Output, string outputPath)
        {
            //构造Geoprocessor
            Geoprocessor gp   = new Geoprocessor();
            string       path = Path.GetDirectoryName(Output);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            try
            {
                ESRI.ArcGIS.DataManagementTools.MakeXYEventLayer step1 = new ESRI.ArcGIS.DataManagementTools.MakeXYEventLayer();
                step1.table      = Inputfile + "\\Sheet1$";//textBox1.Text.ToString() + "\\xy.xls\\Sheet1$";
                step1.in_x_field = txbX.Text.ToString();
                step1.in_y_field = txbY.Text.ToString();
                RunTool(gp, step1, null);
                Console.WriteLine(Inputfile);
                //Console.WriteLine("MakeXYEventLayer:添加点数据");

                ESRI.ArcGIS.DataManagementTools.PointsToLine step2 = new ESRI.ArcGIS.DataManagementTools.PointsToLine();
                step2.Input_Features       = step1.out_layer;
                step2.Output_Feature_Class = outputPath + "\\temp.shp";//@"C:\Users\Yayu.Jiang\Desktop\output\temp.shp";
                RunTool(gp, step2, null);
                //Console.WriteLine("PointsToLine:点转线");

                ESRI.ArcGIS.DataManagementTools.FeatureToPolygon step3 = new ESRI.ArcGIS.DataManagementTools.FeatureToPolygon();
                step3.in_features       = step2.Output_Feature_Class;
                step3.out_feature_class = Output;//@"C:\Users\Yayu.Jiang\Desktop\output\xy.shp";
                RunTool(gp, step3, null);
                //Console.WriteLine("FeatureToPolygon:要素转面");

                ESRI.ArcGIS.DataManagementTools.CalculateField calculateField = new ESRI.ArcGIS.DataManagementTools.CalculateField();
                calculateField.in_table = Output;
                calculateField.field    = "ID";
                //calculateField.expression = "5";
                calculateField.expression      = Path.GetFileNameWithoutExtension(Output);
                calculateField.expression_type = "VB";
                RunTool(gp, calculateField, null);
                //Console.WriteLine("CalculateField:填充ID字段");

                ESRI.ArcGIS.DataManagementTools.AddField addField = new ESRI.ArcGIS.DataManagementTools.AddField();
                addField.in_table     = Output;
                addField.field_name   = "YSBH";
                addField.field_type   = "TEXT";
                addField.field_length = 50;
                RunTool(gp, addField, null);
                //Console.WriteLine("AddField:添加字段YSBH");

                string[] foldName = Inputfile.Split('\\');
                calculateField.in_table        = addField.out_table;
                calculateField.field           = "YSBH";
                calculateField.expression_type = "VB";
                calculateField.expression      = "\"" + foldName[foldName.Length - 2] + "\"";
                //calculateField.expression = "\"aaa\"";
                RunTool(gp, calculateField, null);
                //Console.WriteLine("CalculateField:填充字段YSBH");

                #region 添加字段
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow  dr     = dt.Rows[i];
                    string[] fields = { dr["fields"].ToString(), dr["types"].ToString(), dr["length"].ToString() };
                    addField.field_name = fields[0];
                    addField.field_type = fields[1];
                    if (fields[1] == "TEXT")
                    {
                        addField.field_length = Convert.ToInt32(fields[2]);
                    }
                    RunTool(gp, addField, null);
                    //Console.WriteLine("AddField:添加字段" + dr["fields"].ToString());
                }

                #endregion
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }