使用ArcObjects添加点线面

在AE中数据编辑是一个重难点。它包括的东西很多,如地物的添加,地物的修改,地物查询,节点捕捉,地物的符号化等一系列的问题。熟练的使用地物编辑的功能,是开发一个系统必须具备的条件。数据编辑问题解决得好坏直接决定着软件是否操作方便。在这我只是写一些相应的功能函数,至于软件开发中的架构暂不考虑。
1、添加地物
什么是地物,这是 GIS的基本概念,在此只说明一点,地物可以表现在地图上,如房子、铁路、水管等等。我们把房子的总称称为一个地物类,在AE中对应一个地物类(IFeatureClass),一个地物类在地图上表示为一个地物层(IFeatureLayer),单独的一栋房子或一条管道我们称为地物(IFeature),Arcgis中一类地物只能放在一个层,通过图层的叠加组成一幅地图。
熟悉面向对象的人都知道,其实上边的地物类和地物的概念就是类和对象的概念。房子、铁路、水管等是一类地物的抽象,而具体的某一房子就是对象了。大家了解这一点,接下来的开发就容易理解一些了。当然,还有一些其他的概念也必须了解一下:如长事务、短事务、编辑空间等。请大家查找一些相关资料,了解这方面的内容。
我们先开始最基本的编辑功能:添加点线面的操作。它包括输入添加点线面和通过鼠标拖动添加点线面。下边讨论一下添加点线面的基本的实现方法:
一、添加点
我们可以有多种方法添加点,但基本的思路一样,只是有少量的接口有变化。下边是通过IFeatureClass的CreateFeature()函数添加地物。
IFeatureLayer I = MapTest.Map.get_Layer(0) as IFeatureLayer;
            IFeatureClass fc = I.FeatureClass;

            IFeatureClassWrite fcw = fc as IFeatureClassWrite;

            IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit;
            IFeature f;
            IPoint p;

            w.StartEditing(false);
            w.StartEditOperation();
          
            f = fc.CreateFeature();
            p = new PointClass();
            p.PutCoords(93000, 48000);
            f.Shape = p;
            fcw.WriteFeature(f);

            w.StopEditOperation();
            w.StopEditing(true); 
二、添加线
添加线的方法跟添加点一样,不同的只是地物类型不一样而已,我把代码贴出来,大家跟添加点的方式进行对比。
IFeatureLayer I = MapTest.Map.get_Layer(0) as IFeatureLayer;
            IFeatureClass fc = I.FeatureClass;

            IFeatureClassWrite fcw = fc as IFeatureClassWrite;
            IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit;
            IFeature f;
            IPoint p = new PointClass();

            w.StartEditing(false);
            w.StartEditOperation();

            //可选参数设置
            object Missing = Type.Missing;

            f = fc.CreateFeature();
            //定义一个多义线对象
            IPolyline polyLine = new PolylineClass();
            //定义一个点的集合
            IPointCollection ptCollect = polyLine as IPointCollection;
            //定义一系列要添加到多义线上的点对象,并赋初始值
            p.PutCoords(95000, 48000);
            ptCollect.AddPoint(p, ref Missing, ref Missing);
            p.PutCoords(93000, 48000);
            ptCollect.AddPoint(p, ref Missing, ref Missing);
            f.Shape = polyLine;

            fcw.WriteFeature(f);

            w.StopEditOperation();
            w.StopEditing(true);
三、添加面

添加面和添加线基本一致,将IPolyLine换成IPolygon就可以了


            IFeatureLayer feaLayer = MapTest.Map.get_Layer(0) as IFeatureLayer;
            IFeatureClass fc = feaLayer.FeatureClass;

            IFeatureClassWrite fcw = fc as IFeatureClassWrite;
            IWorkspaceEdit workspace = (fc as IDataset).Workspace as IWorkspaceEdit;
            IFeature f;
            IPoint p = new PointClass();

            workspace.StartEditing(false);
            workspace.StartEditOperation();

            //可选参数设置
      object Missing = Type.Missing;

            f = fc.CreateFeature();
            //定义一个多边形对象
      IPolygon polygon = new PolygonClass();
            //定义一个点的集合
      IPointCollection ptCollect = polygon as IPointCollection;
            //定义一系列要添加到多边形上的点对象,并赋初始值
      p.PutCoords(90000, 48000);
            ptCollect.AddPoint(p, ref Missing, ref Missing);
            p.PutCoords(90000, 50000);
            ptCollect.AddPoint(p, ref Missing, ref Missing);
            p.PutCoords(93000, 50000);
            ptCollect.AddPoint(p, ref Missing, ref Missing);

            f.Shape = polygon;
            fcw.WriteFeature(f);

            workspace.StopEditOperation();
            workspace.StopEditing(true);

你可能感兴趣的:(F#)