public static void exportRasterData(string parth, IRasterLayer rasterLayer, float[,] rasterMat)   //输出栅格数据
        {
            string            directory        = parth.Substring(0, parth.LastIndexOf("\\"));
            string            name             = parth.Substring(parth.LastIndexOf("\\") + 1);
            IWorkspaceFactory workspaceFac     = new RasterWorkspaceFactoryClass();
            IRasterWorkspace2 rasterWorkspace2 = workspaceFac.OpenFromFile(directory, 0) as IRasterWorkspace2;

            IRasterInfo rasterInfo  = (rasterLayer.Raster as IRawBlocks).RasterInfo;
            IPoint      originPoint = new Point();

            originPoint.PutCoords(rasterInfo.Origin.X, rasterInfo.Origin.Y - (rasterLayer.Raster as IRasterProps).Height * (rasterLayer.Raster as IRasterProps).MeanCellSize().Y);
            IRasterProps   rasterProps   = rasterLayer.Raster as IRasterProps;
            IRasterDataset rasterDataSet = rasterWorkspace2.CreateRasterDataset(name, "IMAGINE Image", originPoint, rasterProps.Width, rasterProps.Height,
                                                                                rasterProps.MeanCellSize().X, rasterProps.MeanCellSize().Y, 1, rstPixelType.PT_FLOAT, rasterProps.SpatialReference, true) as IRasterDataset2;

            IRaster2 raster2 = rasterDataSet.CreateDefaultRaster() as IRaster2;

            IPnt pntClass = new Pnt();

            pntClass.X = rasterProps.Width;
            pntClass.Y = rasterProps.Height;
            IRasterCursor rasterCursor   = raster2.CreateCursorEx(pntClass);
            IRasterCursor inRasterCursor = (rasterLayer.Raster as IRaster2).CreateCursorEx(pntClass);

            IRasterEdit rasterEdit = raster2 as IRasterEdit;

            if (rasterEdit.CanEdit())
            {
                IPixelBlock3 pixelBlock3   = rasterCursor.PixelBlock as IPixelBlock3;
                IPixelBlock3 inPixelBlock3 = inRasterCursor.PixelBlock as IPixelBlock3;
                System.Array pixels        = (System.Array)rasterMat;
                pixelBlock3.set_PixelData(0, (System.Array)pixels);
                rasterEdit.Write(rasterCursor.TopLeft, (IPixelBlock)pixelBlock3);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pixelBlock3);
            }
            rasterEdit.Refresh();
            IGeoDataset   inDataset   = rasterLayer.Raster as IGeoDataset;
            IGeoDataset   outDataset  = rasterDataSet as IGeoDataset;
            IExtractionOp op          = new RasterExtractionOpClass();
            var           outDataset1 = op.Raster(outDataset, inDataset);
            var           clipRaster  = (IRaster)outDataset1;
            ISaveAs       pSaveAs     = clipRaster as ISaveAs;

            System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterCursor);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterEdit);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(raster2);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterDataSet);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterWorkspace2);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(workspaceFac);
            if (File.Exists(parth))
            {
                File.Delete(parth);
            }
            workspaceFac = new RasterWorkspaceFactoryClass();
            IDataset outdataset = pSaveAs.SaveAs(name, workspaceFac.OpenFromFile(directory, 0), "IMAGINE Image");

            System.Runtime.InteropServices.Marshal.ReleaseComObject(outdataset);
            return;
        }
