Пример #1
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add ExportToFGDB.OnClick implementation
            IMapControl3        mapcontrol3 = m_hookHelper.Hook as IMapControl3;
            ILayer              pLayer      = (ILayer)mapcontrol3.CustomProperty;
            FolderBrowserDialog fd          = new FolderBrowserDialog();

            if (fd.ShowDialog() == DialogResult.OK)
            {
            }
            {
                IWorkspace    pWorkspace   = Utilities.WorkspaceHelper.GetFGDBWorkspace(fd.SelectedPath);
                IFeatureLayer featureLayer = pLayer as IFeatureLayer;
                ArcGISUtilities.CopyData(featureLayer.FeatureClass, pWorkspace, featureLayer.Name);
            }
        }
Пример #2
0
        private void butOk_Click(object sender, EventArgs e)
        {
            if (this.CheckingInput())
            {
                Application.DoEvents();
                this.comboxlayer.Enabled  = false;
                this.comboxFiled.Enabled  = false;
                this.comboClss1.Enabled   = false;
                this.comboClss2.Enabled   = false;
                this.textBox1.Enabled     = false;
                this.button1.Enabled      = false;
                this.butOk.Enabled        = false;
                this.progressBar1.Visible = true;
                this.progressBar1.Minimum = 0;


                ILayer   layer    = this.MapLayer[this.comboxlayer.SelectedIndex];
                IDataset pDataSet = (layer as IFeatureLayer).FeatureClass as IDataset;
                //string outputDir = System.Environment.CurrentDirectory + "\\Default.gdb";
                IWorkspace pWorkspace = Utilities.WorkspaceHelper.GetShapefileWorkspace(MainForm.outshape);
                //
                IEnumDataset pDataSetsEnum = pWorkspace.get_Datasets(esriDatasetType.esriDTAny);
                IDataset     pDataTM       = pDataSetsEnum.Next();
                while (pDataTM != null)
                {
                    if (pDataTM.Name == "temp")
                    {
                        if (pDataTM.CanDelete())
                        {
                            pDataTM.Delete();
                            break;
                        }
                        else
                        {
                            MessageBox.Show("请检查是否处于打开状态!");
                            return;
                        }
                    }

                    pDataTM = pDataSetsEnum.Next();
                }
                ArcGISUtilities.CopyData((layer as IFeatureLayer).FeatureClass, pWorkspace, "temp");
                IEnumDataset pEnumDS = pWorkspace.get_Datasets(esriDatasetType.esriDTAny);

                IFeatureClass  featureClass = ArcGISUtilities.GetDatasetByName(pEnumDS, "temp") as IFeatureClass;
                IQueryFilter   pQueryFilter = null;
                IFeatureCursor pFCursor     = null;



                int index = featureClass.Fields.FindField(comboxFiled.Text);
                if (index < 0)
                {
                    MessageBox.Show("请检查数据是否含分类码或检查编码文件.", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }

                foreach (ListViewItem lvi in listView1.Items)
                {
                    string code = lvi.Text;
                    if (code.Substring(0, 1) == "0" || code.Substring(0, 1) == "1")
                    {
                        string temp = lvi.Text.Substring(2, 2);
                        //一级类
                        if (temp == "00")
                        {
                            code         = code.Substring(0, 2);
                            pQueryFilter = new QueryFilterClass();
                            //pQueryFilter.WhereClause = "[" + comboxFiled.Text + "]" + " LIKE " + "\'" + code + "**" + "\'";//GeoDatase中
                            pQueryFilter.WhereClause = comboxFiled.Text + " LIKE " + "\'" + code + "__" + "\'";
                            pFCursor = featureClass.Update(pQueryFilter, false);
                            IFeature pFeat = pFCursor.NextFeature();
                            while (pFeat != null)
                            {
                                pFeat.set_Value(index, lvi.Text);
                                pFCursor.UpdateFeature(pFeat);
                                pFeat = pFCursor.NextFeature();
                            }
                        }
                        //二级类
                        else if (temp.Substring(1, 1) == "0")
                        {
                            code                     = code.Substring(0, 3);
                            pQueryFilter             = new QueryFilterClass();
                            pQueryFilter.WhereClause = "[" + comboxFiled.Text + "]" + " LIKE " + "\'" + code + "*" + "\'";
                            pFCursor                 = featureClass.Update(pQueryFilter, false);
                            IFeature pFeat = pFCursor.NextFeature();
                            while (pFeat != null)
                            {
                                pFeat.set_Value(index, lvi.Text);
                                pFCursor.UpdateFeature(pFeat);
                                pFeat = pFCursor.NextFeature();
                            }
                        }
                    }

                    this.progressBar1.Value += 1;
                }

                ////////////////////////////////////////////////////////////////////////////////////////////////////
                Application.DoEvents();
                this.progressBar1.Value = 70;
                IFeatureClass pFeatureClass = null;

                VectorOperation operation = new VectorOperation();

                pFeatureClass = operation.Dissolv(featureClass, comboxFiled.Text, textBox1.Text.Trim(), this.textBox2.Text.Trim()
                                                  , this.progressBar1);

                IFeatureLayer pLayer = new FeatureLayerClass
                {
                    FeatureClass = pFeatureClass,
                    Name         = pFeatureClass.AliasName
                };

                this.m_axMapControl.AddLayer(pLayer);
                this.m_axMapControl.ActiveView.Refresh();
                //释放资源
                if (pFCursor != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pFCursor);
                }
                if (pQueryFilter != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pQueryFilter);
                }
                if (featureClass != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
                }

                MessageBox.Show(pLayer.Name + "处理完成!");
                base.Close();
            }
        }