首页 > 代码库 > 关于IDW空间插值

关于IDW空间插值

空间插值一般都会用到IInterPolationOP接口等

首先是通过图层的名称获取图层的方法:

 private ILayer GetLayerByName(string name)
        {
            ILayer layer = null;
            for (int i = 0; i < axmapcontrol.Map.LayerCount; i++)
            {
                if (name == axmapcontrol.Map.Layer[i].Name)
                {
                    layer = axmapcontrol.Map.get_Layer(i);
                    break;
                }

            }
            return layer;
        }

进行插值:

 string layerName = comboBox1.SelectedItem.ToString();
            string fieldName = comboBox2.SelectedItem.ToString();
            object CellSize = textBox1.Text;
            IFeatureLayer layer = GetLayerByName(layerName) as IFeatureLayer;
            IGeoDataset geoLayer=GetLayerByName(layerName) as IGeoDataset;
            object  Env=  geoLayer.Extent;

            IFeatureClassDescriptor descriptor = new FeatureClassDescriptorClass();
            descriptor.Create(layer.FeatureClass, null, fieldName); //处理转换的字段

         
            object ob = null;

            IRasterRadius radius = new RasterRadiusClass();//设置半径
            object maxDistance = null;
            radius.SetVariable(12, ref maxDistance);

            IInterpolationOp interpolation = new RasterInterpolationOpClass();
            IRasterAnalysisEnvironment environment = interpolation as IRasterAnalysisEnvironment;
            environment.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref CellSize);//设置像元大小
            environment.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref Env, ref ob);//设置插值的范围

            IGeoDataset dataset1= interpolation.IDW((IGeoDataset)descriptor, 2, radius, ref maxDistance);//执行插值


            IRaster raster = new ESRI.ArcGIS.DataSourcesRaster.Raster();//添加到图层
            raster = dataset1 as IRaster;
            IRasterLayer rasterLayer = new RasterLayerClass();
            rasterLayer.CreateFromRaster(raster);
            rasterLayer.Name = "IDWraster";
            axmapcontrol.AddLayer(rasterLayer);

            MessageBox.Show("插值成功");
           

 

关于IDW空间插值