arcengine 两个图层叠加获得,获得地区图层中各地区的对应的类型的面积

 
        /// 
        /// 两个图层叠加获得,获得地区图层中各地区的对应的类型的面积
        /// 
        /// 边界
        /// 类型
        /// 名字
        /// 类型字段
        private DataTable getTypeAreaPerRange(string pathArea, string pathType, string areaNameColumn, string typeColumn)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("地名");
            dt.Columns.Add("长度");
            // HashTable hs = new HashTable();

            //分别获取Polyline和Polygon的要素类
            IFeatureLayer pFeatureLayerPolygonArea = Lib.Layer.getShpLayer(pathArea, "polygon1");
            IFeatureLayer pFeatureLayerPolygonType = Lib.Layer.getShpLayer(pathType, "polygon2");
            IFeatureClass pFeatureClassPolygonArea = pFeatureLayerPolygonArea.FeatureClass;
            IFeatureClass pFeatureClassPolygonType = pFeatureLayerPolygonType.FeatureClass;

            IFeatureCursor pPolyCursor = pFeatureClassPolygonArea.Search(null, false);

            IFeature pPolyFeature = pPolyCursor.NextFeature();
            int nameIndex = pPolyFeature.Fields.FindField(areaNameColumn);
            while (pPolyFeature != null)
            {
                Application.DoEvents();

                //IFeature pFeaturePolygon = pFeatureClassPolygon.GetFeature(18);
                IPolygon pPolygon = pPolyFeature.ShapeCopy as IPolygon;
                //获取线要素类的所有要素





                IFeatureCursor pFeatureCursorPolyType = pFeatureClassPolygonType.Search(new QueryFilterClass(), false);
                IFeature pFeaturePolyType = pFeatureCursorPolyType.NextFeature();
                //遍历每一个线要素
                double totalArea = 0;
                while (pFeaturePolyType != null)
                {
                    //求该线与某个面要素相交的几何线段
                    IPolygon pPolyType = pFeaturePolyType.ShapeCopy as IPolygon;
                    ITopologicalOperator pTopologicalOperator = pPolyType as ITopologicalOperator;
                    IGeometry Geo =
                        pTopologicalOperator.Intersect(pPolygon, esriGeometryDimension.esriGeometry2Dimension);
                    IFeatureBuffer FeaBuffer = pFeatureClassPolygonType.CreateFeatureBuffer();
                    FeaBuffer.Shape = Geo;

                    IArea pArea = (IArea)FeaBuffer.Shape;
                    totalArea += pArea.Area;
                    //累加面内线要素几何线段的长度
                    pFeaturePolyType = pFeatureCursorPolyType.NextFeature();
                }
                DataRow dr = dt.NewRow();
                dr[0] = pPolyFeature.get_Value(nameIndex);
                dr[1] = totalArea;
                dt.Rows.Add(dr);
                //   MessageBox.Show(totalLength.ToString());
                pPolyFeature = pPolyCursor.NextFeature();
            }
            dataGridView1.DataSource = dt;

            tabControl1.SelectTab(tabPage2);
            return dt;
        }

你可能感兴趣的:(arcengine 两个图层叠加获得,获得地区图层中各地区的对应的类型的面积)