Exemplo n.º 1
0
        private void bt_ok_Click(object sender, EventArgs e)
        {
            //判断输入路径是否正确
            #region
            try
            {
                if (!File.Exists(tb_nppinput.Text))
                {
                    MessageBox.Show("生态系统净初级生产力平均值数据输入路径不正确或文件被占用,请重新输入路径!", "提示", MessageBoxButtons.OK);
                    return;
                }
                if (!File.Exists(tb_preinput.Text))
                {
                    MessageBox.Show("平均年降水量数据输入路径不正确或文件被占用,请重新输入路径!", "提示", MessageBoxButtons.OK);
                    return;
                }
                if (!File.Exists(tb_tminput.Text))
                {
                    MessageBox.Show("平均温度数据输入路径不正确或文件被占用,请重新输入路径!", "提示", MessageBoxButtons.OK);
                    return;
                }
                if (!File.Exists(tb_altinput.Text))
                {
                    MessageBox.Show("海拔参数数据输入路径不正确或文件被占用,请重新输入路径!", "提示", MessageBoxButtons.OK);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("设置路径不合法,请检查!");
                return;
            }
            #endregion
            object sev = null;
            tb_state.Text = "正在处理……";
            ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator rc      = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator();
            ESRI.ArcGIS.SpatialAnalystTools.Float            tofloat = new ESRI.ArcGIS.SpatialAnalystTools.Float();
            Geoprocessor gp = new Geoprocessor();
            gp.OverwriteOutput = true;
            try
            {
                //输入数据类型转换
                #region
                //npp输入数据转化为浮点型
                string floatfilepath_npp = System.IO.Path.GetDirectoryName(tb_biooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) + "_float_npp" + System.IO.Path.GetExtension(tb_biooutput.Text);
                tofloat.in_raster_or_constant = tb_nppinput.Text;
                tofloat.out_raster            = floatfilepath_npp;
                gp.Execute(tofloat, null);

                //pre输入数据转化为浮点型
                string floatfilepath_pre = System.IO.Path.GetDirectoryName(tb_biooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) + "_float_pre" + System.IO.Path.GetExtension(tb_biooutput.Text);
                tofloat.in_raster_or_constant = tb_preinput.Text;
                tofloat.out_raster            = floatfilepath_pre;
                gp.Execute(tofloat, null);

                //tm输入数据转化为浮点型
                string floatfilepath_tm = System.IO.Path.GetDirectoryName(tb_biooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) + "_float_tm" + System.IO.Path.GetExtension(tb_biooutput.Text);
                tofloat.in_raster_or_constant = tb_tminput.Text;
                tofloat.out_raster            = floatfilepath_tm;
                gp.Execute(tofloat, null);

                //alt输入数据转化为浮点型
                string floatfilepath_alt = System.IO.Path.GetDirectoryName(tb_biooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) + "_float_alt" + System.IO.Path.GetExtension(tb_biooutput.Text);
                tofloat.in_raster_or_constant = tb_altinput.Text;
                tofloat.out_raster            = floatfilepath_alt;
                gp.Execute(tofloat, null);
                #endregion


                //输入数据进行归一化处理
                #region
                //npp数据归一化处理
                string npp;
                npp              = System.IO.Path.GetDirectoryName(tb_biooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) + "_npp" + System.IO.Path.GetExtension(tb_biooutput.Text);
                rc.expression    = "(\"" + floatfilepath_npp + "\" - " + GetMinPixelValue(floatfilepath_npp).ToString() + ") / (" + (GetMaxPixelValue(floatfilepath_npp) - GetMinPixelValue(floatfilepath_npp)).ToString() + ")";
                rc.output_raster = npp;
                tb_state.Text    = "正在对生态系统净初级生产力平均值进行归一化……";
                gp.Execute(rc, null);
                tb_state.Text = "生态系统净初级生产力平均值归一化处理完成!";

                //pre数据归一化处理
                string pre;
                pre              = System.IO.Path.GetDirectoryName(tb_biooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) + "_pre" + System.IO.Path.GetExtension(tb_biooutput.Text);
                rc.expression    = "(\"" + floatfilepath_pre + "\" - " + GetMinPixelValue(floatfilepath_pre).ToString() + ") / (" + (GetMaxPixelValue(floatfilepath_pre) - GetMinPixelValue(floatfilepath_pre)).ToString() + ")";
                rc.output_raster = pre;
                tb_state.Text    = "正在对平均年降水量数据进行归一化……";
                gp.Execute(rc, null);
                tb_state.Text = "平均年降水量数据归一化处理完成!";

                //tm数据归一化处理
                string tm;
                tm               = System.IO.Path.GetDirectoryName(tb_biooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) + "_tm" + System.IO.Path.GetExtension(tb_biooutput.Text);
                rc.expression    = "(\"" + floatfilepath_tm + "\" - " + GetMinPixelValue(floatfilepath_tm).ToString() + ") / (" + (GetMaxPixelValue(floatfilepath_tm) - GetMinPixelValue(floatfilepath_tm)).ToString() + ")";
                rc.output_raster = tm;
                tb_state.Text    = "正在对平均温度进行归一化……";
                gp.Execute(rc, null);
                tb_state.Text = "平均温度归一化处理完成!";

                //alt数据归一化处理
                string alt;
                alt              = System.IO.Path.GetDirectoryName(tb_biooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) + "_alt" + System.IO.Path.GetExtension(tb_biooutput.Text);
                rc.expression    = "(\"" + floatfilepath_alt + "\" - " + GetMinPixelValue(floatfilepath_alt).ToString() + ") / (" + (GetMaxPixelValue(floatfilepath_alt) - GetMinPixelValue(floatfilepath_alt)).ToString() + ")";
                rc.output_raster = alt;
                tb_state.Text    = "正在对海拔参数数据进行归一化……";
                gp.Execute(rc, null);
                tb_state.Text = "海拔参数数据归一化处理完成!";
                #endregion


                //计算生物多样性保护服务能力指数
                rc.expression    = "\"" + npp + "\" * \"" + pre + "\" * \"" + tm + "\" * ( 1 - \"" + alt + "\" )";
                rc.output_raster = tb_biooutput.Text;
                tb_state.Text    = "正在计算计算生物多样性保护服务能力指数……";
                gp.Execute(rc, null);
                tb_state.Text = "计算生物多样性保护服务能力指数计算完成!";


                //删除临时文件
                if (tb_state.Text == "计算生物多样性保护服务能力指数计算完成!")
                {
                    string[] files = Directory.GetFiles(System.IO.Path.GetDirectoryName(tb_biooutput.Text), System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) + "*");
                    foreach (string file in files)
                    {
                        if (System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) != System.IO.Path.GetFileNameWithoutExtension(file))
                        {
                            File.Delete(file);
                        }
                    }
                }



                //将结果加载显示
                #region
                string       mxfile       = System.Environment.CurrentDirectory + "\\Data\\EcoRedLine\\生物多样性生态红线划分.mxd";
                IMapDocument pMapDocument = new MapDocumentClass();
                pMapDocument.Open(mxfile); //打开本地的地图文档,用来操作改mxd文件
                IMap              pMap                   = pMapDocument.get_Map(0);
                IMapLayers        pMapLayer              = pMap as IMapLayers;
                IRasterLayer      pRasterLayer           = new RasterLayerClass();
                IWorkspaceFactory rasterWorkspaceFactory = new RasterWorkspaceFactoryClass();
                IRasterWorkspace  rasterWorkspace        = (IRasterWorkspace)rasterWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(tb_biooutput.Text), 0);
                IRasterDataset    pRasterDataset1        = rasterWorkspace.OpenRasterDataset("Biodiversity.tif"); //打开栅格图的文件名
                pRasterLayer.CreateFromDataset(pRasterDataset1);                                                  //创建
                pRasterLayer = pMapLayer.get_Layer(0) as IRasterLayer;
                pRasterLayer.CreateFromDataset(pRasterDataset1);
                pMapDocument.Save(true, true);//保存更改完路径后的mxd文件

                _PageLayoutControl.LoadMxFile(mxfile);
                _PageLayoutControl.Extent = _PageLayoutControl.FullExtent;
                _PageLayoutControl.ZoomToWholePage();


                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(gp.GetMessages(ref sev), "提示", MessageBoxButtons.OK);
            }
        }