Exemple #2
0
        /// <summary>
        /// 栅格操作修改栅格的值
        /// </summary>
        /// <param name="pRasterDataset2"></param>
        public static void ChangeRasterValue(IRasterDataset2 pRasterDataset2)
        {
            //设置读取栅格的大小
            IRaster2 pRaster2  = pRasterDataset2.CreateFullRaster() as IRaster2;
            IPnt     pPntBlock = new PntClass();

            pPntBlock.X = 128;
            pPntBlock.Y = 128;
            IRasterCursor pRasterCursor = pRaster2.CreateCursorEx(pPntBlock);
            IRasterEdit   pRasterEdit   = pRaster2 as IRasterEdit;

            if (pRasterEdit.CanEdit())
            {
                //循环波段,长和宽度
                IRasterBandCollection pBands       = pRasterDataset2 as IRasterBandCollection;
                IPixelBlock3          pPixelblock3 = null;
                int          pBlockwidth           = 0;
                int          pBlockheight          = 0;
                System.Array pixels;
                object       pValue;
                long         pBandCount = pBands.Count;
                //
                IRasterProps pRasterProps = pRaster2 as IRasterProps;
                object       nodata       = pRasterProps.NoDataValue;
                do
                {
                    pPixelblock3 = pRasterCursor.PixelBlock as IPixelBlock3;
                    pBlockwidth  = pPixelblock3.Width;
                    pBlockheight = pPixelblock3.Height;
                    for (int k = 0; k < pBandCount; k++)
                    {
                        pixels = (System.Array)pPixelblock3.get_PixelData(k);
                        for (int i = 0; i < pBlockwidth; i++)
                        {
                            for (int j = 0; j < pBlockheight; j++)
                            {
                                pValue = pixels.GetValue(i, j);
                                int value = Convert.ToInt32(pValue);
                                if (Convert.ToInt32(pValue) != 3)
                                {
                                    pixels.SetValue(Convert.ToByte(0), i, j);
                                }
                            }
                        }
                        pPixelblock3.set_PixelData(k, pixels);
                    }
                    pPntBlock = pRasterCursor.TopLeft;
                    pRasterEdit.Write(pPntBlock, (IPixelBlock)pPixelblock3);
                } while (pRasterCursor.Next());
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pRasterEdit);
            }
        }
        public static IRasterDataset exportRasterData(string parth, IRasterLayer rasterLayer, float[,] rasterMat)
        {
            string directory = parth.Substring(0, parth.LastIndexOf("\\"));
            string name      = parth.Substring(parth.LastIndexOf("\\") + 1);

            IWorkspaceFactory workspaceFac     = new RasterWorkspaceFactoryClass();
            IRasterWorkspace2 rasterWorkspace2 = workspaceFac.OpenFromFile(directory, 0) as IRasterWorkspace2;

            IRasterInfo rasterInfo  = (rasterLayer.Raster as IRawBlocks).RasterInfo;
            IPoint      originPoint = new Point();

            originPoint.PutCoords(rasterInfo.Origin.X, rasterInfo.Origin.Y - (rasterLayer.Raster as IRasterProps).Height * (rasterLayer.Raster as IRasterProps).MeanCellSize().Y);
            IRasterProps   rasterProps   = rasterLayer.Raster as IRasterProps;
            IRasterDataset rasterDataSet = rasterWorkspace2.CreateRasterDataset(name, "IMAGINE Image", originPoint, rasterProps.Width, rasterProps.Height, rasterProps.MeanCellSize().X, rasterProps.MeanCellSize().Y, 1, rstPixelType.PT_FLOAT, rasterProps.SpatialReference, true);
            IRaster2       raster2       = rasterDataSet.CreateDefaultRaster() as IRaster2;
            IPnt           pntClass      = new Pnt();

            pntClass.X = rasterProps.Width;
            pntClass.Y = rasterProps.Height;

            IRasterCursor rasterCursor = raster2.CreateCursorEx(pntClass);
            IRasterEdit   rasterEdit   = raster2 as IRasterEdit;

            if (rasterEdit.CanEdit())
            {
                IRasterBandCollection bands       = rasterDataSet as IRasterBandCollection;
                IPixelBlock3          pixelBlock3 = rasterCursor.PixelBlock as IPixelBlock3;
                System.Array          pixels      = (System.Array)pixelBlock3.get_PixelData(0);
                for (int i = 0; i < rasterProps.Width; i++)
                {
                    for (int j = 0; j < rasterProps.Height; j++)
                    {
                        pixels.SetValue(Convert.ToSingle(rasterMat[j, i]), i, j);
                    }
                }
                pixelBlock3.set_PixelData(0, (System.Array)pixels);
                rasterEdit.Write(rasterCursor.TopLeft, (IPixelBlock)pixelBlock3);
            }
            (raster2 as IRasterProps).NoDataValue = 0f;
            rasterEdit.Refresh();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterEdit);
            return(rasterDataSet);
        }
Exemple #4
0
        public static void ReplacePixel(IRasterDataset2 irasterDataset2_0)
        {
            IRaster2 raster2  = irasterDataset2_0.CreateFullRaster() as IRaster2;
            IPnt     pntClass = new Pnt()
            {
                X = 128,
                Y = 128
            };

            raster2.CreateCursorEx(pntClass);
            IRasterEdit rasterEdit = raster2 as IRasterEdit;

            if (rasterEdit.CanEdit())
            {
                long         count       = (long)(irasterDataset2_0 as IRasterBandCollection).Count;
                IRasterProps rasterProp  = raster2 as IRasterProps;
                object       noDataValue = rasterProp.NoDataValue;
                rasterProp.NoDataValue = 255;
                (rasterProp as ISaveAs).SaveAs("j:\\image1.tif", null, "TIFF");
                Marshal.ReleaseComObject(rasterEdit);
            }
        }
Exemple #5
0
        //IRasterStatistics rasterStatic;
        private void SetRasterSymbol(IRasterLayer rasterLayer)
        {
            //获取选择的序号
            int index = sBC.SelectedIndex;
            ISymbologyStyleClass symbologyStyleClass = axSymbologyControl1.GetStyleClass(esriSymbologyStyleClass.esriStyleClassColorRamps);
            IStyleGalleryItem    mStyleGalleryItem   = symbologyStyleClass.GetItem(index);
            //获取选择的符号
            IColorRamp select = (IColorRamp)mStyleGalleryItem.Item;
            IRasterStretchColorRampRenderer rasterStretchColorRampRenderer = new RasterStretchColorRampRendererClass();
            IRasterRenderer rasterRenderer = rasterStretchColorRampRenderer as IRasterRenderer;

            rasterRenderer.Raster = (rasterLayer).Raster;

            if (checkBox1.Checked == true)
            {
                //修改像元值 线性拉伸
                IRaster2 pRaster2  = rasterLayer.Raster as IRaster2;
                IPnt     pPntBlock = new PntClass();

                pPntBlock.X = 128;
                pPntBlock.Y = 128;

                IRasterCursor pRasterCursor = pRaster2.CreateCursorEx(pPntBlock);

                IRasterEdit pRasterEdit = pRaster2 as IRasterEdit;
                if (pRasterEdit.CanEdit())
                {
                    // IRasterBandCollection pBands = rasterLayer as IRasterBandCollection;
                    IPixelBlock3 pPixelblock3 = null;
                    int          pBlockwidth  = 0;
                    int          pBlockheight = 0;
                    System.Array pixels;
                    IPnt         pPnt = null;
                    object       pValue;
                    // long pBandCount = pBands.Count;

                    //获取Nodata
                    //IRasterProps pRasterPro = pRaster2 as IRasterProps;

                    //object pNodata = pRasterPro.NoDataValue;
                    do
                    {
                        pPixelblock3 = pRasterCursor.PixelBlock as IPixelBlock3;
                        pBlockwidth  = pPixelblock3.Width;
                        pBlockheight = pPixelblock3.Height;

                        //   for (int k = 0; k < pBandCount; k++)

                        //IRasterBandCollection bandCollection;
                        //IRasterLayer irasterLayer = rasterLayer;
                        //IRaster2 raster = rasterLayer.Raster as IRaster2;
                        //IRasterDataset rd = raster.RasterDataset;
                        //bandCollection = rd as IRasterBandCollection;
                        //IEnumRasterBand enumband = bandCollection.Bands;
                        //IRasterBand rasterBand = enumband.Next();
                        //rasterStatic = null;
                        //if (rasterBand != null && rasterBand.Statistics != null)
                        //{
                        //    rasterStatic = rasterBand.Statistics;
                        //}


                        int pixelmax, pixelmin;


                        {
                            pixels   = (System.Array)pPixelblock3.get_PixelData(0);
                            pixelmax = Convert.ToInt32(pixels.GetValue(0, 0));
                            pixelmin = pixelmax;

                            for (int i = 0; i < pBlockwidth; i++)
                            {
                                for (int j = 0; j < pBlockheight; j++)
                                {
                                    pValue = pixels.GetValue(i, j);


                                    {
                                        // pixels.SetValue(Convert.ToByte(Convert.ToInt32(pValue) * strscale), i, j);
                                        if (Convert.ToInt32(pValue) > pixelmax)
                                        {
                                            pixelmax = Convert.ToInt32(pValue);
                                        }
                                        if (Convert.ToInt32(pValue) < pixelmin)
                                        {
                                            pixelmin = Convert.ToInt32(pValue);
                                        }
                                    }
                                }
                            }
                            double strscale = ((double)pixelmax - (double)pixelmin) / 255.0;

                            for (int i = 0; i < pBlockwidth; i++)
                            {
                                for (int j = 0; j < pBlockheight; j++)
                                {
                                    pValue = pixels.GetValue(i, j);


                                    {
                                        pixels.SetValue(Convert.ToByte((Convert.ToInt32(pValue) - pixelmin) / (strscale)), i, j);
                                    }
                                }
                            }


                            pPixelblock3.set_PixelData(0, pixels);
                        }
                        pPnt = pRasterCursor.TopLeft;
                        pRasterEdit.Write(pPnt, (IPixelBlock)pPixelblock3);
                    }while (pRasterCursor.Next());
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pRasterEdit);
                    // MessageBox.Show("done");
                }
            }



            rasterRenderer.Update();
            rasterStretchColorRampRenderer.ColorRamp = select;
            rasterRenderer.Update();
            ((IRasterLayer)rasterLayer).Renderer = rasterRenderer;
        }
Exemple #6
0
        public void ChangeRasterValue(IRasterDataset2 pRasterDatset, double dbScale, double dbOffset)
        {
            try
            {
                IRaster2 pRaster2 = pRasterDatset.CreateFullRaster() as IRaster2;

                IPnt pPntBlock = new PntClass();

                pPntBlock.X = 128;
                pPntBlock.Y = 128;

                IRasterCursor pRasterCursor = pRaster2.CreateCursorEx(pPntBlock);
                IRasterEdit   pRasterEdit   = pRaster2 as IRasterEdit;

                if (pRasterEdit.CanEdit())
                {
                    IRasterBandCollection pBands       = pRasterDatset as IRasterBandCollection;
                    IPixelBlock3          pPixelblock3 = null;
                    int          pBlockwidth           = 0;
                    int          pBlockheight          = 0;
                    System.Array pixels;
                    IPnt         pPnt = null;
                    object       pValue;
                    long         pBandCount = pBands.Count;

                    //获取Nodata
                    IRasterProps pRasterPro = pRaster2 as IRasterProps;
                    object       pNodata    = pRasterPro.NoDataValue;
                    //double dbNoData = Convert.ToDouble(((double[])pNodata)[0]);
                    double dbNoData = getNoDataValue(pNodata);

                    do
                    {
                        pPixelblock3 = pRasterCursor.PixelBlock as IPixelBlock3;
                        pBlockwidth  = pPixelblock3.Width;
                        pBlockheight = pPixelblock3.Height;

                        for (int k = 0; k < pBandCount; k++)
                        {
                            pixels = (System.Array)pPixelblock3.get_PixelData(k);
                            for (int i = 0; i < pBlockwidth; i++)
                            {
                                for (int j = 0; j < pBlockheight; j++)
                                {
                                    pValue = pixels.GetValue(i, j);
                                    double ob = Convert.ToDouble(pValue);
                                    if (ob != dbNoData)
                                    {
                                        ob *= dbScale;  //翻转
                                        ob += dbOffset; //Z方向偏移
                                    }

                                    IRasterProps pRP = pRaster2 as IRasterProps;
                                    if (pRP.PixelType == rstPixelType.PT_CHAR)
                                    {
                                        pixels.SetValue(Convert.ToChar(ob), i, j);
                                    }
                                    else if (pRP.PixelType == rstPixelType.PT_UCHAR)
                                    {
                                        pixels.SetValue(Convert.ToByte(ob), i, j);
                                    }
                                    else if (pRP.PixelType == rstPixelType.PT_FLOAT)
                                    {
                                        pixels.SetValue(Convert.ToSingle(ob), i, j);
                                    }
                                    else if (pRP.PixelType == rstPixelType.PT_DOUBLE)
                                    {
                                        pixels.SetValue(Convert.ToDouble(ob), i, j);
                                    }
                                    else if (pRP.PixelType == rstPixelType.PT_ULONG)
                                    {
                                        pixels.SetValue(Convert.ToInt32(ob), i, j);
                                    }
                                    else
                                    {
                                        ;
                                    }
                                }
                            }
                            pPixelblock3.set_PixelData(k, pixels);

                            System.Array textPixel = null;
                            textPixel = (System.Array)pPixelblock3.get_PixelData(k);
                        }

                        pPnt = pRasterCursor.TopLeft;
                        pRasterEdit.Write(pPnt, (IPixelBlock)pPixelblock3);
                    }while (pRasterCursor.Next());

                    //改变了Z值,重新统计下直方图
                    //IRasterDataset2 prd = pRaster2 as IRasterDataset2;
                    IRasterDatasetEdit3 pRedtit = pRasterDatset as IRasterDatasetEdit3;
                    pRedtit.DeleteStats();//This method is avaliable only on raster datasets in File and ArcSDE geodatabases.
                    pRedtit.ComputeStatisticsHistogram(1, 1, null, true);

                    pRasterEdit.Refresh();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pRasterEdit);
                }
            }
            catch (System.Exception ex)
            {
            }
        }
        public bool SetRegionToNoDataValue()
        {
            try
            {
                if (m_pSrcRaster == null || m_pClipPolygon == null || double.IsNaN(m_dbNoDataValue))
                {
                    return(false);
                }

                IGeoDataset   pSrcGeoDataset      = m_pSrcRaster as IGeoDataset;
                IExtractionOp pRasterExtractionOp = new RasterExtractionOpClass();
                IRasterProps  pSrcRasterProps     = m_pSrcRaster as IRasterProps;
                double        dbCellSize          = (pSrcRasterProps.MeanCellSize().X + pSrcRasterProps.MeanCellSize().Y) / 2;

                //设置范围和分辨率
                IRasterAnalysisEnvironment pRasterAnalysisEnv = pRasterExtractionOp as IRasterAnalysisEnvironment;
                pRasterAnalysisEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, dbCellSize);
                pRasterAnalysisEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, m_pClipPolygon.Envelope, Type.Missing);
                //pRasterAnalysisEnv.OutSpatialReference = (m_pSrcRaster as IRasterProps).SpatialReference;

                //保留区域外的值,区域内的设置为原始栅格的无效值
                IGeoDataset pDstGeoDataset = pRasterExtractionOp.Rectangle(pSrcGeoDataset, m_pClipPolygon.Envelope, true);

                //逐点判断像素是否在区域内,在区域内则改变为设置值,否则不变
                IRelationalOperator pRelationalOp = m_pClipPolygon as IRelationalOperator;
                if (pDstGeoDataset is IRaster)
                {
                    //得到原始栅格的对象,用于修改
                    IRaster2        pSrcRaster2        = m_pSrcRaster as IRaster2;
                    IRasterDataset2 pSrcRasterDataset2 = pSrcRaster2.RasterDataset as IRasterDataset2;
                    IRaster         pTmpRaster         = pSrcRasterDataset2.CreateFullRaster();
                    IRasterEdit     pSrcEdit           = pTmpRaster as IRasterEdit;
                    //得到图层NoDataValue
                    IRasterProps rasterProps = pSrcRaster2 as IRasterProps;
                    double       noData      = ClsGDBDataCommon.getNoDataValue(rasterProps.NoDataValue);

                    //得到输出的栅格
                    IRaster2      pDstRaster2      = pDstGeoDataset as IRaster2;
                    IRasterProps  pDstRasterProps  = pDstRaster2 as IRasterProps;
                    IRasterCursor pDstRasterCursor = pDstRaster2.CreateCursorEx(null);
                    //pDstRasterCursor.Reset();

                    do
                    {
                        //得到当前处理的块
                        IPixelBlock3 pixelBlock3 = pDstRasterCursor.PixelBlock as IPixelBlock3;
                        int          nWidth      = pixelBlock3.Width;
                        int          nHeight     = pixelBlock3.Height;
                        IPnt         ptLeftTop   = pDstRasterCursor.TopLeft;

                        //block值转数组时,NoData转换时有时为NoData,有时为栅格中的最小值
                        System.Array array = pixelBlock3.get_PixelData(0) as System.Array;

                        //逐点判断: 判断像素是否在区域内,在区域内则改变为设置值,否则不变
                        for (int i = 0; i < nWidth; i++)
                        {
                            for (int j = 0; j < nHeight; j++)
                            {
                                double dbX = double.NaN, dbY = double.NaN;

                                //得到当前像素点的地图坐标
                                int nCurrentX = Convert.ToInt32(ptLeftTop.X + i);
                                int nCurrentY = Convert.ToInt32(ptLeftTop.Y + j);
                                pDstRaster2.PixelToMap(nCurrentX, nCurrentY, out dbX, out dbY);
                                IPoint ptInMap = new PointClass();
                                ptInMap.X = dbX;
                                ptInMap.Y = dbY;

                                //判断是否在区域内
                                bool bFlag = pRelationalOp.Contains(ptInMap as IGeometry);
                                if (bFlag) //在当前区域内
                                {
                                    object oValidValue = getValidType(pDstRasterProps, m_dbNoDataValue);
                                    array.SetValue(oValidValue, i, j);
                                }
                                else
                                {
                                    double v = Convert.ToDouble(array.GetValue(i, j));

                                    if (v == 0 || v < -3.4e15 || v > 3.4e15)
                                    //if (v == 0 || Math.Abs(v -noData) <1e18)
                                    {
                                        int col, row;
                                        pSrcRaster2.MapToPixel(dbX, dbY, out col, out row);
                                        //表示getpixelvalue为null表示nodata
                                        object obj = pSrcRaster2.GetPixelValue(0, col, row);
                                        if (obj == null)
                                        {
                                            object oValidValue = getValidType(pDstRasterProps, m_dbNoDataValue);
                                            array.SetValue(oValidValue, i, j);
                                        }
                                        else
                                        {
                                            array.SetValue(obj, i, j);
                                        }
                                    }
                                }
                            }
                        }
                        pixelBlock3.set_PixelData(0, array);

                        //得到当前区域块在原图中的左上角像素坐标, 直接修改原栅格的数据
                        int    nPixelLeftX = -1, nPixelLeftY = -1;
                        double dbMapLeftTopX = double.NaN, dbMapLeftTopY = double.NaN;
                        pDstRaster2.PixelToMap(Convert.ToInt32(ptLeftTop.X), Convert.ToInt32(ptLeftTop.Y), out dbMapLeftTopX, out dbMapLeftTopY); //得到当前块左上角的地理坐标
                        pSrcRaster2.MapToPixel(dbMapLeftTopX, dbMapLeftTopY, out nPixelLeftX, out nPixelLeftY);

                        IPnt ptPixelLeftTop = new PntClass();
                        ptPixelLeftTop.SetCoords(nPixelLeftX, nPixelLeftY);
                        if (pSrcEdit.CanEdit())
                        {
                            pSrcEdit.Write(ptPixelLeftTop, pixelBlock3 as IPixelBlock);
                            //pSrcEdit.Refresh();
                        }
                        else
                        {
                            return(false);
                        }
                    } while (pDstRasterCursor.Next() == true);

                    //更新
                    pSrcEdit.Refresh();
                }
                else
                {
                    return(false);
                }

                return(true);
            }
            catch (System.Exception ex)
            {
                return(false);
            }
        }
