コード例 #1
0
        private void styleGipodLyr(IGeoFeatureLayer geolayer)
        {
            IUniqueValueRenderer renderer = new UniqueValueRendererClass();

            renderer.FieldCount = 1;
            renderer.set_Field(0, "hinder");
            renderer.set_FieldType(0, false);
            //renderer.UseDefaultSymbol = true;
            renderer.DefaultLabel = "other";

            ISimpleMarkerSymbol trueMarkerSymbol = new SimpleMarkerSymbolClass();

            trueMarkerSymbol.Color = new RgbColorClass()
            {
                Red = 255, Blue = 0, Green = 255
            };
            trueMarkerSymbol.Outline      = true;
            trueMarkerSymbol.OutlineColor = new RgbColorClass()
            {
                Red = 0, Blue = 0, Green = 0
            };;
            trueMarkerSymbol.Size  = 5;
            trueMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;

            ISimpleMarkerSymbol falseMarkerSymbol = new SimpleMarkerSymbolClass();

            falseMarkerSymbol.Color = new RgbColorClass()
            {
                Red = 255, Blue = 0, Green = 0
            };
            falseMarkerSymbol.Outline      = true;
            falseMarkerSymbol.OutlineColor = new RgbColorClass()
            {
                Red = 0, Blue = 0, Green = 0
            };;
            falseMarkerSymbol.Size  = 5;
            falseMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;

            renderer.AddValue("0", "", falseMarkerSymbol as ISymbol);
            renderer.set_Label("0", "Geen hinder");
            renderer.AddValue("1", "", trueMarkerSymbol as ISymbol);
            renderer.set_Label("1", "Veel hinder");

            geolayer.Renderer = renderer as IFeatureRenderer;

            IMxDocument mxDoc = ArcMap.Document;

            mxDoc.CurrentContentsView.Refresh(null);
        }
