예제 #1
0
파일: Thematic.cs 프로젝트: truonghinh/TnX
 public Thematic(IMapControl3 mapControl)
 {
     if (mapControl != null)
     {
         this._mapControl = mapControl;
     }
     _renderer = new ClassBreaksRendererClass();
     _classify = new QuantileClass();
     _tableHistogram = new BasicTableHistogramClass();
     _colorFrom = new HsvColorClass();
     _colorTo = new HsvColorClass();
     _algClrRamp = new AlgorithmicColorRampClass();
 }
예제 #2
0
        /// <summary>
        /// 输入HSV值,获取IHsvColor型值
        /// </summary>
        /// <param name="intH">Hue</param>
        /// <param name="intS">Saturation</param>
        /// <param name="intV">Value</param>
        /// <returns>IHsvColor</returns>
        public static IHsvColor GetHsvColor(int intH, int intS, int intV)
        {
            IHsvColor hsvColor = null;

            if (intH < 0 || intH > 360 || intS < 0 || intS > 100 || intV < 0 || intV > 100)
            {
                return(hsvColor);
            }
            hsvColor            = new HsvColorClass();
            hsvColor.Hue        = intH;
            hsvColor.Saturation = intS;
            hsvColor.Value      = intV;
            return(hsvColor);
        }
예제 #3
0
        public static IAlgorithmicColorRamp CreateColorRamp(IHsvColor fromColor, IHsvColor toColor, int size = 10)
        {
            IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRampClass()
            {
                FromColor = fromColor,
                ToColor   = toColor,                                 // 起止颜色
                Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm, // 梯度类型
                Size      = size                                     // 色带颜色数量
            };
            // 创建色带
            bool bture = true;

            pColorRamp.CreateRamp(out bture);
            return(pColorRamp);
        }
예제 #4
0
 public IHsvColor GetHsvColor(int iHue, int iSaturation, int iValue, bool bUseWinDithering)
 {
     try
     {
         IHsvColor color = null;
         color                     = new HsvColorClass();
         iHue                      = this.CheckNumValueRegion(iHue, 0, 360);
         iSaturation               = this.CheckNumValueRegion(iSaturation, 0, 100);
         iValue                    = this.CheckNumValueRegion(iValue, 0, 100);
         color.Hue                 = iHue;
         color.Saturation          = iSaturation;
         color.Value               = iValue;
         color.UseWindowsDithering = bUseWinDithering;
         return(color);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.ColorFun", "GetHsvColor", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(null);
     }
 }
