arcengine实现挖填方Cut Fill分析以及读取栅格值

    arcengine实现挖填方Cut Fill分析以及读取栅格值

       stirng demCutfill="";//分析后的挖填方文件

        private void CutFill()
        {
            try
            {
                Random rand = new Random();
                 string dem = "BTFX" + rand.Next();//不能用中文名称,并且为局部变量,否则分析很可能失败
                Geoprocessor GP = new Geoprocessor();
                ESRI.ArcGIS.SpatialAnalystTools.CutFill cuffill = new ESRI.ArcGIS.SpatialAnalystTools.CutFill();
                cuffill.in_before_surface = “”;//旧的dem
                cuffill.in_after_surface = “”;//新的dem
                cuffill.out_raster =  "D:\\" + dem; ; //对比变化
                GP.ToolExecuted += new EventHandler<ToolExecutedEventArgs>(executedCutfill);
                GP.ExecuteAsync(cuffill);
                 demCutfill= dem;//文件赋值,须放在执行分析后面,否则分析很可能失败
            }
            catch (Exception ex)
            {
                MessageBox.Show("分析失败!\n1.选择的不是有效影像数据;\n2.两个文件格式保持一致;\n"+ex.Message);
            }

        }

      //分析完成

        private void executedCuTfill(object e, ToolExecutedEventArgs ToolExecuted)
        {
            try
            {
                getReadDataset(CommonVariable.tempShpPath, demCullfill);
            }catch(Exception ex){
                MessageBox.Show(ex.Message);
            }
            FrmstatuCuffill.Close();
           

        }

       //读取栅格值

        private void getReadDataset(string path ,string name )
        {
            IRasterDataset rastDataset;
            IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory();
            IWorkspace workspace;
            workspace = workspaceFactory.OpenFromFile(path, 0); //inPath栅格数据存储路径
            if (workspace == null)
            {
                return;
            }
            IRasterWorkspace rastWork = (IRasterWorkspace)workspace;

            rastDataset = rastWork.OpenRasterDataset(name);//inName栅格文件名
            if (rastDataset == null)
            {
                return;
            }
            IRasterProps rasterProps = (IRasterProps)rastDataset.CreateDefaultRaster();
            IGeoDataset pGeodataset = rastDataset as IGeoDataset;
            IRasterBandCollection pRsBandCol = pGeodataset as IRasterBandCollection;
            double area = 0.0;//涉及面积
            double volume = 0.0;//填方方量
            for (int i = 0; i < pRsBandCol.Count; i++)
            {
                IRasterBand pBand = pRsBandCol.Item(0);
                ITable pRTable = pBand.AttributeTable;
                ICursor pCursor = pRTable.Search(null, false);
                //获取像素块中的值
                IRow pRrow = pCursor.NextRow();
                while (pRrow != null)
                {
                  //  for (int t = 0; t < pRrow.Fields.FieldCount; t++)
                   // {
                       // string v = pRrow.get_Value(pRrow.Fields.FindField("AREA")).ToString();
                     
                  //  }
                     area+=Convert.ToDouble( pRrow.get_Value(pRrow.Fields.FindField("AREA")).ToString());
                     volume += Convert.ToDouble(pRrow.get_Value(pRrow.Fields.FindField("VOLUME")).ToString());
                    pRrow = pCursor.NextRow();
                }
            }
           string countVolume = Math.Round(volume,2) + "m³";
            string countArea= Math.Round(area,2) + "㎡";
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大龄牛码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值