コード例 #2
0
        private void RenderByUniqueValue(IFeatureLayer featureLayer, string fieldName)
        {
            string[] uniqueValues = GetUniqueValues(featureLayer, fieldName);

            if (uniqueValues != null)
            {
                IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRendererClass();

                uniqueValueRenderer.FieldCount = 1;

                uniqueValueRenderer.Field[0] = fieldName;

                IFeatureClass featureClass = featureLayer.FeatureClass;

                int n = featureClass.FindField(fieldName);

                IField field = featureClass.Fields.Field[n];

                if (field.Type == esriFieldType.esriFieldTypeString)
                {
                    // 如果实际字段值类型是字符串型

                    // 则 UniqueValueRenderer 组件对象的字段类型设置为 true

                    uniqueValueRenderer.set_FieldType(0, true);
                }
                else
                {
                    uniqueValueRenderer.set_FieldType(0, false);
                }

                IRandomColorRamp randomColorRamp = new RandomColorRampClass();

                randomColorRamp.StartHue = 30;

                randomColorRamp.EndHue = 50;

                randomColorRamp.MinSaturation = 20;

                randomColorRamp.MaxSaturation = 40;

                randomColorRamp.MinValue = 0;

                randomColorRamp.MaxValue = 100;

                randomColorRamp.Size = uniqueValues.Length;

                bool b;

                randomColorRamp.CreateRamp(out b);

                if (b)
                {
                    for (int i = 0; i < uniqueValues.Length; i++)
                    {
                        ISymbol symbol = null;

                        if (featureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                        {
                            symbol = new SimpleFillSymbolClass();

                            (symbol as IFillSymbol).Outline.Width = 1.0;

                            (symbol as IFillSymbol).Color = randomColorRamp.get_Color(i);

                            uniqueValueRenderer.AddValue(uniqueValues[i], uniqueValues[i], symbol);
                        }
                        else if (featureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                        {
                            symbol = new SimpleLineSymbolClass();

                            (symbol as ILineSymbol).Width = 1.0;

                            (symbol as ILineSymbol).Color = randomColorRamp.get_Color(i);

                            uniqueValueRenderer.AddValue(uniqueValues[i], uniqueValues[i], symbol);
                        }
                    }
                }
                IGeoFeatureLayer geoFeatureLayer = featureLayer as IGeoFeatureLayer;

                if (geoFeatureLayer != null)
                {
                    geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer;

                    IActiveView activeView = axMapControl1.ActiveView;

                    activeView.ContentsChanged();

                    activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                }
            }
        }
コード例 #3
0
ファイル: gipodForm.cs プロジェクト: geopunt/geopunt4arcgis
        private void styleGipodLyr( IGeoFeatureLayer geolayer )
        {
            IUniqueValueRenderer renderer = new UniqueValueRendererClass();
            renderer.FieldCount = 1;
            renderer.set_Field(0, "hinder");
            renderer.set_FieldType(0, false);
            //renderer.UseDefaultSymbol = true;
            renderer.DefaultLabel = "other";

            ISimpleMarkerSymbol trueMarkerSymbol = new SimpleMarkerSymbolClass();
            trueMarkerSymbol.Color = new RgbColorClass(){Red= 255, Blue= 0, Green= 255 };
            trueMarkerSymbol.Outline = true;
            trueMarkerSymbol.OutlineColor = new RgbColorClass() { Red = 0, Blue = 0, Green = 0 }; ;
            trueMarkerSymbol.Size = 5;
            trueMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;

            ISimpleMarkerSymbol falseMarkerSymbol = new SimpleMarkerSymbolClass();
            falseMarkerSymbol.Color = new RgbColorClass() { Red = 255, Blue = 0, Green = 0 };
            falseMarkerSymbol.Outline = true;
            falseMarkerSymbol.OutlineColor = new RgbColorClass() { Red = 0, Blue = 0, Green = 0 }; ;
            falseMarkerSymbol.Size = 5;
            falseMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;

            renderer.AddValue("0","", falseMarkerSymbol as ISymbol);
            renderer.set_Label("0", "Geen hinder");
            renderer.AddValue("1", "", trueMarkerSymbol as ISymbol);
            renderer.set_Label("1", "Veel hinder");

            geolayer.Renderer = renderer as IFeatureRenderer;

            IMxDocument mxDoc = ArcMap.Document;
            mxDoc.CurrentContentsView.Refresh(null);
        }
コード例 #4
0
        public static void DefineUniqueValueRenderer(IGeoFeatureLayer geoFealyr,string fieldName)
        {
            // Create color ramp for the symbol in rendere
            IRandomColorRamp randomColorRamp = new RandomColorRampClass();
            randomColorRamp.MinSaturation = 20;
            randomColorRamp.MaxSaturation = 40;
            randomColorRamp.MinValue = 85;
            randomColorRamp.MaxValue = 100;
            randomColorRamp.StartHue = 76;
            randomColorRamp.EndHue = 188;
            randomColorRamp.UseSeed = true;
            randomColorRamp.Seed = 43;
            // Create a symbol
            ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
            simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
            simpleFillSymbol.Outline.Width = 0.4;
            // Create the renderer
            IUniqueValueRenderer uniqueValueRender = new UniqueValueRendererClass();
            uniqueValueRender.FieldCount = 1;
            uniqueValueRender.set_Field(0, fieldName);
            uniqueValueRender.DefaultSymbol = simpleFillSymbol as ISymbol;
            uniqueValueRender.UseDefaultSymbol = true;

            IDisplayTable displayTable = geoFealyr as IDisplayTable;
            IFeatureCursor feacursor = displayTable.SearchDisplayTable(null, false) as IFeatureCursor;
            IFeature fea = feacursor.NextFeature();

            bool valfound;
            int fieldIndex;

            IFields fields = feacursor.Fields;
            fieldIndex = fields.FindField(fieldName);
            while(fea!=null)
            {
                ISimpleFillSymbol classSymbol = new SimpleFillSymbolClass();
                classSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                classSymbol.Outline.Width = 0.4;

                string classValue;
                classValue = fea.get_Value(fieldIndex) as string;

                valfound = false;
                for(int i=0;i<=uniqueValueRender.ValueCount-1;i++)
                {
                    if(uniqueValueRender.get_Value(i)==classValue)
                    {
                        valfound = true;
                        break;
                    }
                }
                if(valfound==false)
                {
                    uniqueValueRender.AddValue(classValue, fieldName, classSymbol as ISymbol);
                    uniqueValueRender.set_Label(classValue, classValue);
                    uniqueValueRender.set_Symbol(classValue, classSymbol as ISymbol);
                }

                fea = feacursor.NextFeature();
            }

            System.Runtime.InteropServices.Marshal.ReleaseComObject(feacursor);

            randomColorRamp.Size = uniqueValueRender.ValueCount;
            bool bOK;
            randomColorRamp.CreateRamp(out bOK);

            IEnumColors enumColors = randomColorRamp.Colors;
            enumColors.Reset();
            for(int j=0;j<=uniqueValueRender.ValueCount-1;j++)
            {
                string xv;
                xv = uniqueValueRender.get_Value(j);
                if(xv!="")
                {
                    ISimpleFillSymbol simplefs = uniqueValueRender.get_Symbol(xv) as ISimpleFillSymbol;
                    simplefs.Color = enumColors.Next();
                    uniqueValueRender.set_Symbol(xv, simplefs as ISymbol);
                }
            }

            uniqueValueRender.ColorScheme = "Custome";
            ITable tbl = displayTable as ITable;
            bool isString = tbl.Fields.get_Field(fieldIndex).Type == esriFieldType.esriFieldTypeString;
            uniqueValueRender.set_FieldType(0, isString);

            geoFealyr.Renderer = uniqueValueRender as IFeatureRenderer;

            IUID uid = new UIDClass();
            uid.Value = "{25AE5C2F-0B57-41C6-A492-31352BAD3A37}";
            geoFealyr.RendererPropertyPageClassID = uid as UIDClass;
        }
コード例 #5
0
        /// <summary>
        /// Returns Simple Renderer if no values can be found
        /// </summary>
        /// <param name="renderContainer"></param>
        /// <returns></returns>
        public static IFeatureRenderer NewUniqueValueRenderer(RendererContainer renderContainer)
        {
            BiPolarRendererContainer biPolarRendererContainer = renderContainer.BiPolarRendererContainer;

            IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRendererClass();

            ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();

            simpleFillSymbol.Style         = esriSimpleFillStyle.esriSFSSolid;
            simpleFillSymbol.Outline.Width = 0.4;

            var fieldName = biPolarRendererContainer.Field.Name;

            uniqueValueRenderer.FieldCount = 1;
            uniqueValueRenderer.Field[0]   = fieldName;

            int fieldIndex;

            ISet <double> setOfFeatures       = new HashSet <double>();
            var           containsDbNullValue = false;

            using (var comReleaser = new ComReleaser())
            {
                var featureCursor = renderContainer.Field.Feature.FeatureClass.Search(null, true);

                comReleaser.ManageLifetime(featureCursor);

                fieldIndex = featureCursor.Fields.FindField(fieldName);

                IFeature currentFeature;

                while ((currentFeature = featureCursor.NextFeature()) != null)
                {
                    var value = currentFeature.Value[fieldIndex];

                    if (Convert.IsDBNull(value))
                    {
                        containsDbNullValue = true;
                        continue;
                    }
                    //TODO datetime is possible???
                    setOfFeatures.Add(Convert.ToDouble(value));
                }
            }

            if (containsDbNullValue && setOfFeatures.Count == 0)
            {
                return(NewAllMissingValuesRenderer());
            }

            if (setOfFeatures.Count == 0)
            {
                return(NewSimpleRenderer());
            }

            IEnumerable <double> orderedSet = setOfFeatures.OrderBy(d => d);

            foreach (var currentClassValue in orderedSet)
            {
                ISimpleFillSymbol pClassSymbol = new SimpleFillSymbolClass();
                pClassSymbol.Style         = esriSimpleFillStyle.esriSFSSolid;
                pClassSymbol.Outline.Width = 0.4;

                // the format is important, because the normal to string will represent the power as E-05 or something like that
                // the result are mismatches between the renderer value and the column value
                //string classValue = currentClassValue.ToString("N20"); does not really work

                var dirtyTrick = (decimal)currentClassValue;

                var classValue = dirtyTrick.ToString();

                uniqueValueRenderer.AddValue(classValue, fieldName, (ISymbol)pClassSymbol);
                uniqueValueRenderer.set_Label(classValue, classValue);
                uniqueValueRenderer.set_Symbol(classValue, (ISymbol)pClassSymbol);
            }

            //figure out how many colors belong to which side from the neutral color
            var size = uniqueValueRenderer.ValueCount;

            var left  = (int)(size * biPolarRendererContainer.NeutralColorPosition);
            var right = size - left;

            // for the case one or both are zero -> create color ramp crashes, the magic value seems to be 2
            if (left < 2)
            {
                left = 2;
            }

            if (right < 2)
            {
                right = 2;
            }

            IAlgorithmicColorRamp firstColorRamp = new AlgorithmicColorRampClass();

            firstColorRamp.FromColor = ToColor(biPolarRendererContainer.NegativColor);
            firstColorRamp.ToColor   = ToColor(biPolarRendererContainer.NeutralColor);

            firstColorRamp.Size = left;
            bool bOk;

            IAlgorithmicColorRamp secondColorRamp = new AlgorithmicColorRampClass();

            secondColorRamp.FromColor = ToColor(biPolarRendererContainer.NeutralColor);
            secondColorRamp.ToColor   = ToColor(biPolarRendererContainer.PositivColor);

            secondColorRamp.Size = right;

            firstColorRamp.CreateRamp(out bOk);
            secondColorRamp.CreateRamp(out bOk);

            var firstEnumColors  = firstColorRamp.Colors;
            var secondEnumColors = secondColorRamp.Colors;

            firstEnumColors.Reset();
            secondEnumColors.Reset();

            for (var j = 0; j <= uniqueValueRenderer.ValueCount - 1; j++)
            {
                var label = uniqueValueRenderer.Value[j];

                var pSimpleFillColor = (ISimpleFillSymbol)uniqueValueRenderer.Symbol[label];

                var color = firstEnumColors.Next();

                //in case the first half colors is "empty" change to the second
                if (color == null)
                {
                    firstEnumColors = secondEnumColors;
                    color           = firstEnumColors.Next();
                }

                pSimpleFillColor.Color = color;

                uniqueValueRenderer.set_Symbol(label, (ISymbol)pSimpleFillColor);
            }

            //'** If you didn'toolParameter use a predefined color ramp
            //'** in a style, use "Custom" here. Otherwise,
            //'** use the name of the color ramp you selected.
            uniqueValueRenderer.ColorScheme = "Custom";
            ////ITable pTable = pDisplayTable as ITable;
            bool isString = renderContainer.Field.Feature.FeatureClass.Fields.Field[fieldIndex].Type == esriFieldType.esriFieldTypeString;

            //uniqueValueRenderer.FieldType[0] = isString;
            uniqueValueRenderer.set_FieldType(0, isString);
            //TODO geoFeatureLayer
            var geoFeatureLayer = renderContainer.Field.Feature.FeatureLayer as IGeoFeatureLayer;

            geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer;

            return((IFeatureRenderer)uniqueValueRenderer);
        }
コード例 #6
0
        public static void DefineUniqueValueRenderer(IGeoFeatureLayer pGeoFeatureLayer, string fieldName)
        {
            IRandomColorRamp pRandomColorRamp = new RandomColorRampClass();

            //Create the color ramp for the symbols in the renderer.
            pRandomColorRamp.MinSaturation = 20;
            pRandomColorRamp.MaxSaturation = 40;
            pRandomColorRamp.MinValue      = 85;
            pRandomColorRamp.MaxValue      = 100;
            pRandomColorRamp.StartHue      = 76;
            pRandomColorRamp.EndHue        = 188;
            pRandomColorRamp.UseSeed       = true;
            pRandomColorRamp.Seed          = 43;

            //Create the renderer.
            IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();

            ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();

            pSimpleFillSymbol.Style         = esriSimpleFillStyle.esriSFSSolid;
            pSimpleFillSymbol.Outline.Width = 0.4;

            //These properties should be set prior to adding values.
            pUniqueValueRenderer.FieldCount = 1;
            pUniqueValueRenderer.set_Field(0, fieldName);
            pUniqueValueRenderer.DefaultSymbol    = pSimpleFillSymbol as ISymbol;
            pUniqueValueRenderer.UseDefaultSymbol = true;

            IDisplayTable  pDisplayTable  = pGeoFeatureLayer as IDisplayTable;
            IFeatureCursor pFeatureCursor = pDisplayTable.SearchDisplayTable(null, false) as IFeatureCursor;
            IFeature       pFeature       = pFeatureCursor.NextFeature();


            bool ValFound;
            int  fieldIndex;

            IFields pFields = pFeatureCursor.Fields;

            fieldIndex = pFields.FindField(fieldName);
            while (pFeature != null)
            {
                ISimpleFillSymbol pClassSymbol = new SimpleFillSymbolClass();
                pClassSymbol.Style         = esriSimpleFillStyle.esriSFSSolid;
                pClassSymbol.Outline.Width = 0.4;

                string classValue;
                classValue = pFeature.get_Value(fieldIndex) as string;

                //Test to see if this value was added to the renderer. If not, add it.
                ValFound = false;
                for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++)
                {
                    if (pUniqueValueRenderer.get_Value(i) == classValue)
                    {
                        ValFound = true;
                        break; //Exit the loop if the value was found.
                    }
                }
                //If the value was not found, it's new and will be added.
                if (ValFound == false)
                {
                    pUniqueValueRenderer.AddValue(classValue, fieldName, pClassSymbol as
                                                  ISymbol);
                    pUniqueValueRenderer.set_Label(classValue, classValue);
                    pUniqueValueRenderer.set_Symbol(classValue, pClassSymbol as ISymbol);
                }
                pFeature = pFeatureCursor.NextFeature();
            }
            //Since the number of unique values is known, the color ramp can be sized and the colors assigned.
            pRandomColorRamp.Size = pUniqueValueRenderer.ValueCount;
            bool bOK;

            pRandomColorRamp.CreateRamp(out bOK);

            IEnumColors pEnumColors = pRandomColorRamp.Colors;

            pEnumColors.Reset();
            for (int j = 0; j <= pUniqueValueRenderer.ValueCount - 1; j++)
            {
                string xv;
                xv = pUniqueValueRenderer.get_Value(j);
                if (xv != "")
                {
                    ISimpleFillSymbol pSimpleFillColor = pUniqueValueRenderer.get_Symbol(xv)
                                                         as ISimpleFillSymbol;
                    pSimpleFillColor.Color = pEnumColors.Next();
                    pUniqueValueRenderer.set_Symbol(xv, pSimpleFillColor as ISymbol);
                }
            }

            //'** If you didn't use a predefined color ramp in a style, use "Custom" here.
            //'** Otherwise, use the name of the color ramp you selected.

            pUniqueValueRenderer.ColorScheme = pRandomColorRamp.Name;//"Custom";

            ITable pTable   = pDisplayTable as ITable;
            bool   isString = pTable.Fields.get_Field(fieldIndex).Type ==
                              esriFieldType.esriFieldTypeString;

            pUniqueValueRenderer.set_FieldType(0, isString);
            pGeoFeatureLayer.Renderer = pUniqueValueRenderer as IFeatureRenderer;

            //This makes the layer properties symbology tab show the correct interface.
            IUID pUID = new UIDClass();

            pUID.Value = "{683C994E-A17B-11D1-8816-080009EC732A}";
            pGeoFeatureLayer.RendererPropertyPageClassID = pUID as UIDClass;
        }