Exemplo 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);
        }
Exemplo 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);
            }
        }
Exemplo 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);
        }
Exemplo n.º 4
0
        public static IRasterRenderer CreateSlopeDegreesColorRamp(GCDConsoleLib.Raster gRaster)
        {
            IRasterRenderer rasterRenderer = null;

            try
            {
                // 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();

                // Create the classify renderer
                IRasterClassifyColorRampRenderer classifyRenderer = new RasterClassifyColorRampRendererClass();
                rasterRenderer = (IRasterRenderer)classifyRenderer;
                IRaster raster = rasterDataset.CreateDefaultRaster();
                rasterRenderer.Raster       = raster;
                classifyRenderer.ClassCount = 10;
                rasterRenderer.Update();

                classifyRenderer.Break[0]  = (double)gRaster.GetStatistics()["min"];
                classifyRenderer.Label[0]  = "0 to 2";
                classifyRenderer.Break[1]  = 2;
                classifyRenderer.Label[1]  = "2 to 5";
                classifyRenderer.Break[2]  = 5;
                classifyRenderer.Label[2]  = "5 to 10";
                classifyRenderer.Break[3]  = 10;
                classifyRenderer.Label[3]  = "10 to 15";
                classifyRenderer.Break[4]  = 15;
                classifyRenderer.Label[4]  = "15 to 25";
                classifyRenderer.Break[5]  = 25;
                classifyRenderer.Label[5]  = "25 to 35";
                classifyRenderer.Break[6]  = 35;
                classifyRenderer.Label[6]  = "35 to 45";
                classifyRenderer.Break[7]  = 45;
                classifyRenderer.Label[7]  = "45 to 60";
                classifyRenderer.Break[8]  = 60;
                classifyRenderer.Label[8]  = "60 to 80";
                classifyRenderer.Break[9]  = 80;
                classifyRenderer.Label[9]  = "80 to 90";
                classifyRenderer.Break[10] = 90;

                //Create the symbol for the classes.
                List <RgbColor> lColors    = CreateSlopeColorRamp();
                IFillSymbol     fillSymbol = new SimpleFillSymbolClass();
                for (int i = 0; i < classifyRenderer.ClassCount; i++)
                {
                    fillSymbol.Color           = lColors[i];
                    classifyRenderer.Symbol[i] = (ISymbol)fillSymbol;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                rasterRenderer = null;
            }

            return(rasterRenderer);
        }