阅读:1931回复:1
单值专题图总是一种颜色
我在做单值专题图时,明明已经为Renderer设置了不同的颜色,但是结果却总是一种颜色。代码如下:<br>
<br> //打开影响场要素类<br> IFeatureClass pFcYxc = pFeatureWorkspace.OpenFeatureClass("YXC");<br> //打开影响场图层<br> IFeatureLayer pFl = (IFeatureLayer)axMapControl1.Map.get_Layer(1);<br> <br> //创建并设置随机色谱<br> IRandomColorRamp rx = new RandomColorRampClass();<br> rx.MinSaturation = 15;<br> rx.MaxSaturation = 30;<br> rx.MinValue = 85;<br> rx.MaxValue = 100;<br> rx.StartHue = 0;<br> rx.EndHue = 360;<br> rx.UseSeed = true;<br> rx.Seed = 43;<br> <br> //创建填充符号<br> ISimpleFillSymbol symx = new SimpleFillSymbolClass();<br> <br> //单值专题图<br> IUniqueValueRenderer pRender = new UniqueValueRendererClass();<br> pRender.FieldCount = 1;<br> pRender.set_Field(0, "LD");<br> pRender.DefaultSymbol = (ISymbol)symx;<br> pRender.UseDefaultSymbol = true;<br> <br> //为每个值设置一个符号<br> int n = pFcYxc.FeatureCount(null);<br> IFeatureCursor pFCur = pFcYxc.Search(null, false);<br> for (int i = 0; i < n; i++)<br> {<br> IFeature pFeat = pFCur.NextFeature();<br> string pFeatValue = pFeat.get_Value(pFeat.Fields.FindField("LD")).ToString();<br> pRender.AddValue(pFeatValue, "烈度", (ISymbol)symx);<br> }<br> <br> rx.Size = pRender.ValueCount;<br> bool ok = true;<br> rx.CreateRamp(out ok);<br> IEnumColors RColors = rx.Colors;<br> RColors.Reset();<br> <br> //为每个符号设置颜色<br> for (int i = 0; i <= pRender.ValueCount - 1; i++)<br> {<br> string xv = pRender.get_Value(i);<br> if (xv != "")<br> {<br> ISimpleFillSymbol jsy = (ISimpleFillSymbol)pRender.get_Symbol(xv);<br> jsy.Color = RColors.Next();<br> pRender.set_Symbol(xv, (ISymbol)jsy); <br> //---------------------------------------------------------------------------<br> //在这里设置断点,每一轮循环中jsy.Color的值不相同。<br> //---------------------------------------------------------------------------<br> }<br> }<br> <br> //设置到图层<br> IGeoFeatureLayer pGeoFl = (IGeoFeatureLayer)pFl;<br> pGeoFl.Renderer = (IFeatureRenderer)pRender;<br> pGeoFl.DisplayField = "LD";<br> <br> //刷新<br> axMapControl1.Refresh(esriViewDrawPhase.esriViewGraphics, axMapControl1.Map.get_Layer(1), Type.Missing);<br> axMapControl1.Refresh();<br> axTOCControl1.Update(); |
|
1楼#
发布于:2007-10-23 14:36
<PRE>Sub MyUVR(theField As String)
'assistance from Michael Knight, from ESRI developers network forum. Dim pMxDoc As IMxDocument Set pMxDoc = Application.Document Dim pMap As IMap Set pMap = pMxDoc.FocusMap 'create renderer Dim pUVR As IUniqueValueRenderer Set pUVR = New UniqueValueRenderer pUVR.FieldCount = 1 pUVR.Field(0) = theField '"Code" pUVR.DefaultLabel = "No Value" 'create default symbol Dim color As IColor Set color = CreateColor(255, 255, 0) Dim defaultMarker As ISimpleMarkerSymbol Set defaultMarker = CreateSimpleMarkerSymbol(color, esriSMSSquare, 10) 'add default symbol to renderer pUVR.DefaultSymbol = defaultMarker pUVR.UseDefaultSymbol = True Dim pStyleStorage As IStyleGalleryStorage Dim pStyleGallery As IStyleGallery Dim pStyleClass As IStyleGalleryClass Set pStyleGallery = pMxDoc.StyleGallery Set pStyleStorage = pStyleGallery Dim pEnumStyleGall As IEnumStyleGalleryItem Dim pStyleItem As IStyleGalleryItem Dim pMarkerSym As IMarkerSymbol 'Initialize the style gallery Set pEnumStyleGall = pStyleGallery.Items("Marker Symbols", "Business.style", "Default") pEnumStyleGall.Reset Set pStyleItem = pEnumStyleGall.Next 'I had to had the symbols in this order, which is the order they appear in the 'style page. 'If I tried to add them in a different order, they wouldn't all get added. 'Maybe this has something to do with reseting the symbol gallery? 'I couldn't figure it out, but this works for me. 'symbol 1 - up arrow Do While Not pStyleItem Is Nothing 'Loop through and access each marker If pStyleItem.Name = "Arrow Up" Then Set pMarkerSym = pStyleItem.Item pMarkerSym.color = CreateColor(255, 0, 0) Exit Do End If Set pStyleItem = pEnumStyleGall.Next Loop Dim symbol As IMarkerSymbol Set symbol = pMarkerSym pUVR.AddValue "3", "Rising", symbol 'symbol 2 - down arrow, green Do While Not pStyleItem Is Nothing 'Loop through and access each marker If pStyleItem.Name = "Arrow Down" Then Set pMarkerSym = pStyleItem.Item pMarkerSym.color = CreateColor(0, 255, 0) Exit Do End If Set pStyleItem = pEnumStyleGall.Next Loop Set symbol = pMarkerSym pUVR.AddValue "1", "Falling", symbol 'symbol 3 - right arrow, black Do While Not pStyleItem Is Nothing 'Loop through and access each marker If pStyleItem.Name = "Arrow Right" Then Set pMarkerSym = pStyleItem.Item pMarkerSym.color = CreateColor(0, 0, 0) Exit Do End If Set pStyleItem = pEnumStyleGall.Next Loop Set symbol = pMarkerSym pUVR.AddValue "2", "Neutral", symbol 'add renderer to layer Dim pLayer As ILayer 'Set pLayer = pMap.Layer(0) Set pLayer = GetLayerByName(pMxDoc, "FF_WLCh") 'pMxDoc.FocusMap.Layer(0) Dim pGeoFeatureLayer As IGeoFeatureLayer Set pGeoFeatureLayer = pLayer Set pGeoFeatureLayer.Renderer = pUVR 'This makes the layer properties symbology tab show 'show the correct interface. Dim hx As IRendererPropertyPage Set hx = New UniqueValuePropertyPage pGeoFeatureLayer.RendererPropertyPageClassID = hx.ClassID 'Refresh the TOC pMxDoc.ActiveView.ContentsChanged pMxDoc.UpdateContents 'Draw the map pMxDoc.ActiveView.Refresh End Sub </PRE> |
|
|