private void getRasterBandItem(DevComponents.AdvTree.Node parentNode, string dataType) { //获取当前的栅格文件 FileInfo file = (FileInfo)parentNode.Tag; string dataPath = file.FullName; IRasterDataset pRasterDataset; pRasterDataset = GetRasterDataset(file.FullName, dataType); IRasterLayer pRasterLayer = new RasterLayerClass(); pRasterLayer.CreateFromDataset(pRasterDataset); IRaster pRaster = pRasterLayer.Raster; IRasterBandCollection pRasterBandCol = (IRasterBandCollection)pRaster; IRasterBand pRasterBand = null; for (int i = 0; i < pRasterBandCol.Count; i++) { pRasterBand = pRasterBandCol.Item(i); ListViewItem item = new ListViewItem(); item.Tag = pRasterBand; item.Name = pRasterBand.Bandname; item.Text = pRasterBand.Bandname; item.ImageIndex = 14; lvwData.Items.Add(item); } }
//图层Plus计算后的包含关系数值判断 public static bool containCorrRel(IGeoDataset pGeodataset, int chkVal1, int chkVal2) { bool containRel = true; //利用栅格图层的属性表实验 IRaster pRaster = pGeodataset as IRaster; IRasterBandCollection pRasterBandCollection = pRaster as IRasterBandCollection; IRasterBand pRasterBand = pRasterBandCollection.Item(0); ITable pTabel = pRasterBand.AttributeTable; IQueryFilter pQueryfilter = new QueryFilterClass(); pQueryfilter.WhereClause = ""; ICursor pCursor = pTabel.Search(pQueryfilter, false); IRow pRow = pCursor.NextRow(); while (pRow != null) { long type = Convert.ToInt64(pRow.get_Value(pTabel.Fields.FindField("Value"))); if (type != chkVal1 && type != chkVal2) { containRel = false; break; } pRow = pCursor.NextRow(); } return(containRel); }
/// <summary> /// 获取栅格波段中的属性表 /// </summary> /// <param name="raster"></param> /// <returns></returns> private static ITable GetRasterBandAttributeTable(IRaster raster) { IRasterBandCollection rasterBands = (IRasterBandCollection)raster; IRasterBand rasterBand = rasterBands.Item(0); return(rasterBand.AttributeTable); }
public void Write(float?[,] rasterValue, string format) { FileHelper.DeleteFile(_workSpace, _fileName, ".tif", ".tfw", ".tif.aux"); IRasterWorkspace2 rasterWs = OpenRasterWorkspace(); if (rasterWs == null) { throw new NullReferenceException("栅格文件打开失败"); } IRasterDataset rasterDataset = rasterWs.CreateRasterDataset(_fileName + ".tif", format, RasterInfo.OriginPoint, RasterInfo.Width, RasterInfo.Height, RasterInfo.XCellSize, RasterInfo.YCellSize, 1, rstPixelType.PT_FLOAT, RasterInfo.SpatialReference, true); IRasterBandCollection rasterBands = (IRasterBandCollection)rasterDataset; var rasterBand = rasterBands.Item(0); var rasterProps = (IRasterProps)rasterBand; //Set NoData if necessary. For a multiband image, NoData value needs to be set for each band. rasterProps.NoDataValue = -1; //Create a raster from the dataset. IRaster raster = rasterDataset.CreateDefaultRaster(); //Create a pixel block. IPnt blocksize = new PntClass(); blocksize.SetCoords(RasterInfo.Width, RasterInfo.Height); IPixelBlock3 pixelblock = raster.CreatePixelBlock(blocksize) as IPixelBlock3; //Populate some pixel values to the pixel block. var pixels = (Array)pixelblock.get_PixelData(0); for (int i = 0; i < RasterInfo.Width; i++) { for (int j = 0; j < RasterInfo.Height; j++) { if (rasterValue[i, j].HasValue) { pixels.SetValue((float)rasterValue[i, j], i, j); } else { pixels.SetValue(-1, i, j); } } } pixelblock.set_PixelData(0, pixels); //Define the location that the upper left corner of the pixel block is to write. IPnt upperLeft = new PntClass(); upperLeft.SetCoords(0, 0); //Write the pixel block. IRasterEdit rasterEdit = (IRasterEdit)raster; rasterEdit.Write(upperLeft, (IPixelBlock)pixelblock); //Release rasterEdit explicitly. Marshal.ReleaseComObject(rasterEdit); }
private void SetMeanCellSize() { if (chkSocCellSize.Checked) { IRasterBandCollection rasterBands = m_pRaster.RasterDataset as IRasterBandCollection; if (rasterBands.Count < 1) { return; } IRasterProps props = rasterBands.Item(0) as IRasterProps; //更改分辨率首先要修改图层范围 if (SetLayerExtent(props.MeanCellSize().X, props.MeanCellSize().Y)) { txtCellSizeX.Text = props.MeanCellSize().X.ToString(); txtCellSizeY.Text = props.MeanCellSize().Y.ToString(); } } else { if (SetLayerExtent(m_pRasterProps.MeanCellSize().X, m_pRasterProps.MeanCellSize().Y)) { txtCellSizeX.Text = m_pRasterProps.MeanCellSize().X.ToString(); txtCellSizeY.Text = m_pRasterProps.MeanCellSize().Y.ToString(); } } }
/// <summary> /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels. /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling. /// The log raster is the natural log of the raster. /// </summary> /// <param name="pTlc">Point to start the reading from in the Raster</param> /// <param name="pRaster">Reference Raster for the PixelBlock</param> /// <param name="pPixelBlock">PixelBlock to be filled in</param> public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock) { try { // Call Read method of the Raster Function Helper object. myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock); int pBHeight = pPixelBlock.Height; int pBWidth = pPixelBlock.Width; IPnt pbSize = new PntClass(); pbSize.SetCoords(pBWidth, pBHeight); //IPixelBlock3 inVlsPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize); //myFunctionHelperCoef.Read(pTlc,null,myFunctionHelperCoef.Raster, (IPixelBlock)inVlsPb); IPixelBlock3 outPixelBlock = (IPixelBlock3)pPixelBlock; System.Array outArr = (System.Array)outPixelBlock.get_PixelData(0); System.Array[] inArr = new System.Array[inrs.RasterInfo.BandCount]; IRasterBandCollection rsBc = (IRasterBandCollection)inrs; for (int b = 0; b < inrs.RasterInfo.BandCount; b++) { IRasterBand rsB = rsBc.Item(b); IRawPixels rPix = (IRawPixels)rsB; IPixelBlock pb = rPix.CreatePixelBlock(pbSize); rPix.Read(pTlc, pb); inArr[b] = (System.Array)pb.get_SafeArray(b); } updateOutArr(outPixelBlock, inArr, outArr); outPixelBlock.set_PixelData(0, outArr); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
private void ConvertRasterToRsDataset(String sPath, ref IRaster pRaster, String sOutName) { try { IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass(); if (pWSF.IsWorkspace(sPath) == false) { return; } IWorkspace pRWS = pWSF.OpenFromFile(sPath, 0); if (System.IO.File.Exists(sPath + "\\" + sOutName + ".img") == true) { System.IO.File.Delete(sPath + "\\" + sOutName + ".img"); } IRasterBandCollection pRasBandCol = (IRasterBandCollection)pRaster; IDataset pDS = pRasBandCol.SaveAs(sOutName + ".img", pRWS, "IMAGINE Image"); ITemporaryDataset pRsGeo = (ITemporaryDataset)pDS; if (pRsGeo.IsTemporary()) { pRsGeo.MakePermanent(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void RGBCompositeRender(ILayer pLayerR, int bandred, int bandgreen, int bandblue) { // Get raster input from layer IRasterLayer rasterLayer = (IRasterLayer)pLayerR; IRaster raster = rasterLayer.Raster; IRasterBandCollection bandCol = (IRasterBandCollection)raster; if (bandCol.Count < 3) { return; } // Create UniqueValue renderer and QI RasterRenderer IRasterRGBRenderer2 rasterRGBRen = new RasterRGBRenderer() as IRasterRGBRenderer2; IRasterRenderer rasterRen = (IRasterRenderer)rasterRGBRen; // Connect the renderer and the raster rasterRen.Raster = raster; rasterRen.Update(); rasterRGBRen.RedBandIndex = bandred; rasterRGBRen.GreenBandIndex = bandgreen; rasterRGBRen.BlueBandIndex = bandblue; //Update render and refresh layer rasterRen.Update(); rasterLayer.Renderer = (IRasterRenderer)rasterRGBRen; }
private void btnChangeRGBRenderer_Click(object sender, EventArgs e) { //Only effective to Raster Layer IMap map = axMapControl1.ActiveView.FocusMap; ILayer aLayer = map.get_Layer(0); //IRasterLayer rLayer = map.get_Layer(3) as IRasterLayer; //IRasterLayer rLayer = (IRasterLayer)aLayer; IRasterLayer rLayer = aLayer as IRasterLayer; IRaster raster = rLayer.Raster; IRasterBandCollection bandCol = raster as IRasterBandCollection; if (bandCol.Count < 3) { //not meet the requirements return; } IRasterRGBRenderer rgbRen = new RasterRGBRenderer(); IRasterRenderer rasRen = rgbRen as IRasterRenderer; rasRen.Raster = raster; rasRen.Update(); //change band ro renderer rgbRen.RedBandIndex = 2; rgbRen.GreenBandIndex = 1; rgbRen.BlueBandIndex = 0; //updtae renderer and refresh layer rLayer.Renderer = rgbRen as IRasterRenderer; axMapControl1.ActiveView.Refresh(); axTOCControl1.Update(); }
//分级渲染函数 private void RasterClassifyRender(IRasterLayer pRasterLayer) { try { IColorRamp pColorRamp = (IColorRamp)EnumStyleItem[comboBoxColor.SelectedIndex]; IRasterClassifyColorRampRenderer pRClassRend = new RasterClassifyColorRampRenderer() as IRasterClassifyColorRampRenderer; IRasterRenderer pRRend = pRClassRend as IRasterRenderer; IRaster pRaster = pRasterLayer.Raster; IRasterBandCollection pRBandCol = pRaster as IRasterBandCollection; IRasterBand pRBand = pRBandCol.Item(0); if (pRBand.Histogram == null) { pRBand.ComputeStatsAndHist(); } pRRend.Raster = pRaster; pRRend.Update(); IRgbColor pFromColor = new RgbColor() as IRgbColor; pFromColor.Red = 255; pFromColor.Green = 0; pFromColor.Blue = 0; IRgbColor pToColor = new RgbColor() as IRgbColor; pToColor.Red = 0; pToColor.Green = 0; pToColor.Blue = 255; IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRamp() as IAlgorithmicColorRamp; //colorRamp = pColorRamp as IAlgorithmicColorRamp;/////// colorRamp.Size = comboBoxClassValue.SelectedIndex + 1; //colorRamp.FromColor = pFromColor; //colorRamp.ToColor = pToColor; int nClass = comboBoxClassValue.SelectedIndex + 1; colorRamp.FromColor = pColorRamp.get_Color(0); colorRamp.ToColor = pColorRamp.get_Color(nClass - 1); bool createColorRamp; colorRamp.CreateRamp(out createColorRamp); IFillSymbol fillSymbol = new SimpleFillSymbol() as IFillSymbol; for (int i = 0; i < nClass; 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")); } pRasterLayer.Renderer = pRRend; m_mapControl.Refresh(); } catch (Exception e) { MessageBox.Show("创建失败!"); } }
private IRasterDataset OpenRasterDataset(string inFile, int bandIndex) { IRasterDataset rasterDataset = null; IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactory();; IRasterWorkspace rasterWorkspace; int Index = inFile.LastIndexOf("\\"); string filePath = inFile.Substring(0, Index); string fileName = inFile.Substring(Index + 1); try { if (!File.Exists(inFile)) { throw new Exception("文件不存在," + inFile); } rasterWorkspace = (IRasterWorkspace)pWorkspaceFactory.OpenFromFile(filePath, 0); rasterDataset = rasterWorkspace.OpenRasterDataset(fileName); if (bandIndex > 0) { IRasterBandCollection pRasterBandCollection = rasterDataset as IRasterBandCollection; IRasterBand pBand = pRasterBandCollection.Item(bandIndex - 1); rasterDataset = pBand as IRasterDataset; } } catch (Exception ex) { //Console.WriteLine("Failed in Opening RasterDataset. " + ex.InnerException.ToString()); Log.WriteLog(typeof(RasterMapAlgebraOp), ex); throw ex; } return(rasterDataset); }
/// <summary> /// 计算信息熵阈值 /// </summary> public bool CalEntropyMean(out string msg) { IRasterDataset pRasterDataset = null; try { pRasterDataset = EngineAPI.OpenRasterFile(_Hyper_Entropy); IRasterBandCollection pRasterBandCollection = pRasterDataset as IRasterBandCollection; IRasterBand pRasterBand = pRasterBandCollection.Item(0); bool hasSta = false; pRasterBand.HasStatistics(out hasSta); if (!hasSta) { pRasterBand.ComputeStatsAndHist(); } IRasterStatistics pRasterStatistics = pRasterBand.Statistics; _Hyper_Entropy_T = pRasterStatistics.Mean; msg = ""; return(true); } catch (Exception ex) { msg = ex.Message; return(false); } finally { if (pRasterDataset != null) { Marshal.ReleaseComObject(pRasterDataset); } } }
public IRasterRenderer CreateDefaultRasterRenderer(IRaster raster) { //Get raster dataset IRasterBandCollection rasterBandCollection = (IRasterBandCollection)raster; IRasterBand rasterBand = rasterBandCollection.Item(0); IRasterDataset rasterDataset = (IRasterDataset)rasterBand; //Check for TIFF format string format_Renamed = rasterDataset.Format; if (format_Renamed.Substring(0, 4) != "TIFF") { return(null); } //check for bit depth IRasterProps rasterProps = (IRasterProps)rasterBand; if (rasterProps.PixelType != rstPixelType.PT_U1) { return(null); } //create renderer for 1 bit raster //Create a unique value renderer and associate it with raster IRasterUniqueValueRenderer rasterUniqueValueRenderer = new RasterUniqueValueRendererClass(); IRasterRenderer rasterRenderer = (IRasterRenderer)rasterUniqueValueRenderer; rasterRenderer.Raster = raster; rasterRenderer.Update(); //Define the renderer rasterUniqueValueRenderer.HeadingCount = 1; rasterUniqueValueRenderer.set_Heading(0, ""); rasterUniqueValueRenderer.set_ClassCount(0, 2); rasterUniqueValueRenderer.Field = "VALUE"; rasterUniqueValueRenderer.AddValue(0, 0, 0); rasterUniqueValueRenderer.AddValue(0, 1, 1); rasterUniqueValueRenderer.set_Label(0, 0, "0"); rasterUniqueValueRenderer.set_Label(0, 1, "1"); // Define symbology for rendering value 0 IColor color1 = (IColor)(CreateRGBColor(200, 50, 0)); //Brown color ISimpleFillSymbol simpleFillSymbol1 = new SimpleFillSymbolClass(); simpleFillSymbol1.Color = color1; rasterUniqueValueRenderer.set_Symbol(0, 0, (ISymbol)simpleFillSymbol1); IColor color2 = new RgbColorClass(); color2.NullColor = true; ISimpleFillSymbol simpleFillSymbol2 = new SimpleFillSymbolClass(); simpleFillSymbol2.Color = color2; rasterUniqueValueRenderer.set_Symbol(0, 1, (ISymbol)simpleFillSymbol2); return(rasterRenderer); }
/// <summary> /// 基于给定的波段索引,获取栅格波段 /// </summary> /// <param name="inFile">输入栅格文件</param> /// <param name="bandIndex">波段索引</param> /// <returns></returns> public static IRasterBand GetRasterBandAt(string inFile, int bandIndex = 0) { IRaster raster = GetRaster(inFile); IRasterBandCollection rasterBandCollection = raster as IRasterBandCollection; return(rasterBandCollection == null ? null : rasterBandCollection.Item(bandIndex)); }
private void Btn_RasterStatistic_Click(object sender, EventArgs e) { IRasterLayer pTargetRasterLayer = m_selectedLayer as IRasterLayer; if (pTargetRasterLayer == null) { MessageBox.Show("非栅格图层"); return; } IRaster pTargetRaster = pTargetRasterLayer.Raster; IRasterBandCollection pTargetRasterBandCollection = pTargetRaster as IRasterBandCollection; string strReport = ""; for (int index = 0; index < pTargetRasterBandCollection.Count; index++) { IRasterBand pTarRasterBand = pTargetRasterBandCollection.Item(index); pTarRasterBand.HasStatistics(out bool bHasStat); if (!bHasStat) { pTarRasterBand.ComputeStatsAndHist(); } IRasterStatistics pRStatistic = pTarRasterBand.Statistics; strReport += String.Format("Band{0}\n Maximum:{1}\n Mean:{2}\n Median:{3}\n Minimum{4}\n Mode:{5}\n StandardDeviation:{6}\n", index, pRStatistic.Maximum, pRStatistic.Mean, pRStatistic.Median, pRStatistic.Minimum, pRStatistic.Mode, pRStatistic.StandardDeviation); } MessageBox.Show(strReport, m_selectedLayer.Name + "栅格信息统计"); }
private void frmSelectBand_Load(object sender, EventArgs e) { this.comboBox1.Items.Clear(); IDataLayer2 dataLayer = m_rasLayer as IDataLayer2; string dataSource = dataLayer.DataSourceName.NameString; if (dataSource.Contains("RASTER")) //�ļ� { string path = dataSource.Substring(dataSource.IndexOf('=') + 1, dataSource.IndexOf(';') - dataSource.IndexOf('=') - 2); string name = dataSource.Substring(dataSource.LastIndexOf('=') + 1, dataSource.LastIndexOf(';') - dataSource.LastIndexOf('=') - 1); IWorkspaceFactory m_workspaceFactory = new RasterWorkspaceFactoryClass(); IRasterWorkspace rasterWorkspce = m_workspaceFactory.OpenFromFile(path.Trim(), 0) as IRasterWorkspace; IRasterDataset rasDataset = rasterWorkspce.OpenRasterDataset(name.Trim()); m_rc = rasDataset as IRasterBandCollection; for (int i = 0; i < m_rc.Count; i++) { this.comboBox1.Items.Add(m_rc.Item(i).Bandname.ToString()); } } else { string name = dataSource; IRasterWorkspaceEx rasterWorkspce = m_workSpace as IRasterWorkspaceEx; IRasterDataset rasDataset = rasterWorkspce.OpenRasterDataset(name); m_rc = rasDataset as IRasterBandCollection; for (int i = 0; i < m_rc.Count; i++) { this.comboBox1.Items.Add(m_rc.Item(i).Bandname.ToString()); } } }
public normalization(IFunctionRasterDataset ReferenceRaster, IFunctionRasterDataset TransformRaster, int PercentChange = 20, rasterUtil rasterUtility = null) { referenceRaster = ReferenceRaster; IRasterBandCollection rsBc = (IRasterBandCollection)referenceRaster; rsType = referenceRaster.RasterInfo.PixelType; cellCount = new int[rsBc.Count]; minArray = new double[rsBc.Count]; maxArray = new double[rsBc.Count]; sumX2Array = new double[rsBc.Count]; sumXArray = new double[rsBc.Count]; sumXYArray = new double[rsBc.Count]; sumYArray = new double[rsBc.Count]; sumY2Array = new double[rsBc.Count]; coef = new double[rsBc.Count][]; blockCellCount = new int[rsBc.Count]; difDic = new Dictionary <int, int> [rsBc.Count]; for (int i = 0; i < rsBc.Count; i++) { difDic[i] = new Dictionary <int, int>(); } transformRaster = TransformRaster; pChange = System.Convert.ToDouble(PercentChange) / 200d; rsUtil = rasterUtility; }
private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e) { if (tabControl1.SelectedIndex == 1) { if (m_layer is IRasterLayer) { panel1.Visible = false; panel2.Visible = true; listBox1.SelectedIndex = 0; panel3.Visible = true; } else { panel1.Visible = true; panel2.Visible = false; } } if (panel3.Visible == true) { //加载波段 comboBoxBand.Items.Clear(); string strFilepath = GetFileNameByLayer.GetRasterFileName(m_layer); m_pRasterDataset = OpenFileRasterDataset(strFilepath); m_pRasterBandCollection = (IRasterBandCollection)m_pRasterDataset; int BandCount = m_pRasterBandCollection.Count; for (int i = 0; i < BandCount; i++) { IRasterBand band = m_pRasterBandCollection.Item(i); comboBoxBand.Items.Add(band.Bandname); } comboBoxBand.SelectedIndex = 0; } }
public static IRasterBand GetRasterBand(IWorkspace pSDEWorkspace, string strRasterDataset, string strBandName) { IEnumDataset pEnumdataset = pSDEWorkspace.get_Datasets(esriDatasetType.esriDTRasterDataset); IRasterBandCollection pRasterBandCollection = null; IEnumRasterBand pEnumRasterBand = null; IRasterBand pRasterBand = null; IDataset pDataset = pEnumdataset.Next(); while (pDataset != null) { if (pDataset.Name == strRasterDataset) { pRasterBandCollection = (IRasterBandCollection)pDataset; pEnumRasterBand = pRasterBandCollection.Bands; pRasterBand = pEnumRasterBand.Next(); while (pRasterBand != null) { if (pRasterBand.Bandname == strBandName) { return(pRasterBand); } pRasterBand = pEnumRasterBand.Next(); } } pDataset = pEnumdataset.Next(); } pRasterBandCollection = null; pEnumRasterBand = null; pRasterBand = null; pEnumdataset = null; pDataset = null; return(null); }
public ISurface GetSurfaceFromLayer(ILayer ilayer_0) { ISurface surface = null; if (ilayer_0 == null) { surface = null; } else if (ilayer_0 is ITinLayer) { ITinLayer tinLayer = ilayer_0 as ITinLayer; surface = (tinLayer.Dataset as ISurface); } else if (ilayer_0 is IRasterLayer) { IRasterLayer rasterLayer = ilayer_0 as IRasterLayer; if (surface == null) { IRasterBandCollection rasterBandCollection = rasterLayer.Raster as IRasterBandCollection; IRasterBand rasterBand = rasterBandCollection.Item(0); surface = (new RasterSurface { RasterBand = rasterBand } as ISurface); } } return(surface); }
internal static Dictionary <string, double> SummariseRasterStatistically(IGeoDataset pRasterGeoDataset) { IRasterBandCollection tClippedAsBandCollection = pRasterGeoDataset as IRasterBandCollection; IRasterBand tClippedBand = tClippedAsBandCollection.Item(0); logger.LogMessage(ServerLogger.msgType.debug, "SummariseContinuousRaster", 99, "Continuous raster clipped, checking stats..."); bool tHasStatistics; tClippedBand.HasStatistics(out tHasStatistics); // what on earth? why not just have a bool return type to the HasStatistics method??! if (!tHasStatistics) { tClippedBand.ComputeStatsAndHist(); } IRasterStatistics tClippedStats = tClippedBand.Statistics; //tClippedStats.Recalculate(); logger.LogMessage(ServerLogger.msgType.debug, "SummariseContinuousRaster", 99, "Continuous raster stats made, recording info..."); Dictionary <string, double> tResults = new Dictionary <string, double>(); tResults["Mean"] = tClippedStats.Mean; tResults["Max"] = tClippedStats.Maximum; tResults["Min"] = tClippedStats.Minimum; //NB Median isn't available with floating data. (Neither are majority,minority,variety). Would need //to e.g. convert to int by multiplying raster first. //tResults["Median"] = tClippedStats.Median; return(tResults); }
public void addRasterToComboBox(string rstName, IRaster rst) { IRasterBandCollection rsBc = (IRasterBandCollection)rst; if (rsBc.Count > 1) { for (int i = 0; i < rsBc.Count; i++) { string rstName2 = rstName + "_Band_" + (i + 1).ToString(); if (!cmbInRaster1.Items.Contains(rstName2)) { cmbInRaster1.Items.Add(rstName2); rstDic[rstName] = rst; } } } else { if (!cmbInRaster1.Items.Contains(rstName)) { cmbInRaster1.Items.Add(rstName); rstDic[rstName] = rst; } } }
public static void GetCurrentSurfaceMax(ILayer ilayer_0, out double double_0, out double double_1) { ISurface surfaceFromLayer = SurfaceInfo.GetSurfaceFromLayer(ilayer_0); if (surfaceFromLayer != null) { if (surfaceFromLayer is ITinAdvanced) { ITinAdvanced tinAdvanced = surfaceFromLayer as ITinAdvanced; IEnvelope extent = tinAdvanced.Extent; double_0 = ((extent.Width > extent.Height) ? extent.Width : extent.Height); double_1 = extent.ZMax; } else { IRasterSurface rasterSurface = surfaceFromLayer as IRasterSurface; IRasterProps rasterProps = rasterSurface.Raster as IRasterProps; IEnvelope extent = rasterProps.Extent; double_0 = ((extent.Width > extent.Height) ? extent.Width : extent.Height); IRasterBandCollection rasterBandCollection = rasterProps as IRasterBandCollection; IRasterBand rasterBand = rasterBandCollection.Item(0); IRasterStatistics statistics = rasterBand.Statistics; double_1 = statistics.Maximum; } } else { double_0 = 0.0; double_1 = 0.0; } }
private void FrmGenerateScene_Load(object sender, EventArgs e) { // itemPanelSetVisible.Items.Clear(); doubleInputExaFactor.Value = Convert.ToDecimal(m_pSceneCtrl.Scene.ExaggerationFactor.ToString()); comboBoxExBaseHeightLayer.Items.Clear(); if (m_pMapCtrl != null) { for (int i = 0; i < m_pMapCtrl.Map.LayerCount; i++) { DevComponents.DotNetBar.CheckBoxItem CBItem = new DevComponents.DotNetBar.CheckBoxItem(); CBItem.Checked = true; ILayer pLayer = m_pMapCtrl.Map.get_Layer(i); CBItem.Text = pLayer.Name; // itemPanelSetVisible.Items.Add(CBItem); if (pLayer is IRasterLayer) { IRasterBandCollection pRasterCollection = ((IRasterLayer)pLayer).Raster as IRasterBandCollection; if (pRasterCollection.Count == 1) { comboBoxExBaseHeightLayer.Items.Add(pLayer.Name); } } if (pLayer is ITinLayer) { comboBoxExBaseHeightLayer.Items.Add(pLayer.Name); } } } if (comboBoxExBaseHeightLayer.Items.Count > 0) { comboBoxExBaseHeightLayer.SelectedIndex = 0; } }
public void Init() { try { //根据选择的矢量文件的路径打开工作空间 string fileN = panImage; FileInfo fileInfo = new FileInfo(fileN); string filePath = fileInfo.DirectoryName; string fileName = fileInfo.Name; IWorkspaceFactory wsf = new RasterWorkspaceFactory(); IWorkspace wp = wsf.OpenFromFile(filePath, 0); IRasterWorkspace rw = (IRasterWorkspace)wp; IRasterDataset panDataset = rw.OpenRasterDataset(fileName); IRaster2 multiRaster2 = m_raster as IRaster2; IRasterDataset multiDataset = multiRaster2.RasterDataset; //默认波段顺序,RGB和近红外 //创建全色和多光谱栅格数据集的full栅格对象 IRaster panRaster = ((IRasterDataset2)panDataset).CreateFullRaster(); IRaster multiRaster = ((IRasterDataset2)multiDataset).CreateFullRaster(); //设置红外波段 IRasterBandCollection rasterbandCol = (IRasterBandCollection)multiRaster; IRasterBandCollection infredRaster = new RasterClass(); infredRaster.AppendBand(rasterbandCol.Item(3)); //设置全色波段的属性 IRasterProps panSharpenRasterProps = (IRasterProps)multiRaster; IRasterProps panRasterProps = (IRasterProps)panRaster; panSharpenRasterProps.Width = panRasterProps.Width; panSharpenRasterProps.Height = panRasterProps.Height; panSharpenRasterProps.Extent = panRasterProps.Extent; multiRaster.ResampleMethod = rstResamplingTypes.RSP_BilinearInterpolationPlus; //创建全色锐化过滤器和设置其参数 IPansharpeningFilter pansharpenFilter = new PansharpeningFilterClass(); pansharpenFilter.InfraredImage = (IRaster)infredRaster; pansharpenFilter.PanImage = (IRaster)panRaster; pansharpenFilter.PansharpeningType = esriPansharpeningType.esriPansharpeningESRI; pansharpenFilter.PutWeights(red, green, blue, infra); //将全色锐化过滤器设置于多光谱栅格对象上 IPixelOperation pixeOperation = (IPixelOperation)multiRaster; pixeOperation.PixelFilter = (IPixelFilter)pansharpenFilter; //保存结果数据集,并加载显示 //加载显示裁剪结果图像 /*IRasterLayer panSharpenLayer = new RasterLayerClass(); * panSharpenLayer.CreateFromRaster(multiRaster); * panSharpenLayer.Name = "panSharpen_Result"; * panSharpenLayer.SpatialReference = ((IGeoDataset)multiRaster).SpatialReference; * return panSharpenLayer;*/ m_raster = multiRaster; } catch (System.Exception ex)//异常处理,输出错误信息 { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 获取当前栅格图层中城市用地类型栅格的数量。区分栅格图层是否有属性表两种情况。 /// </summary> /// <param name="rasterLayer"></param> /// <param name="landUseClassificationInfo"></param> /// <returns></returns> public static int GetUrbanCount(IRasterLayer rasterLayer, LandUseClassificationInfo landUseClassificationInfo) { int urbanConuts = 0; IRasterBandCollection rbc = rasterLayer.Raster as IRasterBandCollection; IRasterBand rb = rbc.Item(0); //ITable table = rbc.Item(0).AttributeTable; //AttributeTable - OID, Value, Count ITable attributeTable = rb.AttributeTable; if (attributeTable != null) { int count = attributeTable.RowCount(null); int[] values = new int[count]; int[] counts = new int[count]; ICursor cursor = attributeTable.Search(null, false); IRow row = cursor.NextRow(); int index = 0; //数据不一定有OBJECTID字段。同时列名称及顺序不一定符合条件Value,Count。 while (row != null) { values[index] = Convert.ToInt32(row.get_Value(GetColumnIndex(attributeTable, "VALUE"))); counts[index] = Convert.ToInt32(row.get_Value(GetColumnIndex(attributeTable, "COUNT"))); row = cursor.NextRow(); index++; } for (int j = 0; j < count; j++) { for (int i = 0; i < landUseClassificationInfo.UrbanValues.Count; i++) { if (Convert.ToSingle(values[j]) == landUseClassificationInfo.UrbanValues[i].LanduseTypeValue) { urbanConuts += Convert.ToInt32(counts[j]); } } } } else { rb.ComputeStatsAndHist(); IRasterHistogram rh = rb.Histogram; object rhCount = rh.Counts; double[] counts = (double[])rhCount; IRasterUniqueValueRenderer rasterUniqueValueRenderer = (IRasterUniqueValueRenderer)rasterLayer.Renderer; IRasterRendererUniqueValues rasterRendererUniqueValues = (IRasterRendererUniqueValues)rasterUniqueValueRenderer; IUniqueValues uniqueValues = rasterRendererUniqueValues.UniqueValues; for (int j = 0; j < uniqueValues.Count; j++) { for (int i = 0; i < landUseClassificationInfo.UrbanValues.Count; i++) { if (Convert.ToSingle(uniqueValues.get_UniqueValue(j)) == landUseClassificationInfo.UrbanValues[i].LanduseTypeValue) { urbanConuts += Convert.ToInt32(counts[j + 1]); } } } } return(urbanConuts); }
private void frmSelectBand_Load(object sender, EventArgs e) { this.comboBox1.Items.Clear(); IDataLayer2 dataLayer = m_rasLayer as IDataLayer2; string dataSource = dataLayer.DataSourceName.NameString; if (dataSource.Contains("RASTER")) //Îļþ { string path = dataSource.Substring(dataSource.IndexOf('=') + 1, dataSource.IndexOf(';') - dataSource.IndexOf('=') - 2); string name = dataSource.Substring(dataSource.LastIndexOf('=') + 1, dataSource.LastIndexOf(';') - dataSource.LastIndexOf('=') - 1); IWorkspaceFactory m_workspaceFactory = new RasterWorkspaceFactoryClass(); IRasterWorkspace rasterWorkspce = m_workspaceFactory.OpenFromFile(path.Trim(), 0) as IRasterWorkspace; IRasterDataset rasDataset = rasterWorkspce.OpenRasterDataset(name.Trim()); m_rc = rasDataset as IRasterBandCollection; for (int i = 0; i < m_rc.Count; i++) { this.comboBox1.Items.Add(m_rc.Item(i).Bandname.ToString()); } } else { string name = dataSource; IRasterWorkspaceEx rasterWorkspce = m_workSpace as IRasterWorkspaceEx; IRasterDataset rasDataset = rasterWorkspce.OpenRasterDataset(name); m_rc = rasDataset as IRasterBandCollection; for (int i = 0; i < m_rc.Count; i++) { this.comboBox1.Items.Add(m_rc.Item(i).Bandname.ToString()); } } }
/// <summary> /// 栅格保存为数据集(并创建金字塔) /// </summary> /// <param name="raster">栅格</param> /// <param name="outFile">输出文件</param> public static void SaveRasterAsDataset(IRaster raster, string outFile) { //文件已存在,则返回 if (File.Exists(outFile) || raster == null) { return; } IRasterBandCollection pRasBandCol = raster as IRasterBandCollection; if (pRasBandCol == null) { return; } string fileName = Path.GetFileName(outFile); IWorkspace workspace = RasterDataInfoClass.GetRasterWorkspace(outFile); //保存波段集合为数据集 IDataset dataset = pRasBandCol.SaveAs(fileName, workspace, "IMAGINE Image"); ITemporaryDataset pRsGeo = dataset as ITemporaryDataset; if (pRsGeo != null && pRsGeo.IsTemporary()) { pRsGeo.MakePermanent(); } RasterDataInfoClass.CreatePyramid(outFile); //创建金字塔 }
private int GetMaxBandCount() { int[] max = new int[m_selband.Length]; for (int i = 0; i < m_selband.Length; i++) { IRaster2 raster2 = m_rstlayer.Raster as IRaster2; IRasterDataset rstDataset = raster2.RasterDataset; IRasterBandCollection rstBandColl = rstDataset as IRasterBandCollection; IRasterBand rasterBand = rstBandColl.Item(i); //获取每个像元值的统计个数 double[] histo = rasterBand.Histogram.Counts as double[]; //计算最大像元数 int maxCount = (int)histo[0]; for (int j = 0; j < histo.Length; j++) { if (maxCount < histo[j]) { maxCount = (int)histo[j]; } } //记录下该波段的最大像元数 max[i] = maxCount; } //计算所有波段的最大像元数 int maxst = max[0]; for (int k = 0; k < max.Length; k++) { if (maxst < max[k]) { maxst = (int)max[k]; } } return(maxst); }
private void Btn_ApplyRasterBaseSurface_Click(object sender, EventArgs e) { ILayer pBaseLayer = m_pTarScene.Layer[CbBoxBaseLayer.SelectedIndex]; ILayer pDisplayLayer = m_pTarLayer; IRasterSurface pBaseSurfaceRaster = new RasterSurface(); IRasterLayer pBaseRasterLayer = pBaseLayer as IRasterLayer; IRaster pBaseRaster = (IRaster)pBaseRasterLayer.Raster; IRasterBandCollection pBaseRasterBandCollection = pBaseRaster as IRasterBandCollection; IRasterBand pBaseRasterBand = pBaseRasterBandCollection.Item(0); pBaseSurfaceRaster.RasterBand = pBaseRasterBand; ISurface pBaseSurface = pBaseSurfaceRaster as ISurface; ILayerExtensions pLayerExtensions = pDisplayLayer as ILayerExtensions; I3DProperties p3DProperties = null; for (int i = 0; i < pLayerExtensions.ExtensionCount; i++) { object pCurExtension = pLayerExtensions.get_Extension(i); if (pCurExtension != null) { p3DProperties = (I3DProperties)pCurExtension; break; } } p3DProperties.BaseOption = esriBaseOption.esriBaseSurface; p3DProperties.BaseSurface = pBaseSurface; p3DProperties.Apply3DProperties(pDisplayLayer); p3DProperties.ZFactor = 1; m_pTarScene.SceneGraph.RefreshViewers(); }
public static void setNoDataValueForASpecificBand(IRasterDataset rasterDataset) { IRasterBandCollection rasterBandCollection = (IRasterBandCollection)rasterDataset; IRasterBand rasterBand = rasterBandCollection.Item(0); IRasterProps rasterProps = (IRasterProps)rasterBand; rasterProps.NoDataValue = 15; }
public IFunctionRasterDataset calcCombineRasterFunction(IRasterBandCollection rsbc) { return compositeBandFunction(rsbc); }
/// <summary> /// creates a composite band function /// </summary> /// <param name="rsArray"></param> /// <returns></returns> public IFunctionRasterDataset compositeBandFunction(IRasterBandCollection rsBandCollection) { string tempAr = funcDir + "\\" + FuncCnt + ".afr"; IFunctionRasterDataset frDset = new FunctionRasterDatasetClass(); IFunctionRasterDatasetName frDsetName = new FunctionRasterDatasetNameClass(); frDsetName.FullName = tempAr; frDset.FullName = (IName)frDsetName; IRasterFunction rsFunc = new CompositeBandFunctionClass(); frDset.Init(rsFunc, rsBandCollection); return frDset; }
/// <summary> /// /// </summary> /// <param name="_pGdsLocation"></param> /// <param name="_BandCol"></param> /// <returns></returns> private ITable ExportSample(IGeoDataset _pGdsLocation, IRasterBandCollection _BandCol) { //IRasterLayer pRastetLayer = pLayer as IRasterLayer; //IRasterBandCollection pRasterBandColection = pRastetLayer.Raster as IRasterBandCollection; //if (pRasterBandColection.Count == 1) //{ //Create the RasterExtractionOp object IExtractionOp pExtractionOp = new RasterExtractionOpClass(); ////Declare the input location raster object //IGeoDataset pGdsLocation=_pGdsLocation; ////Create a raster of multiple bands //IRasterBandCollection pBandCol=_BandCol; ////Declare the output table object ITable pOutputTable; //Calls the method pOutputTable = pExtractionOp.Sample(_pGdsLocation, _BandCol as IGeoDataset, esriGeoAnalysisResampleEnum.esriGeoAnalysisResampleNearest); return pOutputTable; //} }