Ejemplo n.º 1
0
        public static IRasterRenderer CreateGrainSizeStatisticColorRamp(GCDConsoleLib.Raster gRaster, UnitsNet.Units.LengthUnit eUnits)
        {
            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();

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

                rasterRenderer.Raster       = raster;
                classifyRenderer.ClassCount = 5;
                rasterRenderer.Update();
                classifyRenderer.Break[0] = 0;
                classifyRenderer.Label[0] = "Fines, Sand (0 to 2 mm)";
                classifyRenderer.Break[1] = UnitsNet.Length.From(2, UnitsNet.Units.LengthUnit.Millimeter).As(eUnits);
                classifyRenderer.Label[1] = "Fine Gravel (2 mm to 16 mm)";
                classifyRenderer.Break[2] = UnitsNet.Length.From(16, UnitsNet.Units.LengthUnit.Millimeter).As(eUnits);
                classifyRenderer.Label[2] = "Coarse Gravel (16 mm to 64 mm)";
                classifyRenderer.Break[3] = UnitsNet.Length.From(64, UnitsNet.Units.LengthUnit.Millimeter).As(eUnits);
                classifyRenderer.Label[3] = "Cobbles (64 mm to 256 mm)";
                classifyRenderer.Break[4] = UnitsNet.Length.From(256, UnitsNet.Units.LengthUnit.Millimeter).As(eUnits);
                classifyRenderer.Label[4] = "Boulders (> 256 mm)";

                List <RgbColor> lColors = new List <RgbColor>();
                lColors.Add(CreateRGBColor(194, 82, 60));
                lColors.Add(CreateRGBColor(240, 180, 17));
                lColors.Add(CreateRGBColor(123, 237, 0));
                lColors.Add(CreateRGBColor(27, 168, 124));
                lColors.Add(CreateRGBColor(11, 44, 122));

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

                return(rasterRenderer);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
Ejemplo n.º 2
0
        public static IRasterRenderer CreateClassifyRenderer(GCDConsoleLib.Raster gRaster, int iClassCount, string sColorRampName, double dMax, bool bInvert = false)
        {
            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();

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

                rasterRenderer.Raster = raster;
                IColorRamp        pColorRamp;
                IStyleGalleryItem pStyleItem = GetESRIStyleColorRamp(out pColorRamp, sColorRampName);
                classifyRenderer.ClassCount = iClassCount;
                rasterRenderer.Update();
                CreateClassBreaks(dMax, iClassCount, classifyRenderer);
                pColorRamp.Size = iClassCount;
                bool bOK = false;
                pColorRamp.CreateRamp(out bOK);
                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);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
Ejemplo n.º 3
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.º 4
0
        /// <summary>
        /// Given a Template Raster, a vector and a field name, create a usable rasterized poly mask
        /// Notice how we use everything from the template raster except the projection, which MUST
        /// come from the vector in case there are slight differences.
        /// </summary>
        /// <param name="Template">Template will be used for Shape and projection only</param>
        /// <param name="input"></param>
        /// <param name="FieldName"></param>
        public VectorRaster(Raster Template, Vector vectorInput, string FieldName) : base(Template, vectorInput.Proj)
        {
            FieldValues = new Dictionary <int, string> {
            };
            Datatype    = new GdalDataType(typeof(int));

            SetNoData(-1.0);
            // Do GDaL's rasterize first to get the rough boolean shape.
            Rasterize(vectorInput, this);

            int fieldIndex = vectorInput.Features.First().Value.Feat.GetFieldIndex(FieldName);

            if (fieldIndex == -1)
            {
                throw new IndexOutOfRangeException(String.Format("Could not find field: `{0}`", FieldName));
            }

            int GDALMASKidx = vectorInput.Features.First().Value.Feat.GetFieldIndex(Vector.CGDMASKFIELD);

            if (GDALMASKidx == -1)
            {
                throw new IndexOutOfRangeException(String.Format("Could not find MANDATORY field: `{0}`", FieldName));
            }

            // Now make an equivalence between the GCDFID field and the FieldName Values
            foreach (KeyValuePair <long, VectorFeature> kvp in vectorInput.Features)
            {
                int    maskid = kvp.Value.Feat.GetFieldAsInteger(GDALMASKidx);
                string val    = kvp.Value.Feat.GetFieldAsString(fieldIndex);
                if (!FieldValues.ContainsKey(maskid))
                {
                    FieldValues.Add(maskid, val);
                }
            }
            vectorInput.Dispose();
        }
Ejemplo n.º 5
0
 public bool IsOrthogonal(Raster otherRaster)
 {
     return(Extent.IsOrthogonal(otherRaster.Extent));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Just some helper convenience methods:
 /// </summary>
 public bool IsConcurrent(Raster otherRaster)
 {
     return(Extent.IsConcurrent(otherRaster.Extent));
 }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        public static IRasterRenderer CreateRoughnessColorRamp(GCDConsoleLib.Raster gRaster)
        {
            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();

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

                rasterRenderer.Raster       = raster;
                classifyRenderer.ClassCount = 10;
                rasterRenderer.Update();
                classifyRenderer.Break[0] = 0;
                classifyRenderer.Label[0] = "0 to 0.1";
                classifyRenderer.Break[1] = 0.1;
                classifyRenderer.Label[1] = "0.1 to 0.25";
                classifyRenderer.Break[2] = 0.25;
                classifyRenderer.Label[2] = "0.25 to 0.5";
                classifyRenderer.Break[3] = 0.5;
                classifyRenderer.Label[3] = "0.5 to 0.75";
                classifyRenderer.Break[4] = 0.75;
                classifyRenderer.Label[4] = "0.75 to 1.0";
                classifyRenderer.Break[5] = 1;
                classifyRenderer.Label[5] = "1.0 to 1.5";
                classifyRenderer.Break[6] = 1.5;
                classifyRenderer.Label[6] = "1.5 to 2.0";
                classifyRenderer.Break[7] = 2;
                classifyRenderer.Label[7] = "2.0 to 3.0";
                classifyRenderer.Break[8] = 3;
                classifyRenderer.Label[8] = "3.0 to 5.0";
                classifyRenderer.Break[9] = 5;
                classifyRenderer.Label[9] = "> 5.0";

                List <RgbColor> lColors = new List <RgbColor>();
                lColors.Add(CreateRGBColor(255, 255, 179));
                lColors.Add(CreateRGBColor(252, 241, 167));
                lColors.Add(CreateRGBColor(252, 230, 157));
                lColors.Add(CreateRGBColor(250, 218, 145));
                lColors.Add(CreateRGBColor(250, 208, 135));
                lColors.Add(CreateRGBColor(237, 191, 126));
                lColors.Add(CreateRGBColor(219, 167, 118));
                lColors.Add(CreateRGBColor(201, 147, 111));
                lColors.Add(CreateRGBColor(184, 127, 106));
                lColors.Add(CreateRGBColor(166, 101, 101));

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

                return(rasterRenderer);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
Ejemplo n.º 9
0
 public GdalDataType(Raster rRaster)
 {
     _origType = rRaster.Datatype._origType;
 }