Exemplo n.º 2
0
        private void bt_ok_Click(object sender, EventArgs e)
        {
            //判断输入路径是否正确
            #region
            try
            {
                if (!File.Exists(tb_demnput.Text))
                {
                    MessageBox.Show("平均降水量数据输入路径不正确或文件被占用,请重新输入路径!", "提示", MessageBoxButtons.OK);
                    return;
                }
                if (Convert.ToDouble(tb_highinput.Text) < 0)
                {
                    MessageBox.Show("请输入正确的水位高程值!", "提示", MessageBoxButtons.OK);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("设置路径或水位高程值不合法,请检查!");
                return;
            }
            #endregion



            ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator rc = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator();
            Geoprocessor gp = new Geoprocessor();
            gp.OverwriteOutput = true;
            object sev = null;
            try
            {
                tb_state.Text = "正在处理……";
                //判断输入水位数据的单位
                double waterunit = 0;
                if (cb_waterunits.Text == "米(m)")
                {
                    waterunit = 1;
                }
                else
                {
                    waterunit = 0.001;
                }


                //判断输入缓冲距离及缓冲单位
                double bufferunit = 0;
                if (cb_bufferunits.Text == "米(m)")
                {
                    bufferunit = 1;
                }
                else
                {
                    bufferunit = 1000;
                }
                double[] bufferdistance = { Convert.ToDouble(nud_one.Value) * bufferunit, Convert.ToDouble(nud_two.Value) * bufferunit, Convert.ToDouble(nud_three.Value) * bufferunit, Convert.ToDouble(nud_four.Value) * bufferunit };


                //提取高程高于水位的区域
                tb_state.Text = "正在提取未淹没区域……";
                string flood_high = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_high" + System.IO.Path.GetExtension(tb_flooutput.Text);
                rc.output_raster = flood_high;
                rc.expression    = "Con(\"" + tb_demnput.Text + "\" >= (" + tb_highinput.Text + " * " + waterunit.ToString() + "),\"" + tb_demnput.Text + "\")";
                gp.Execute(rc, null);
                tb_state.Text = "未淹没区域提取完成!";


                //水文分析填洼
                tb_state.Text = "正在进行水文分析计算填洼……";
                ESRI.ArcGIS.SpatialAnalystTools.Fill fill = new ESRI.ArcGIS.SpatialAnalystTools.Fill();
                string fill_input, fill_output;
                fill_input              = flood_high;
                fill_output             = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_fill" + System.IO.Path.GetExtension(tb_flooutput.Text);
                fill.in_surface_raster  = fill_input;
                fill.out_surface_raster = fill_output;
                gp.Execute(fill, null);
                tb_state.Text = "水文分析填洼计算完成!";

                //水文分析计算流向
                tb_state.Text = "正在进行水文分析计算流向……";
                ESRI.ArcGIS.SpatialAnalystTools.FlowDirection flowdirection = new ESRI.ArcGIS.SpatialAnalystTools.FlowDirection();
                string flowdirection_input, flowdirection_output;
                flowdirection_input                     = fill_output;
                flowdirection_output                    = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_FlowDir" + System.IO.Path.GetExtension(tb_flooutput.Text);
                flowdirection.in_surface_raster         = flowdirection_input;
                flowdirection.out_flow_direction_raster = flowdirection_output;
                gp.Execute(flowdirection, null);
                tb_state.Text = "水文分析流向计算完成!";



                //水文分析计算流量
                tb_state.Text = "正在进行水文分析计算流量……";
                ESRI.ArcGIS.SpatialAnalystTools.FlowAccumulation flowaccumulation = new ESRI.ArcGIS.SpatialAnalystTools.FlowAccumulation();
                string flowaccumulation_input, flowaccumulation_output;
                flowaccumulation_input  = flowdirection_output;
                flowaccumulation_output = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_FlowAcc" + System.IO.Path.GetExtension(tb_flooutput.Text);
                flowaccumulation.in_flow_direction_raster = flowaccumulation_input;
                flowaccumulation.out_accumulation_raster  = flowaccumulation_output;
                gp.Execute(flowaccumulation, null);
                tb_state.Text = "水文分析流量计算完成!";

                //盆域分析
                tb_state.Text = "正在进行水文分析盆域分析……";
                ESRI.ArcGIS.SpatialAnalystTools.Basin basin = new ESRI.ArcGIS.SpatialAnalystTools.Basin();
                string basin_input, basin_output;
                basin_input  = flowdirection_output;
                basin_output = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_Basin" + System.IO.Path.GetExtension(tb_flooutput.Text);
                basin.in_flow_direction_raster = basin_input;
                basin.out_raster = basin_output;
                gp.Execute(basin, null);
                tb_state.Text = "水文分析盆域分析计算完成!";


                //阈值提取河流
                tb_state.Text = "正在阈值提取河流……";
                string flood_rasterriver = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_river" + System.IO.Path.GetExtension(tb_flooutput.Text);
                rc.expression    = "Con(\"" + flowaccumulation_output + "\" >= 800,1)";
                rc.output_raster = flood_rasterriver;
                gp.Execute(rc, null);
                tb_state.Text = "阈值提取河流计算完成!";

                //水文分析栅格河网矢量化
                tb_state.Text = "正在进行水文分析栅格河网矢量化……";
                ESRI.ArcGIS.SpatialAnalystTools.StreamToFeature streamtofeature = new ESRI.ArcGIS.SpatialAnalystTools.StreamToFeature();
                string streamtofeature_output;
                streamtofeature_output = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_river.shp";
                streamtofeature.in_flow_direction_raster = flowdirection_output;
                streamtofeature.in_stream_raster         = flood_rasterriver;
                streamtofeature.out_polyline_features    = streamtofeature_output;
                gp.Execute(streamtofeature, null);
                tb_state.Text = "水文分析栅格河网矢量化计算完成!";


                //多环缓冲区
                tb_state.Text = "正在计算多环缓冲区……";
                ESRI.ArcGIS.AnalysisTools.MultipleRingBuffer multipleringbuffer = new ESRI.ArcGIS.AnalysisTools.MultipleRingBuffer();
                string multipleringbuffer_output = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_multbuffer.shp";
                multipleringbuffer.Input_Features = streamtofeature_output;
                multipleringbuffer.Distances      = bufferdistance[0].ToString() + ";" + bufferdistance[1].ToString() + ";" + bufferdistance[2].ToString() + ";" + bufferdistance[3].ToString() + ";";
                ;
                multipleringbuffer.Buffer_Unit          = "meters";
                multipleringbuffer.Output_Feature_class = multipleringbuffer_output;
                gp.Execute(multipleringbuffer, null);
                tb_state.Text = "多环缓冲区计算完成!";


                //多环缓冲区矢量转栅格
                tb_state.Text = "正在进行多环缓冲区矢量转栅格……";
                ESRI.ArcGIS.ConversionTools.FeatureToRaster featuretoraster = new ESRI.ArcGIS.ConversionTools.FeatureToRaster();
                string featuretoraster_output = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_multbuffer" + System.IO.Path.GetExtension(tb_flooutput.Text);
                featuretoraster.in_features = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_multbuffer.shp";
                featuretoraster.field       = "distance";
                featuretoraster.out_raster  = featuretoraster_output;
                gp.Execute(featuretoraster, null);
                tb_state.Text = "多环缓冲区矢量转栅格计算完成!";


                //删除临时文件
                if (tb_state.Text == "多环缓冲区矢量转栅格计算完成!")
                {
                    string[] files = Directory.GetFiles(System.IO.Path.GetDirectoryName(tb_flooutput.Text), System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "*");
                    foreach (string file in files)
                    {
                        if (System.IO.Path.GetFileNameWithoutExtension(file) != System.IO.Path.GetFileNameWithoutExtension(basin_output) && System.IO.Path.GetFileNameWithoutExtension(file) != System.IO.Path.GetFileNameWithoutExtension(featuretoraster_output))
                        {
                            File.Delete(file);
                        }
                    }
                }


                //将结果加载显示
                #region
                string       mxfile       = System.Environment.CurrentDirectory + "\\Data\\EcoRedLine\\洪水淹没生态红线划分.mxd";
                IMapDocument pMapDocument = new MapDocumentClass();
                pMapDocument.Open(mxfile); //打开本地的地图文档,用来操作改mxd文件
                IMap              pMap                   = pMapDocument.get_Map(0);
                IMapLayers        pMapLayer              = pMap as IMapLayers;
                IRasterLayer      pRasterLayer           = new RasterLayerClass();
                IWorkspaceFactory rasterWorkspaceFactory = new RasterWorkspaceFactoryClass();
                IRasterWorkspace  rasterWorkspace        = (IRasterWorkspace)rasterWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(tb_flooutput.Text), 0);

                IRasterDataset pRasterDataset1 = rasterWorkspace.OpenRasterDataset("Flood_multbuffer.tif"); //打开栅格图的文件名
                pRasterLayer.CreateFromDataset(pRasterDataset1);                                            //创建
                pRasterLayer = pMapLayer.get_Layer(0) as IRasterLayer;
                pRasterLayer.CreateFromDataset(pRasterDataset1);

                IRasterLayer   pRasterLayer2   = new RasterLayerClass();
                IRasterDataset pRasterDataset2 = rasterWorkspace.OpenRasterDataset("Flood_Basin.tif"); //打开栅格图的文件名
                pRasterLayer2.CreateFromDataset(pRasterDataset2);                                      //创建
                pRasterLayer2 = pMapLayer.get_Layer(1) as IRasterLayer;
                pRasterLayer2.CreateFromDataset(pRasterDataset2);


                pMapDocument.Save(true, true);//保存更改完路径后的mxd文件

                _PageLayoutControl.LoadMxFile(mxfile);
                _PageLayoutControl.Extent = _PageLayoutControl.FullExtent;
                _PageLayoutControl.ZoomToWholePage();


                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(gp.GetMessages(ref sev), "提示", MessageBoxButtons.OK);
            }
        }
