예제 #1
0
        private int GetMaxBandCount()
        {
            int                   maxCount          = 0;
            IRaster2              raster2           = m_rstlayer.Raster as IRaster2;
            IRasterDataset        rstDataset        = raster2.RasterDataset;
            IRasterBandCollection rstBandCollection = rstDataset as IRasterBandCollection;


            int[] max = new int[m_selband.Length];
            for (int i = 0; i < m_selband.Length; i++)
            {
                IRasterBand rstBand = rstBandCollection.Item(m_selband[i]);
                bool        hasStat = false;
                rstBand.HasStatistics(out hasStat);
                if (null == rstBand.Statistics || !hasStat || null == rstBand.Histogram)
                {
                    //转换Irasterbandedit2接口,调用computestshistogram方法用于波段信息统计以及直方图绘制
                    IRasterBandEdit2 rstBandEdit = rstBand as IRasterBandEdit2;
                    rstBandEdit.ComputeStatsHistogram(0);
                }
                //获取每个像元值的统计个数
                double[] pixelCounts = rstBand.Histogram.Counts as double[];
                max[i] = (int)pixelCounts[0];
                for (int j = 0; j < pixelCounts.Length; j++)
                {
                    if (max[i] < pixelCounts[j])
                    {
                        max[i] = (int)pixelCounts[j];
                    }
                }

                maxCount = max[0];
                for (int j = 0; j < m_selband.Length; j++)
                {
                    if (maxCount < max[j])
                    {
                        maxCount = max[j];
                    }
                }
            }
            return(maxCount);
        }
예제 #2
0
        private void DrawHisto(int index, int maxst, Graphics g)
        {
            Pen   pen   = new Pen(Brushes.Black, 1);
            Color color = Color.Black;

            switch (index)
            {
            case 0:
                color = Color.Red;
                break;

            case 1:
                color = Color.Orange;
                break;

            case 2:
                color = Color.Yellow;
                break;

            case 3:
                color = Color.Green;
                break;

            case 4:
                color = Color.Blue;
                break;

            case 5:
                color = Color.Purple;
                break;

            case 6:
                color = Color.Peru;
                break;
            }
            pen.Color = color;
            IRaster2              raster2           = m_rstlayer.Raster as IRaster2;
            IRasterDataset        rstDataset        = raster2.RasterDataset;
            IRasterBandCollection rstBandCollection = rstDataset as IRasterBandCollection;
            IRasterBand           rstBand           = rstBandCollection.Item(index);

            bool hasStat = false;

            rstBand.HasStatistics(out hasStat);
            if (null == rstBand.Statistics || !hasStat || null == rstBand.Histogram)
            {
                //转换Irasterbandedit2接口,调用computestshistogram方法用于波段信息统计以及直方图绘制
                IRasterBandEdit2 rstBandEdit = rstBand as IRasterBandEdit2;
                rstBandEdit.ComputeStatsHistogram(0);
            }
            //获取每个像元值的统计个数
            double[] pixelCounts = rstBand.Histogram.Counts as double[];
            double   xTemp       = 0;
            double   yTemp       = 0;

            for (int i = 0; i < pixelCounts.Length; i++)
            {
                xTemp = i * 1.0 / pixelCounts.Length * (300 - 50);
                yTemp = 200.0 * pixelCounts[i] / maxst;
                g.DrawLine(pen, 50 + (int)xTemp, 240, 50 + (int)xTemp, 240 - (int)yTemp);
            }
            pen.Dispose();
        }