예제 #5
0
        protected override void OnClick()
        {
            //
            // When the utility is selected, check that we have a currently selected
            // feature layer with a ClassBreaksRenderer already set. First we get the contents view.
            //
            IContentsView ContentsView = null;

            ContentsView = ArcMap.Document.CurrentContentsView;
            //
            // If we have a DisplayView active
            //
            object               VarSelectedItem     = null;
            IGeoFeatureLayer     GeoFeatureLayer     = null;
            IClassBreaksRenderer ClassBreaksRenderer = null;
            IEnumColors          pColors             = null;
            int         lngCount     = 0;
            IHsvColor   HsvColor     = null;
            IClone      ClonedSymbol = null;
            ISymbol     NewSymbol    = null;
            IActiveView ActiveView   = null; //AlgorithimcColorRamp contains HSV colors.

            if (ContentsView is TOCDisplayView)
            {
                if (ContentsView.SelectedItem is DBNull)
                {
                    //
                    // If we don't have anything selected.
                    //
                    MessageBox.Show("SelectedItem is Null C#." + "Select a layer in the Table of Contents.", "No Layer Selected", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                //
                // Get the selected Item.
                //
                VarSelectedItem = ContentsView.SelectedItem;
                //
                // Selected Item should implement the IGeoFeatureLayer interface - therefore we
                // have selected a feature layer with a Renderer property (Note: Other interfaces
                // also have a Renderer property, which may behave differently.
                //
                if (VarSelectedItem is IGeoFeatureLayer)
                {
                    GeoFeatureLayer = (IGeoFeatureLayer)VarSelectedItem;
                    //
                    // Set the cached property to true, so we can refresh this layer
                    // without refreshing all the layers, when we have changed the symbols.
                    //
                    GeoFeatureLayer.Cached = true;
                    //
                    // Check we have an existing ClassBreaksRenderer.
                    //
                    if (GeoFeatureLayer.Renderer is IClassBreaksRenderer)
                    {
                        ClassBreaksRenderer = (IClassBreaksRenderer)GeoFeatureLayer.Renderer;
                        //
                        // If successful so far we can go ahead and open the Form. This allows the
                        // user to change the properties of the new RandomColorRamp.
                        //
                        frmAlgoColorRamp.m_lngClasses = ClassBreaksRenderer.BreakCount;
                        frmAlgoColorRamp.ShowDialog();
                        //
                        // Return the selected colors enumeration.
                        pColors = frmAlgoColorRamp.m_enumNewColors;
                        if (pColors == null)
                        {
                            //
                            // User has cancelled the form, or not set a ramp.
                            //
                            //MsgBox("Colors object is empty. Exit Sub")

                            return;
                        }
                        //
                        // Set the new random colors onto the Symbol array of the ClassBreaksRenderer.
                        //
                        pColors.Reset(); // Because you never know if the enumeration has been
                        // iterated before being passed back.

                        int tempFor1 = ClassBreaksRenderer.BreakCount;
                        for (lngCount = 0; lngCount < tempFor1; lngCount++)
                        {
                            //
                            // For each Value in the ClassBreaksRenderer, we clone the existing
                            // Fill symbol (so that all the properties are faithful preserved,
                            // and set its color from our new AlgorithmicColorRamp.
                            //
                            IClone symClone;
                            symClone = (IClone)ClassBreaksRenderer.get_Symbol(lngCount);

                            ClonedSymbol = CloneMe(ref (symClone));
                            //
                            // Now the ClonedSymbol variable holds a copy of the existing
                            // Symbol, we can change the assigned Color. We set the new
                            // symbol onto the Symbol array of the Renderer.          '
                            //
                            HsvColor  = (IHsvColor)pColors.Next();
                            NewSymbol = SetColorOfUnknownSymbol(ClonedSymbol, HsvColor);
                            if (NewSymbol != null)
                            {
                                ClassBreaksRenderer.set_Symbol(lngCount, NewSymbol);
                            }
                        }
                        //
                        // Refresh the table of contents and the changed layer.
                        //
                        ActiveView = (IActiveView)ArcMap.Document.FocusMap;
                        ActiveView.ContentsChanged();
                        ArcMap.Document.UpdateContents();
                        ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, GeoFeatureLayer, null);
                    }
                }
            }
        }
		private ISymbol ApplyColor(ISymbol pSym, IFeature pFeat)
		{
	try
	{
			ISymbol pSym1 = null;
			ISymbol pSym2 = null;
			IColor pColor = null;
			IHsvColor pHSVColor = null;

			if ((m_pColorRend1 != null) & (m_pColorRend2 != null)) // for now both color renderers need to be set to apply color
			{
				pSym1 = m_pColorRend1.get_SymbolByFeature(pFeat);
				pSym2 = m_pColorRend2.get_SymbolByFeature(pFeat);
				// only use GetCombinedColor for HSV component-type combination method
				if (m_eColorCombinationMethod == EColorCombinationType.enuComponents)
				{
					pColor = GetCombinedColor(GetSymbolColor(pSym1), GetSymbolColor(pSym2), m_eColorCombinationMethod);

					
					// Hue is good when I do this...
					pHSVColor = pColor as IHsvColor;
					//'MsgBox(Str(pHSVColor.Hue) & " " & Str(pHSVColor.Saturation) & " " & " " & Str(pHSVColor.Value()))

				}
				else
				{
					
					pColor = new RgbColor();
                    pColor.RGB = (int)m_OLEColorMatrix[GetSymbolIndex(pSym1 as ISymbol, m_pColorRend1 as IClassBreaksRenderer), GetSymbolIndex(pSym2 as ISymbol, m_pColorRend2 as IClassBreaksRenderer)];
					
					
				}


				if (pSym is IMarkerSymbol)
				{
					IMarkerSymbol pMarkerSym = null;
                    pMarkerSym = pSym as IMarkerSymbol;
					pMarkerSym.Color = pColor;
				}
				else if (pSym is ILineSymbol)
				{
					ILineSymbol pLineSym = null;
                    pLineSym = pSym as ILineSymbol;
					pLineSym.Color = pColor;
				}
				else if (pSym != null)
				{
					IFillSymbol pFillSym = null;
					pFillSym = pSym as IFillSymbol;
					pFillSym.Color = pColor;
					

				}


			}

			return pSym;
			return null;
}

catch
{
    return null;
}
		}
		private ESRI.ArcGIS.Display.IColor GetCombinedColor(IColor pColor1, IColor pColor2, EColorCombinationType eCombinationMethod, IColor pOriginColor)
		{
			// combines the input colors based on m_eColorCombinationMethod

			// (11/08/04) -- RGB and enuLabLChColorRamp aren't used by GUI

			IColor pOutColor = null;

			long MyOLE_COLOR = 0; // As OLE_COLOR in VB6
			IRgbColor pMainRGBColor = null;
			IRgbColor pVariationRGBColor = null;
			IRgbColor pMergedRGBColor = null;
			bool bOK = false;
			IAlgorithmicColorRamp pAlgorithmicCR = null;

			// if either of the colors are null, then don't run the color through any algorithm,
			//   instead, just return the other color.  if both are null, then return a null color
			if (pColor1.NullColor)
			{
				pOutColor = pColor2;

			}
			else if (pColor2.NullColor)
			{
				pOutColor = pColor1;

			}
			else if (eCombinationMethod == EColorCombinationType.enuComponents)
			{
				// HSV components
				// create a new HSV color
				IHsvColor pHSVDrawColor = null;
				pHSVDrawColor = new HsvColor();
				// get HSV values from Color1 and Color2 and assign to pHSVDrawColor
				IHsvColor pHSVColor1 = null;
				IHsvColor pHSVColor2 = null;

				// (new 4/27/04) didn't think I had to do this...
				//pHSVColor1 = pColor1
				//pHSVColor2 = pColor2
				pHSVColor1 = new HsvColor();
				pHSVColor1.RGB = pColor1.RGB;
				pHSVColor2 = new HsvColor();
				pHSVColor2.RGB = pColor2.RGB;

				pHSVDrawColor.Hue = pHSVColor1.Hue;
				pHSVDrawColor.Saturation = pHSVColor2.Saturation;
				pHSVDrawColor.Value = pHSVColor2.Value;

				pOutColor = pHSVDrawColor;

			}
			else if (eCombinationMethod == EColorCombinationType.enuRGBAverage)
			{
				// use additive color model to merge the two colors
				MyOLE_COLOR = pColor1.RGB;
				pMainRGBColor = new RgbColor();
				pMainRGBColor.RGB = (int)MyOLE_COLOR;
				MyOLE_COLOR = pColor2.RGB;
				pVariationRGBColor = new RgbColor();
				pVariationRGBColor.RGB = (int)MyOLE_COLOR;
				// merged color = RGB average of the two colors
				pMergedRGBColor = new RgbColor();
				pMergedRGBColor.Red = (pMainRGBColor.Red + pVariationRGBColor.Red) / 2;
				pMergedRGBColor.Green = (pMainRGBColor.Green + pVariationRGBColor.Green) / 2;
				pMergedRGBColor.Blue = (pMainRGBColor.Blue + pVariationRGBColor.Blue) / 2;

				pOutColor = pMergedRGBColor;
			}
			else if ((eCombinationMethod == EColorCombinationType.enuCIELabColorRamp) | (eCombinationMethod == EColorCombinationType.enuLabLChColorRamp))
			{
				// use color ramp and take central color between the two colors
				pAlgorithmicCR = new AlgorithmicColorRamp();
				if (m_eColorCombinationMethod == EColorCombinationType.enuCIELabColorRamp)
					pAlgorithmicCR.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
				else
					pAlgorithmicCR.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm;
				pAlgorithmicCR.Size = 3;
				pAlgorithmicCR.FromColor = pColor1;
				pAlgorithmicCR.ToColor = pColor2;
				pAlgorithmicCR.CreateRamp(out bOK);

				pOutColor = pAlgorithmicCR.get_Color(1); // middle color in ramp
			}
			else // EColorCombinationType.enuCIELabMatrix
			{

				double[] iLab1 = new double[4]; // L, a, b values for Color1
				double[] iLab2 = new double[4]; // L, a, b values for Color2
				double[] iLabOrig = new double[4]; // L, a, b values for pOriginColor
				pColor1.GetCIELAB(out iLab1[0], out iLab1[1], out iLab1[2]);
				pColor2.GetCIELAB(out iLab2[0], out iLab2[1], out iLab2[2]);
				pOriginColor.GetCIELAB(out iLabOrig[0], out iLabOrig[1], out iLabOrig[2]);

				double[] iLabOut = new double[4];
				// add color1 vector and color2 vector, then subtract the origin color vector
				iLabOut[0] = iLab1[0] + iLab2[0] - iLabOrig[0];
				iLabOut[1] = iLab1[1] + iLab2[1] - iLabOrig[1];
				iLabOut[2] = iLab1[2] + iLab2[2] - iLabOrig[2];

				CorrectLabOutofRange(ref iLabOut[0], ref iLabOut[1], ref iLabOut[2]);

				IHsvColor pHSVColor = null;
				pHSVColor = new HsvColor();
				pHSVColor.SetCIELAB(iLabOut[0], iLabOut[1], iLabOut[2]);
				pOutColor = pHSVColor;
			}

			return pOutColor;

		}