Exemplo n.º 3
0
        private void bt_ok_Click(object sender, EventArgs e)
        {
            //判断输入路径是否正确
            #region
            try
            {
                if (!File.Exists(tb_raininput.Text))
                {
                    MessageBox.Show("平均降水量数据输入路径不正确或文件被占用,请重新输入路径!", "提示", MessageBoxButtons.OK);
                    return;
                }
                if (!File.Exists(tb_suninput.Text))
                {
                    MessageBox.Show("平均日照时长数据输入路径不正确或文件被占用,请重新输入路径!", "提示", MessageBoxButtons.OK);
                    return;
                }
                if (!File.Exists(tb_tminput.Text))
                {
                    MessageBox.Show("平均温度数据输入路径不正确或文件被占用,请重新输入路径!", "提示", MessageBoxButtons.OK);
                    return;
                }
                if (!File.Exists(tb_luinput.Text))
                {
                    MessageBox.Show("土地利用类型数据输入路径不正确或文件被占用,请重新输入路径!", "提示", MessageBoxButtons.OK);
                    return;
                }
            }
                     catch (Exception ex)
                
            {
                 
                         MessageBox.Show("设置路径不合法,请检查!");

                return;
            }

            #endregion


            //水源涵养生态红线
            #region
            object sev = null;
            ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator rc = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator();
            Geoprocessor gp = new Geoprocessor();
            gp.OverwriteOutput = true;
            try
            {
                //计算地表净辐射量(地表净辐射量=日照时长/20)
                string r;
                r                = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_r" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                rc.expression    = "(\"" + tb_suninput.Text + "\")" + " / 20";
                rc.output_raster = r;
                tb_state.Text    = "正在计算地表净辐射量……";
                gp.Execute(rc, null);
                tb_state.Text = "地表净辐射量计算完成!";



                //计算多年平均潜在蒸发量
                string pet, pet1, pet2, pet3, pet4, pet5;
                pet1             = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_pet1" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                pet2             = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_pet2" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                pet3             = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_pet3" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                pet4             = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_pet4" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                pet5             = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_pet5" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                pet              = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_pet" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                tb_state.Text    = "正在计算多年平均潜在蒸发量……";
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 1";
                rc.output_raster = pet1;
                gp.Execute(rc, null);
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 2";
                rc.output_raster = pet2;
                gp.Execute(rc, null);
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 3";
                rc.output_raster = pet3;
                gp.Execute(rc, null);
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 4";
                rc.output_raster = pet4;
                gp.Execute(rc, null);
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 5";
                rc.output_raster = pet5;
                gp.Execute(rc, null);
                rc.expression    = "(\"" + pet1 + "\"* 336.30)" + " + (\"" + pet2 + "\"* 314.70)" + " + (\"" + pet3 + "\"* 384.58)" + " + (\"" + pet4 + "\"* 182.81)" + " + (\"" + pet5 + "\"* 219.87)";
                rc.output_raster = pet;
                gp.Execute(rc, null);
                tb_state.Text = "多年平均潜在蒸发量计算完成!";


                //计算下垫面(土地覆盖)影响系数
                string w, w1, w2, w3, w4, w5;
                w1               = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_w1" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                w2               = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_w2" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                w3               = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_w3" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                w4               = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_w4" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                w5               = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_w5" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                w                = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_w" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                tb_state.Text    = "正在计算下垫面(土地覆盖)影响系数……";
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 1";
                rc.output_raster = w1;
                gp.Execute(rc, null);
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 2";
                rc.output_raster = w2;
                gp.Execute(rc, null);
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 3";
                rc.output_raster = w3;
                gp.Execute(rc, null);
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 4";
                rc.output_raster = w4;
                gp.Execute(rc, null);
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 5";
                rc.output_raster = w5;
                gp.Execute(rc, null);
                rc.expression    = "(\"" + pet1 + "\"* 0.5)" + " + (\"" + pet2 + "\"* 0.1)" + " + (\"" + pet3 + "\"* 1.5)" + " + (\"" + pet4 + "\"* 0.1)" + " + (\"" + pet5 + "\"* 0.5)";
                rc.output_raster = w;
                gp.Execute(rc, null);
                tb_state.Text = "下垫面(土地覆盖)影响系数计算完成!";



                //计算蒸散量(蒸散量=0.489+0.289*表净辐射量+0.023*平均温度)
                string et, et1, et2, et2_t;
                et1              = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_et1" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                et2              = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_et2" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                et2_t            = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_et2_t" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                et               = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_et" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                tb_state.Text    = "正在计算蒸散量……";
                rc.expression    = "\"" + tb_raininput.Text + "\" + " + "\"" + w + "\" *  \"" + pet + "\"";
                rc.output_raster = et1;
                gp.Execute(rc, null);
                rc.expression    = " 1 + " + "(\"" + w + "\" *  \"" + pet + "\" / (\"" + tb_raininput.Text + "\") + \"" + tb_raininput.Text + "\" / \"" + pet + "\")";
                rc.output_raster = et2_t;
                gp.Execute(rc, null);
                rc.expression    = "Con(\"" + et2_t + "\"" + " != 0 ,\"" + et2_t + "\")";
                rc.output_raster = et2;
                gp.Execute(rc, null);
                rc.expression    = "\"" + et1 + "\" / \"" + et2 + "\"";
                rc.output_raster = et;
                gp.Execute(rc, null);
                tb_state.Text = "蒸散量计算完成!";


                //计算水源涵养量(水源涵养量=多年平均降水量-蒸散量)
                rc.expression    = "\"" + tb_raininput.Text + "\" - \"" + et + "\"";
                rc.output_raster = tb_wcoutput.Text;
                tb_state.Text    = "正在计算水源涵养量……";
                gp.Execute(rc, null);
                tb_state.Text = "水源涵养量计算完成!";


                //删除临时文件
                if (tb_state.Text == "水源涵养量计算完成!")
                {
                    string[] files = Directory.GetFiles(System.IO.Path.GetDirectoryName(tb_wcoutput.Text), System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "*");
                    foreach (string file in files)
                    {
                        if (System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) != System.IO.Path.GetFileNameWithoutExtension(file))
                        {
                            File.Delete(file);
                        }
                    }
                }

                #endregion

                //将结果加载显示
                #region
                string       mxfile       = System.Environment.CurrentDirectory + "\\Data\\EcoRedLine\\水源涵养生态红线划分.mxd";
                IMapDocument pMapDocument = new MapDocumentClass();
                pMapDocument.Open(mxfile); //打开本地的地图文档,用来操作改mxd文件
                IMap              pMap                   = pMapDocument.get_Map(0);
                IMapLayers        pMapLayer              = pMap as IMapLayers;
                IRasterLayer      pRasterLayer           = new RasterLayerClass();
                IWorkspaceFactory rasterWorkspaceFactory = new RasterWorkspaceFactoryClass();
                IRasterWorkspace  rasterWorkspace        = (IRasterWorkspace)rasterWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(tb_wcoutput.Text), 0);
                IRasterDataset    pRasterDataset1        = rasterWorkspace.OpenRasterDataset("waterConervations.tif"); //打开栅格图的文件名
                pRasterLayer.CreateFromDataset(pRasterDataset1);                                                       //创建
                pRasterLayer = pMapLayer.get_Layer(0) as IRasterLayer;
                pRasterLayer.CreateFromDataset(pRasterDataset1);
                pMapDocument.Save(true, true);//保存更改完路径后的mxd文件

                _PageLayoutControl.LoadMxFile(mxfile);
                _PageLayoutControl.Extent = _PageLayoutControl.FullExtent;
                _PageLayoutControl.ZoomToWholePage();


                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(gp.GetMessages(ref sev), "提示", MessageBoxButtons.OK);
            }
        }