/// <summary> /// 生成等值线 /// </summary> /// <params name="targetworkspace"></params> /// <params name="nameOftargetFeatureClass"></params> /// <params name="sLayerAliasName"></params> private bool CreateContours(IWorkspace targetworkspace, string nameOftargetFeatureClass, string sLayerAliasName, string extent, ref string failInfo) { double douElevation; //设置一个最小值 progressBarControl1.Properties.Minimum = 0; //设置一个最大值 progressBarControl1.Properties.Maximum = 6; //设置步长,即每次增加的数 progressBarControl1.Properties.Step = 1; //设置进度条的样式 progressBarControl1.Properties.ProgressViewStyle = ProgressViewStyle.Solid; progressBarControl1.Position = 0; try { Geoprocessor GP = new Geoprocessor(); if (withIn(m_strDataFilePath) == false) { return(false); } if (TB_Interval.Text == "") { MessageBox.Show("请输入正确的等高距!", "提示!"); return(false); } if (double.TryParse(TB_Interval.Text.Trim(), out douElevation)) { } else { TB_Interval.Text = null; MessageBox.Show("请输入正确的等高距!", "提示!"); return(false); } string featurOut = m_MakeContoursFolder + "\\Cont.shp"; int k = 0; while (File.Exists(featurOut)) { k++; featurOut = m_MakeContoursFolder + "\\Cont" + k.ToString() + ".shp"; } int countCont = Directory.GetFiles(m_MakeContoursFolder, "Cont*").Length; if (countCont > 0) { featurOut = m_MakeContoursFolder + "\\Cont" + countCont.ToString() + ".shp"; } if (DrawContours.ConvertASCIIDescretePoint2FeatureClass(GP, m_strDataFilePath, featurOut) == false) { return(false); } //执行步长 this.progressBarControl1.PerformStep(); string ContourRaster = m_MakeContoursFolder + "\\Spline"; //string ContourRaster = m_MakeContoursFolder + "\\" + nameOftargetFeatureClass + "_Render"; if (extent != "")//右上左下 xmax ymax xmin ymin { GP.SetEnvironmentValue("Extent", extent); } bool suc = false; string sRasterLayerAliasName = sLayerAliasName + "渲染图"; ILayer rsLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, sRasterLayerAliasName); if (rsLayer != null) { DataEditCommon.g_pMap.DeleteLayer(rsLayer); } if (Directory.Exists(ContourRaster)) { try { Directory.Delete(ContourRaster, true); } catch { k = 1; while (Directory.Exists(ContourRaster)) { ContourRaster = m_MakeContoursFolder + "\\Spline" + k.ToString(); k++; } } } switch (CB_InterpolationMethod.Text) { case "样条函数插值法": suc = DrawContours.Interpolate2RasterSpline(GP, featurOut, ContourRaster, CB_SplineType.Text); break; case "自然邻域插值法": suc = DrawContours.Interpolate2RasterNN(GP, featurOut, ContourRaster); break; case "克里格插值法": suc = DrawContours.Interpolate2RasterKriging(GP, featurOut, ContourRaster, CB_semiVariogramProp.Text, CB_searchRadiusProp.Text); break; case "反距离权重插值法": suc = DrawContours.Interpolate2RasterIDW(GP, featurOut, ContourRaster); break; case "趋势面插值法": suc = DrawContours.TrendToRaster(GP, featurOut, ContourRaster); break; } if (suc == false) { return(false); } this.progressBarControl1.PerformStep(); GP = new Geoprocessor(); string R2Contour = m_MakeContoursFolder + "\\Contour.shp"; k = 1; while (File.Exists(R2Contour)) { R2Contour = m_MakeContoursFolder + "\\Contour" + k.ToString() + ".shp"; k++; } int countContour = Directory.GetFiles(m_MakeContoursFolder, "Contour*").Length; if (countContour > 0) { R2Contour = m_MakeContoursFolder + "\\Contour" + countContour.ToString() + ".shp"; } if (DrawContours.SplineRasterToContour(GP, ContourRaster, R2Contour, douElevation) == false) { return(false); } this.progressBarControl1.PerformStep(); string EvEContour = m_MakeContoursFolder + "\\EvEContour.shp"; k = 1; while (File.Exists(EvEContour)) { EvEContour = m_MakeContoursFolder + "\\EvEContour" + k.ToString() + ".shp"; k++; } int countEvEContour = Directory.GetFiles(m_MakeContoursFolder, "EvEContour*").Length; if (countEvEContour > 0) { EvEContour = m_MakeContoursFolder + "\\EvEContour" + countEvEContour.ToString() + ".shp"; } if (DrawContours.FeaturesTo3D(GP, R2Contour, EvEContour) == false) { return(false); } this.progressBarControl1.PerformStep(); //获得等值线Shp文件所在的工作空间 IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory(); IWorkspace sourceworkspace = workspaceFactory.OpenFromFile(m_MakeContoursFolder, 0); //裁切 IPolygon bianjie = GetPolygon(); //导入等值线Shp文件到数据库中 DrawSpecialCommon drawspecial = new DrawSpecialCommon(); string nameOfsourceFeatureClass = EvEContour.Substring(EvEContour.LastIndexOf("\\") + 1); nameOfsourceFeatureClass = nameOfsourceFeatureClass.Substring(0, nameOfsourceFeatureClass.LastIndexOf(".")); bool Import = false; List <ziduan> list = new List <ziduan> { new ziduan("BID", ""), new ziduan("mingcheng", sLayerAliasName), new ziduan("mcid", "0"), new ziduan("date", DateTime.Now.ToString()), new ziduan("type", CB_InterpolationMethod.Text) }; list.Add(new ziduan("BID", "")); list.Add(new ziduan("mingcheng", sLayerAliasName)); list.Add(new ziduan("mcid", "0")); list.Add(new ziduan("date", DateTime.Now.ToString())); list.Add(new ziduan("type", CB_InterpolationMethod.Text)); IFeatureLayer pFeatureLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, EditLayerName) as IFeatureLayer; string WhereClause = "mcid='" + "0" + "'"; DataEditCommon.DeleteFeatureByWhereClause(pFeatureLayer, WhereClause); if (radioBtnKJ.Checked && bianjie != null) { Import = IntersectAll(DataEditCommon.GetFeatureClassByName(sourceworkspace, nameOfsourceFeatureClass), bianjie, list); } else { Import = drawspecial.ShapeImportGDB(sourceworkspace, targetworkspace, nameOfsourceFeatureClass, nameOftargetFeatureClass, list); } this.progressBarControl1.PerformStep(); if (Import == false) { MessageBox.Show(sLayerAliasName + "导入数据库失败!"); DataEditCommon.g_axTocControl.Update(); DataEditCommon.g_pAxMapControl.Refresh(); failInfo = sLayerAliasName; return(false); } //添加相应的渲染图 IRasterLayer newRasterLayer = new RasterLayerClass(); newRasterLayer.CreateFromFilePath(ContourRaster); newRasterLayer = IntersectRaster(newRasterLayer, bianjie); //newRasterLayer.CreateFromDataset(newRasterDs); newRasterLayer.Name = sRasterLayerAliasName; UsingRasterStretchColorRampRender(newRasterLayer); //groupLayer.Add(newRasterLayer as ILayer); int indexPosition = DataEditCommon.g_pAxMapControl.LayerCount;//GroupLayer序号 //判断MapControl中是否存在该图层 ILayer mLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, sRasterLayerAliasName); if (mLayer != null) { DataEditCommon.g_pMyMapCtrl.Map.DeleteLayer(mLayer); indexPosition--; } DataEditCommon.g_pAxMapControl.AddLayer(newRasterLayer as ILayer, indexPosition);//添加到最下面 DataEditCommon.g_pAxMapControl.ActiveView.Extent = newRasterLayer.AreaOfInterest; DataEditCommon.g_axTocControl.Update(); DataEditCommon.g_pAxMapControl.Refresh(); this.progressBarControl1.PerformStep(); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }