[转]c# 栅格运算 获得一副DEM地图某个高度以下的范围,并显示
private void GetRasterValue() { IRaster pRaster = pRasLyr.Raster; //获取已知栅格图层pRasLyr的栅格对象 IGeoDataset tempGeodata = pRaster as IGeoDataset; IMapAlgebraOp rsalgebra = new RasterMapAlgebraOpClass(); //设置栅格运算空间 IRasterAnalysisEnvironment rasAnaEnv = (IRasterAnalysisEnvironment)rsalgebra; IWorkspaceFactory wsf = new RasterWorkspaceFactoryClass(); IWorkspace ws = wsf.OpenFromFile("F:\\beifen\\jg", 0); rasAnaEnv.OutWorkspace = ws; rsalgebra.BindRaster(tempGeodata, "tempRaster"); //进行栅格运算,height 为已知的整型数据,用来确定高度 string Opstr = "[tempRaster] < " + height.ToString(); IGeoDataset outGeoDataset = rsalgebra.Execute(Opstr); IRasterLayer pCreatRslyr = new RasterLayerClass(); pCreatRslyr.CreateFromRaster((IRaster)outGeoDataset); RasterRender(ref pCreatRslyr); //对生成的栅格图层进行渲染,是满足要求的按一个颜色显示,不满足要求的栅格不显示 m_map.AddLayer(pCreatRslyr); } // //栅格图的渲染 // public void RasterRender(ref IRasterLayer pRasterLayer) { int NumOfClass = 2; IRaster pRaster; pRaster = pRasterLayer.Raster; //Create classfy renderer and QI RasterRenderer interface IRasterClassifyColorRampRenderer pClassRen = new RasterClassifyColorRampRendererClass(); IRasterRenderer pRasRen = pClassRen as IRasterRenderer; pRasRen.Raster = pRaster; //字串5 //Set raster for the render and update pClassRen.ClassCount = NumOfClass; pRasRen.Update(); // Create a color ramp to use IAlgorithmicColorRamp pRamp = new AlgorithmicColorRamp(); pRamp.Size = NumOfClass; IRgbColor pFColor = new RgbColorClass(); IRgbColor pTColor = new RgbColorClass(); pFColor.NullColor = true; pTColor.RGB = 100; pRamp.FromColor = pFColor; pRamp.ToColor = pTColor; bool ok = true; pRamp.CreateRamp(out ok); // Create symbol for the classes 字串2 IFillSymbol pFSymbol = new SimpleFillSymbolClass(); //Update the renderer and plug into layer pFSymbol.Color = pFColor; ISymbol pSmbol1 = pFSymbol as ISymbol; pClassRen.set_Symbol(0, pSmbol1); pFSymbol.Color = pTColor; ISymbol pSmbol2 = pFSymbol as ISymbol; pClassRen.set_Symbol(1, pSmbol2); pRasRen.Update(); pRasterLayer.Renderer = pClassRen as IRasterRenderer; }