_银子

提供更专注、更专心、更专业的服务
  首页  :: 联系 :: 订阅 订阅  :: 管理

Arcgis处理拓扑

Posted on 2012-10-25 08:36  _银子  阅读(249)  评论(0编辑  收藏  举报
  子多边形增加方向,符合拓扑规则:
 
  private void shp要素ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
 
                ILayer pLayer = m_mapControl.get_Layer(0);
                IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
                IFeature tmpFea = pFeatureLayer.FeatureClass.CreateFeature();
                IPolygon pPolygon = new PolygonClass();
                pPolygon = fun() as IPolygon;
      //图形增加方向
                ITopologicalOperator pTopo = pPolygon as ITopologicalOperator;
                pTopo.Simplify();
                if (pPolygon == null) return;
 
                tmpFea.Shape = pPolygon;
                tmpFea.Store();
            }
            catch (Exception err)
            {
            }    
        }
        IGeometry fun()
        {
            //创建一个Ring对象
            ISegmentCollection pSegCollection = new RingClass();
            IPoint pt1 = new PointClass();
            pt1.X = 0;
            pt1.Y = 0;
            IPoint pt2 = new PointClass();
            pt2.X = 1;
            pt2.Y = 0;
            IPoint pt3 = new PointClass();
            pt3.X = 1;
            pt3.Y = 1;

            IPoint pt4 = new PointClass();
            pt4.X = -2;
            pt4.Y = -1;
            IPoint pt5 = new PointClass();
            pt5.X = 2;
            pt5.Y = -1;
            IPoint pt6 = new PointClass();
            pt6.X = 2;
            pt6.Y = 2;
            object o = Type.Missing;

            IPointCollection ptC1 = new RingClass() as IPointCollection;
            ptC1.AddPoint(pt1,ref o ,ref o);
            ptC1.AddPoint(pt2, ref o, ref o);
            ptC1.AddPoint(pt3, ref o, ref o);
            ptC1.AddPoint(pt1, ref o, ref o);
            IPointCollection ptC2 = new RingClass() as IPointCollection;
            ptC2.AddPoint(pt4, ref o, ref o);
            ptC2.AddPoint(pt5, ref o, ref o);
            ptC2.AddPoint(pt6, ref o, ref o);
            ptC2.AddPoint(pt4, ref o, ref o);
            (ptC1 as IRing).Close();
            (ptC2 as IRing).Close();
            IGeometryCollection pGeometryColl = new PolygonClass();
            pGeometryColl.AddGeometry(ptC1 as IRing, ref o, ref o);
            pGeometryColl.AddGeometry(ptC2 as IRing, ref o, ref o);
            return pGeometryColl as IGeometry;
        }