Ejemplo n.º 1
0
        public static IRasterRenderer CreateClassifyRenderer(GCDConsoleLib.Raster gRaster, int iClassCount, string sColorRampName, bool bInvert = false)
        {
            // Open file raster dataset and ensure that statistics and histograms are present (absence of histograms will cause Renderer.Update() to crash)
            IRasterDataset rasterDataset = ArcMapUtilities.GetRasterDataset(gRaster);

            ESRI.ArcGIS.DataSourcesRaster.IRasterBandCollection pRastBands     = (ESRI.ArcGIS.DataSourcesRaster.IRasterBandCollection)rasterDataset;
            ESRI.ArcGIS.DataSourcesRaster.IEnumRasterBand       enumRasterBand = (ESRI.ArcGIS.DataSourcesRaster.IEnumRasterBand)pRastBands.Bands;
            rasterDataset.PrecalculateStats(0);
            ESRI.ArcGIS.DataSourcesRaster.IRasterBand pRastBand = enumRasterBand.Next();
            pRastBand.ComputeStatsAndHist();

            gRaster.ComputeStatistics();
            decimal maxValue = gRaster.GetStatistics()["max"];

            IRasterClassifyColorRampRenderer classifyRenderer = new RasterClassifyColorRampRendererClass();
            IRasterRenderer rasterRenderer = (IRasterRenderer)classifyRenderer;
            IFillSymbol     fillSymbol     = new SimpleFillSymbol();
            IRaster         raster         = rasterDataset.CreateDefaultRaster();

            rasterRenderer.Raster = raster;
            IColorRamp        pColorRamp = null;
            IStyleGalleryItem pStyleItem = GetESRIStyleColorRamp(out pColorRamp, sColorRampName);

            classifyRenderer.ClassCount = iClassCount;
            rasterRenderer.Update();
            CreateClassBreaks((double)maxValue, iClassCount, classifyRenderer);
            pColorRamp.Size = iClassCount;
            bool bSucess = true;

            pColorRamp.CreateRamp(out bSucess);
            List <IColor> lColors = new List <IColor>();

            for (int i = 0; i < classifyRenderer.ClassCount; i++)
            {
                lColors.Add(pColorRamp.Color[i]);
            }

            if (bInvert)
            {
                lColors.Reverse();
            }

            for (int i = 0; i < classifyRenderer.ClassCount; i++)
            {
                fillSymbol.Color           = lColors[i];
                classifyRenderer.Symbol[i] = (ISymbol)fillSymbol;
            }

            return(rasterRenderer);
        }
Ejemplo n.º 2
0
        public static IRasterRenderer CreateESRIDefinedContinuousRenderer(GCDConsoleLib.Raster gRaster, int iClassCount, string sColorRampName, bool bInvert = false)
        {
            try
            {
                gRaster.ComputeStatistics();
                decimal maxValue        = gRaster.GetStatistics()["max"];
                int     iRound          = GetMagnitude(maxValue);
                double  maxValueRounded = Math.Round((double)maxValue, Math.Abs(iRound));

                RasterStretchColorRampRenderer stretchRenderer = new RasterStretchColorRampRendererClass();
                IRasterRenderer rasterRenderer = (IRasterRenderer)stretchRenderer;
                IRasterDataset  rasterDataset  = ArcMapUtilities.GetRasterDataset(gRaster);
                IRaster         raster         = rasterDataset.CreateDefaultRaster();
                rasterRenderer.Raster = raster;
                IColorRamp               pColorRamp       = null;
                IStyleGalleryItem        pStyleItem       = GetESRIStyleColorRamp(out pColorRamp, sColorRampName);
                IRasterRendererColorRamp pRenderColorRamp = (IRasterRendererColorRamp)rasterRenderer;
                pRenderColorRamp.ColorScheme = pStyleItem.Name;
                IRasterStretchMinMax pStretchInfo = (IRasterStretchMinMax)stretchRenderer;
                pStretchInfo.CustomStretchMin       = 0;
                pStretchInfo.CustomStretchMax       = maxValueRounded;
                pStretchInfo.UseCustomStretchMinMax = true;
                stretchRenderer.LabelHigh           = maxValueRounded.ToString();
                stretchRenderer.LabelLow            = "0.0";
                if (bInvert)
                {
                    IRasterStretch2 pStretch = (IRasterStretch2)stretchRenderer;
                    pStretch.Invert = true;
                }

                rasterRenderer.Update();
                return(rasterRenderer);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructing this object from a raster and a number of bins
        /// </summary>
        /// <param name="bins"></param>
        /// <param name="rRa"></param>
        public Histogram(int bins, Raster rRa)
        {
            rRa.ComputeStatistics();
            Dictionary <string, decimal> stats;

            try
            {
                stats = rRa.GetStatistics();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                stats = new Dictionary <string, decimal> {
                    { "max", 0 },
                    { "min", 0 },
                };
            }
            Tuple <int, decimal> newDims;

            // No point calculating stats if there are no bins
            if (stats["max"] == stats["min"])
            {
                if (stats["max"] == 0)
                {
                    newDims = new Tuple <int, decimal>(1, 1);
                }
                else
                {
                    newDims = new Tuple <int, decimal>(1, Math.Abs(stats["max"]));
                }
            }
            else
            {
                newDims = GetCleanBins(bins, stats["max"], stats["min"]);
            }

            _init(newDims.Item1, newDims.Item2);
        }