首页 > 代码库 > 克里金插值及栅格渲染

克里金插值及栅格渲染

1、首先写一个栅格渲染的方法:

步骤:1计算立方图 2创建色带 3渲染

  //渲染
        private void Renders(IRasterLayer layer)
        {
            IRasterClassifyColorRampRenderer classRender = new RasterClassifyColorRampRendererClass();

           
            IRasterRenderer rasterRender = classRender as IRasterRenderer;
            IRaster raster = layer.Raster;
            IRasterBandCollection collection = raster as IRasterBandCollection;
            IRasterBand rasterBand = collection.Item(0);
            if (rasterBand.Histogram == null)
            {
                rasterBand.ComputeStatsAndHist();//计算立方图 
            }

            classRender.ClassCount = 8;
          

            IAlgorithmicColorRamp ramp = new AlgorithmicColorRampClass();
            ramp.FromColor = GetColor(255, 0, 0);
            ramp.ToColor = GetColor(0, 255, 0);
            ramp.Size = 8;
            bool ok=true;
            ramp.CreateRamp(out ok);

            IFillSymbol fillSymbol = new SimpleFillSymbolClass();
            for (int i = 0; i < classRender.ClassCount; i++)
            {
                fillSymbol.Color = ramp.get_Color(i);  //不能用ramp.colors.Next()
                classRender.set_Symbol(i, fillSymbol as ISymbol);
                classRender.set_Label(i, "class" + i.ToString());

            }
            IRasterRenderer render = classRender as IRasterRenderer;
            render.Update();
            layer.Renderer = classRender as IRasterRenderer;
        }

2克里金插值,与IDW插值类似

private void kringToolStripMenuItem_Click(object sender, EventArgs e)
        {
         
            IGeoDataset geodataset = axMapControl1.get_Layer(0) as IGeoDataset;
            object Etn=geodataset.Extent;
            IFeatureLayer layer = axMapControl1.get_Layer(0) as IFeatureLayer;
            IFeatureClassDescriptor descriptor = new FeatureClassDescriptorClass();
            descriptor.Create(layer.FeatureClass, null, "value");

            IRasterRadius radius = new RasterRadiusClass();
            object missing = null;
            radius.SetVariable(12, ref missing);
            //double dSearch=10;
            //object dSearchCount=3;
            //radius.SetFixed(dSearch, ref dSearchCount);

            IInterpolationOp interpolation = new RasterInterpolationOpClass();

            object CellSize=15;
            IRasterAnalysisEnvironment environment = interpolation as IRasterAnalysisEnvironment;
            environment.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref CellSize);
            environment.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref Etn, ref missing);

            IGeoDataset dataset=   interpolation.Krige((IGeoDataset)descriptor, esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisSphericalSemiVariogram, radius, false, ref missing);
            MessageBox.Show("插值成功!");
            IRaster raster = new ESRI.ArcGIS.DataSourcesRaster.Raster();
            raster = dataset as IRaster;
            IRasterLayer rasterlayer = new RasterLayerClass();
            rasterlayer.CreateFromRaster(raster);
            Renders(rasterlayer);
            axMapControl1.AddLayer(rasterlayer);
          
            MessageBox.Show("插值成功!");

 

           
        }


      

克里金插值及栅格渲染