private void button2_Click(object sender, EventArgs e) { //通过IDW插值生成栅格图层 #region label2.Text = "正在进行IDW插值"; IFeatureLayer pFeatureLayer_point = axMapControl1.Map.Layer[0] as IFeatureLayer;//获取点图层 IRasterRadius pRadius = new RasterRadiusClass(); object missing = Type.Missing; pRadius.SetVariable(12, ref missing); IFeatureClassDescriptor pFCDescriptor = new FeatureClassDescriptorClass(); pFCDescriptor.Create(pFeatureLayer_point.FeatureClass, null, "高程"); object cellSizeProvider = 185.244192; IInterpolationOp pInterpolationOp = new RasterInterpolationOpClass(); IRasterAnalysisEnvironment pEnv = pInterpolationOp as IRasterAnalysisEnvironment; pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeProvider); IRaster pOutRaster; try { pOutRaster = pInterpolationOp.IDW(pFCDescriptor as IGeoDataset, 2, pRadius, ref missing) as IRaster; } catch { pOutRaster = pInterpolationOp.IDW(pFCDescriptor as IGeoDataset, 2, pRadius, ref missing) as IRaster; } //Add output into ArcMap as a raster layer RasterLayer pOutRasLayer = new RasterLayerClass(); pOutRasLayer.CreateFromRaster(pOutRaster); pOutRasLayer.Name = "栅格"; axMapControl1.Map.AddLayer(pOutRasLayer); #endregion //提取等值线 #region label2.Text = "正在生成等值线..."; IGeoDataset pGeoDataSet = pOutRaster as IGeoDataset; IWorkspaceFactory pWorkspaceFactory1 = new ShapefileWorkspaceFactory(); string file_path = System.IO.Path.GetDirectoryName(database_path); IWorkspace pShpWorkspace = pWorkspaceFactory1.OpenFromFile(file_path, 0); ISurfaceOp2 pSurfaceOp2 = new RasterSurfaceOpClass(); IRasterAnalysisEnvironment pRasterAnalysisEnvironment = pSurfaceOp2 as IRasterAnalysisEnvironment; pRasterAnalysisEnvironment.Reset(); pRasterAnalysisEnvironment.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeProvider); pRasterAnalysisEnvironment.OutWorkspace = pShpWorkspace; double dInterval = 0.8; //间距 IGeoDataset pOutputDataSet = pSurfaceOp2.Contour(pGeoDataSet, dInterval, ref missing, ref missing); IFeatureClass pFeatureClass1 = pOutputDataSet as IFeatureClass; IFeatureLayer pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = pFeatureClass1; IGeoFeatureLayer pGeoFeatureLayer = pFeatureLayer as IGeoFeatureLayer; pGeoFeatureLayer.DisplayAnnotation = true; pGeoFeatureLayer.DisplayField = "Contour"; pGeoFeatureLayer.Name = "高程等值线"; axMapControl1.Map.AddLayer(pGeoFeatureLayer); label2.Text = "完毕"; #endregion }