Exemple #8
0
        private void btn_2e_Click(object sender, EventArgs e)
        {
            ILayer        pLayer       = new FeatureLayerClass();
            IFeatureClass featureClass = GetFeatureClass(@"D:\a_gis工程设计实践课\china\墓穴地shp\grave.shp");
            IGeoDataset   geo          = featureClass as IGeoDataset;

            object extend = geo.Extent;
            object o      = null;
            IFeatureClassDescriptor feades = new FeatureClassDescriptorClass();

            feades.Create(featureClass, null, "area");
            IRasterRadius rasterrad = new RasterRadiusClass();

            rasterrad.SetVariable(12, ref o);
            object                     dCell     = 0.014800000;//可以根据不同的点图层进行设置
            IInterpolationOp           interpla  = new RasterInterpolationOpClass();
            IRasterAnalysisEnvironment rasanaenv = interpla as IRasterAnalysisEnvironment;

            rasanaenv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref dCell);
            rasanaenv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extend, ref o);
            IGeoDataset  g_GeoDS_Raster  = interpla.IDW((IGeoDataset)feades, 2, rasterrad, ref o);
            IRaster      pOutRsater      = (IRaster)g_GeoDS_Raster;
            IRasterLayer pOutRasterlayer = new RasterLayerClass();

            pOutRasterlayer.CreateFromRaster(pOutRsater);
            pOutRasterlayer.Name = "两个因素都考虑";

            //IRaster raster = pOutRasterlayer.Raster;
            IRaster2 raster2 = (IRaster2)pOutRsater;
            // 指定像素块大小
            IPnt pntBlock = new PntClass();

            pntBlock.X = 1280;
            pntBlock.Y = 1280;
            //创建一个光标以给定像素块大小
            //定义RasterCursor初始化,参数设为null,内部自动设置PixelBlock大小
            //IRasterCursor pRasterCursor = pRaster2.CreateCursorEx(null);
            IRasterCursor rasterCursor = raster2.CreateCursorEx(null);
            //控制像素块级别的编辑操作
            IRasterEdit rasterEdit = raster2 as IRasterEdit;

            if (rasterEdit.CanEdit())
            {
                //得到一段光栅带
                IRasterBandCollection bandCollection = (IRasterBandCollection)pOutRsater;
                System.Array          pixels;
                IPnt   pnt = null;
                object value;
                int    bandCount = bandCollection.Count;
                //创建像素块
                IPixelBlock3 pixelBlock3 = null;
                int          blockWidth  = 0;
                int          blockHeight = 0;
                double       temp        = 0;
                do
                {
                    pixelBlock3 = rasterCursor.PixelBlock as IPixelBlock3;
                    blockWidth  = pixelBlock3.Width;
                    blockHeight = pixelBlock3.Height;
                    for (int k = 0; k < bandCount; k++)
                    {
                        //指定平面的像素的数组
                        pixels = (System.Array)pixelBlock3.get_PixelData(k);

                        for (int i = 0; i < blockWidth; i++)
                        {
                            for (int j = 0; j < blockHeight; j++)
                            {
                                //value = pixels.GetValue(i, j);

                                ////if (Convert.ToInt32(value) == 0)
                                //{
                                //设置像素的颜色值
                                temp = PixelValue1[i, j] + PixelValue2[i, j];
                                pixels.SetValue((int)temp, i, j);
                                //}
                            }
                        }
                        pixelBlock3.set_PixelData(k, pixels);
                    }
                    pnt = rasterCursor.TopLeft;
                    rasterEdit.Write(pnt, (IPixelBlock)pixelBlock3);
                }while (rasterCursor.Next());
                System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterEdit);



                //渲染
                IRasterClassifyColorRampRenderer pRClassRend = new RasterClassifyColorRampRendererClass();
                IRasterRenderer pRRend = pRClassRend as IRasterRenderer;

                IRaster pRaster = pOutRasterlayer.Raster;
                IRasterBandCollection pRBandCol = pRaster as IRasterBandCollection;
                IRasterBand           pRBand    = pRBandCol.Item(0);
                if (pRBand.Histogram == null)
                {
                    pRBand.ComputeStatsAndHist();
                }
                pRRend.Raster          = pRaster;
                pRClassRend.ClassCount = 10;
                pRRend.Update();

                IRgbColor pFromColor = new RgbColorClass();
                pFromColor.Red   = 135;//天蓝色
                pFromColor.Green = 206;
                pFromColor.Blue  = 235;
                IRgbColor pToColor = new RgbColorClass();
                pToColor.Red   = 124;//草坪绿
                pToColor.Green = 252;
                pToColor.Blue  = 0;

                IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRampClass();
                colorRamp.Size      = 10;
                colorRamp.FromColor = pFromColor;
                colorRamp.ToColor   = pToColor;
                bool createColorRamp;
                colorRamp.CreateRamp(out createColorRamp);

                IFillSymbol fillSymbol = new SimpleFillSymbolClass();

                for (int i = 0; i < pRClassRend.ClassCount; i++)
                {
                    fillSymbol.Color = colorRamp.get_Color(i);
                    pRClassRend.set_Symbol(i, fillSymbol as ISymbol);
                    pRClassRend.set_Label(i, pRClassRend.get_Break(i).ToString("0.00"));
                }
                pOutRasterlayer.Renderer = pRRend;
                this.axMapControl1.AddLayer(pOutRasterlayer);
            }
        }