AE创建Voronoi图[转]

private void CreatVoronoi()
        {
            //判定图层是否存在
            IMap pMap = axMapControl1.Map;
            if (pMap.LayerCount == 0)
            {
                MessageBox.Show("图层不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            int k;
            for (k = 0; k < axMapControl1.LayerCount; k++)
                if (axMapControl1.get_Layer(k).Name == tbrCombo.Items[tbrCombo.SelectedIndex].ToString())
                    break;
            IFeatureLayer pFeatureLayer = (IFeatureLayer)axMapControl1.get_Layer(k);
            //IFeatureLayer pFeatureLayer = (IFeatureLayer)pMap.get_Layer(0);
            IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
            //判断图层的类型是否为点状图层
            if (pFeatureClass.ShapeType != esriGeometryType.esriGeometryPoint)
            {
                MessageBox.Show("图层的要素不是Point类型,请重新选择图层!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
                     
            int featureCount = pFeatureClass.FeatureCount(null);
            //如果点数小于2则构不成三角形,退出程序
            if (featureCount < 3)
            {
                MessageBox.Show("输入的点数小于3个,不能构成三角形!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            MessageBox.Show(featureCount.ToString());
            IGeoDataset pGDS = (IGeoDataset)pFeatureClass;
            IEnvelope pEnv = (IEnvelope)pGDS.Extent;
            pEnv.SpatialReference = pGDS.SpatialReference;

            IFields pFields = pFeatureClass.Fields;
            IField pHeightFiled = pFields.get_Field(pFields.FindField("ELEV"));

            ITinEdit pTinEdit = new TinClass();
            pTinEdit.InitNew(pEnv);

            object Missing = Type.Missing;
            pTinEdit.AddFromFeatureClass(pFeatureClass, null, null , null, esriTinSurfaceType.esriTinMassPoint, ref Missing  );
           
            IWorkspace pWorkspace = OpenWorkspace(InitialPath);
            IFeatureClass pFClass;
            pFClass = CreateFeatureClass(pWorkspace, esriGeometryType.esriGeometryPolygon, "Voronoi", 1);

            ITinNodeCollection pTinNodeCollection = (ITinNodeCollection)pTinEdit;
            MessageBox.Show(pTinNodeCollection.NodeCount.ToString());
            pTinNodeCollection.ConvertToVoronoi;
     Regions(pFClass, null, null, "NodeIndex", "ddd");
            IFeatureLayer pFVLayer = new FeatureLayerClass();
            pFVLayer.FeatureClass = pFClass;
            pFVLayer.Name = pFClass.AliasName;
            ILayer pVLayer = (ILayer)pFVLayer;
            axMapControl1.AddLayer(pFVLayer);
            axTOCControl1.Update();
}

posted @ 2009-03-17 20:51  zhh  阅读(598)  评论(1编辑  收藏  举报