private void bindCboxTable(ComboBox comb, int LayerNO) { IMapLayers mapLayers = Program.myMap.Map as IMapLayers; IFeatureLayer pFeatureLayer; ILayer layer; //IList<Info> infoList = new List<Info>(); layer = mapLayers.get_Layer(LayerNO); pFeatureLayer = layer as IFeatureLayer; //ITable table = pFeatureLayer.FeatureClass as ITable; int num = pFeatureLayer.FeatureClass.Fields.FieldCount; List <string> lstName = new List <string>(); for (int j = 0; j < num; j++) { string name = pFeatureLayer.FeatureClass.Fields.get_Field(j).Name; lstName.Add(name); } //Info infoLayer = new Info() { CBId = i.ToString(), CBName = layer.Name }; //infoList.Add(infoLayer); //i++; comb.DataSource = lstName; //comb.ValueMember = "CBId"; //comb.DisplayMember = "CBName"; }
/// <summary> /// combobox控件绑定数据 /// </summary> private void bindCboxLayer(ComboBox comb) { IMapLayers mapLayers = Program.myMap.Map as IMapLayers; ILayer layer; //UID uid = new UIDClass(); IList <Info> infoList = new List <Info>(); //uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}"; // 代表只获取矢量图层 //IEnumLayer layers = mapLayers.get_Layers(uid, true); //layer=mapLayers.get_Layer(); //for (int i = 0; i <= 10;i++ ) int i = 0; while (i < mapLayers.LayerCount) { layer = mapLayers.get_Layer(i); Info infoLayer = new Info() { CBId = i.ToString(), CBName = layer.Name }; infoList.Add(infoLayer); i++; } comb.DataSource = infoList; comb.ValueMember = "CBId"; comb.DisplayMember = "CBName"; //Info info1 = new Info() { CBId = "1", CBName = "张三" }; //Info info2 = new Info() { CBId = "2", CBName = "李四" }; //Info info3 = new Info() { CBId = "3", CBName = "王五" }; //infoList.Add(info1); //infoList.Add(info2); //infoList.Add(info3); //comboBox1.DataSource = infoList; //comboBox1.ValueMember = "Id"; //comboBox1.DisplayMember = "Name"; }
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); } }
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); } }
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); } }
private void btOk_Click(object sender, EventArgs e) { this.rtxtState.AppendText("正在执行,请您耐心等待...\n"); this.rtxtState.ScrollToCaret(); #region 步骤一:接收输入数据的路径 string sInputFile = this.txtInput.Text; if (sInputFile.Equals("")) { MessageBox.Show("请选择输入DEM数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } this.rtxtState.AppendText("读取DEM数据...\n"); this.rtxtState.ScrollToCaret(); string sOutputFile = this.txtOutput.Text; if (sOutputFile.Equals("")) { MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } this.rtxtState.AppendText("读取输出路径...\n"); this.rtxtState.ScrollToCaret(); #endregion //string fileName = "地形地貌.mxd"; //axMapControl1.LoadMxFile(fileName); ////将地图全屏最大化 //axMapControl1.Extent = axMapControl1.FullExtent; IVariantArray parameters = new VarArrayClass(); Geoprocessor GP = new Geoprocessor(); object sev = null; this.rtxtState.AppendText("调用GP工具箱功能...\n"); this.rtxtState.ScrollToCaret(); ESRI.ArcGIS.SpatialAnalystTools.Slope slo = new ESRI.ArcGIS.SpatialAnalystTools.Slope();//计算坡度 slo.in_raster = sInputFile; slo.output_measurement = smeasurement; slo.z_factor = sfactor; string sRoad1 = sOutputFile + sslope; slo.out_raster = sRoad1; this.rtxtState.AppendText("利用DEM数据计算坡度信息...\n"); this.rtxtState.ScrollToCaret(); ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator sCal1 = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator(); ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator sCal2 = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator(); ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator sCal3 = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator(); ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator sCal4 = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator(); //try //{ GP.Execute(slo, null);//坡度计算 this.rtxtState.AppendText("计算坡度完成...\n"); this.rtxtState.ScrollToCaret(); //坡度<=8°&高程<=2500m sOrder1 = "(\"" + sOutputFile + "/slope.tif" + "\"" + "<=8" + ")" + "&" + "(\"" + sInputFile + "\"" + "<=2500" + ")"; sCal1.expression = sOrder1; sCal1.output_raster = sOutputFile + sSlope08; this.rtxtState.AppendText("开始进行建设区分级计算...\n"); this.rtxtState.ScrollToCaret(); GP.Execute(sCal1, null); this.rtxtState.AppendText("计算出“优化建设区”...\n"); this.rtxtState.ScrollToCaret(); //8°<坡度<=15°& 高程<=2500m sOrder2 = "(" + "8<" + "\"" + sOutputFile + "/slope.tif" + "\")" + "&" + "(\"" + sOutputFile + "/slope.tif" + "\"" + "<=15" + ")" + "&" + "(\"" + sInputFile + "\"" + "<=2500" + ")"; sCal2.expression = sOrder2; sCal2.output_raster = sOutputFile + sSlope815; GP.Execute(sCal2, null); this.rtxtState.AppendText("计算出“允许建设区”...\n"); this.rtxtState.ScrollToCaret(); //15°<坡度<=25°&高程<=2500m sOrder3 = "(" + "15<" + "\"" + sOutputFile + "/slope.tif" + "\")" + "&" + "(\"" + sOutputFile + "/slope.tif" + "\"" + "<=25" + ")" + "&" + "(\"" + sInputFile + "\"" + "<=2500" + ")"; sCal3.expression = sOrder3; sCal3.output_raster = sOutputFile + sSlope1525; GP.Execute(sCal3, null); this.rtxtState.AppendText("计算出“有条件建设区”...\n"); this.rtxtState.ScrollToCaret(); //25°<坡度 | 高程<=2500m sOrder4 = "(\"" + sOutputFile + "/slope.tif" + "\"" + ">25" + ")" + "|" + "(\"" + sInputFile + "\"" + ">2500" + ")"; sCal4.expression = sOrder4; sCal4.output_raster = sOutputFile + sSlope25; GP.Execute(sCal4, null); this.rtxtState.AppendText("计算出禁止建设区...\n"); this.rtxtState.ScrollToCaret(); this.rtxtState.AppendText("结果计算完成...\n"); this.rtxtState.ScrollToCaret(); //MessageBox.Show(GP.GetMessages(ref sev)); //修改mxd数据源路径 this.rtxtState.AppendText("开始将结果用地图输出展示,请稍等...\n"); this.rtxtState.ScrollToCaret(); IMapDocument pMapDocument = new MapDocumentClass(); pMapDocument.Open("模板地形地貌.mxd"); //打开本地的“模板地形地貌.mxd”地图文档,用来操作改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(txtOutput.Text, 0); IRasterDataset pRasterDataset1 = rasterWorkspace.OpenRasterDataset("优化建设区.tif"); //打开"优化建设区.tif"为栅格图的文件名 pRasterLayer.CreateFromDataset(pRasterDataset1); //创建 pRasterLayer = pMapLayer.get_Layer(1) as IRasterLayer; pRasterLayer.CreateFromDataset(pRasterDataset1); //更改“允许建设区.tif”数据源路径 IRasterLayer pRasterLayer2 = new RasterLayerClass(); IRasterDataset pRasterDataset2 = rasterWorkspace.OpenRasterDataset("允许建设区.tif"); //打开"允许建设区.tif"为栅格图的文件名 pRasterLayer2.CreateFromDataset(pRasterDataset2); //创建 pRasterLayer2 = pMapLayer.get_Layer(2) as IRasterLayer; pRasterLayer2.CreateFromDataset(pRasterDataset2); //更改"有条件建设区.tif"数据源路径 IRasterLayer pRasterLayer3 = new RasterLayerClass(); IRasterDataset pRasterDataset3 = rasterWorkspace.OpenRasterDataset("有条件建设区.tif"); //打开"有条件建设区.tif"为栅格图的文件名 pRasterLayer3.CreateFromDataset(pRasterDataset3); //创建 pRasterLayer3 = pMapLayer.get_Layer(3) as IRasterLayer; pRasterLayer3.CreateFromDataset(pRasterDataset3); //更改"禁止建设区.tif"数据源路径 IRasterLayer pRasterLayer4 = new RasterLayerClass(); IRasterDataset pRasterDataset4 = rasterWorkspace.OpenRasterDataset("禁止建设区.tif"); //打开"禁止建设区.tif"为栅格图的文件名 pRasterLayer4.CreateFromDataset(pRasterDataset4); //创建 pRasterLayer4 = pMapLayer.get_Layer(4) as IRasterLayer; pRasterLayer4.CreateFromDataset(pRasterDataset4); pMapDocument.Save(true, true);//保存更改完路径后的mxd文件模板地形地貌2 //string fileName = "南湖村.mxd";// @"C:\Users\tangmeng\Desktop\农用地籍数据库\实验四\南湖数据\南湖村.mxd"; //pMap.LoadMxFile(fileName); ////将地图全屏最大化 //pMap.Extent = pMap.FullExtent; string MdbFile = "模板地形地貌.mxd"; _PageLayoutControl.LoadMxFile(MdbFile); //将mxd全屏最大化 _PageLayoutControl.Extent = _PageLayoutControl.FullExtent; // tabControl1.SelectedTab = tabPage1; this.rtxtState.AppendText("地图输出完成...\n"); this.rtxtState.ScrollToCaret(); }