zhousky
论坛版主
论坛版主
  • 注册日期2003-08-01
  • 发帖数281
  • QQ
  • 铜币1027枚
  • 威望3点
  • 贡献值0点
  • 银元0个
阅读:1467回复:1

在AO中怎么来设置一个图层的symbol

楼主#
更多 发布于:2004-08-16 15:48
我已经修改了点图层的样式,可是怎么把这个isymbol接口传给这个图层呢,一直没有找到?  请高手指教
喜欢0 评分0
不要看我噢
destnity
路人甲
路人甲
  • 注册日期2004-03-25
  • 发帖数341
  • QQ
  • 铜币272枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2004-08-16 17:30
<P>Samples  </P><P>Custom Simple Renderer
Language
Java</P><P>VB6</P><P>Show All
Description:</P><P>This sample demonstrates how to create a custom renderer and use it in ArcMap. The renderer draws symbology for point, line and polygon feature layers, rendering all features with the same symbol. This sample expands on the First Custom Renderer sample by demonstrating how to implement ISimpleRenderer and ILegendInfo. Implementing ISimpleRenderer lets you assign a symbol to the renderer before drawing and makes the renderer compatible with the single symbol property page. Implementing ILegendInfo makes the rendered layer compatible with the TOC. Products:
ArcView: VB6</P><P>Engine: Java</P><P>
Platforms: Windows</P><P>Requires: For VB Usage: An ArcMap session with at least one layer added.</P><P>Minimum ArcGIS Release: 9.0
 </P><P>How to use:
[VB6]
Add a point, line, or polygon feature layer to the map.
In the Visual Basic Editor, go to Tools > References. If this sample's dll (CustomSimpleRenderer) does not appear in the Available References box, Browse to the dll and add it. Check the box next to the dll's name. Dismiss the References dialog.
Copy-paste the following VBA code into a code module and run it.
Public Sub TestRenderer()
' this VBA macro demonstrates using CustomSimpleRenderer.CustomSimpleRend
' run this macro with at least one feature layer of points, lines, or polygons in the active dataframe
' the macro creates a symbol depending on feature type and the draws the
' first featurelayer in the dataframe using this symbol</P><P>On Error GoTo ErrHand
  
  Dim pApp As IMxApplication
  Set pApp = Application
  Dim pDoc As IMxDocument
  Set pDoc = ThisDocument
  Dim pMap As IMap
  Set pMap = pDoc.ActiveView.FocusMap</P><P>  Dim pFeatLyr As IFeatureLayer
  Dim i As Long
  ' run through the layers and get the first featurelayer
  For i = 0 To pMap.LayerCount - 1
    If TypeOf pMap.Layer(i) Is IFeatureLayer Then
      Set pFeatLyr = pMap.Layer(i)
      Exit For
    End If
  Next i
  
' --------------------------------------------------
' symbol setup
  
  ' this macro will handle feature symbology according to the following rules:
  '     if we have point features, then use a marker symbol for rendering
  '     else, if we have line features, then use a line symbol
  '     else, if we have polygon features, then use a fill symbol
  '     else, (we don't have any of these feature types) so do not assign renderer to layer
    
  Dim pColor As IRgbColor
  Set pColor = New RgbColor
  ' use red. it's a good color
  pColor.RGB = vbRed
  
  Dim pSym As ISymbol
    
  ' based on feature type, make proper symbol, then assign to pSym
  Select Case pFeatLyr.FeatureClass.ShapeType
    Case esriGeometryPoint     ' set up a marker symbol
        Dim pMarkerSym As ISimpleMarkerSymbol
        Set pMarkerSym = New SimpleMarkerSymbol
        With pMarkerSym
            .Size = 12
            .Color = pColor
            .Style = esriSMSX
        End With
        Set pSym = pMarkerSym
  
    Case esriGeometryPolyline    ' set up a line symbol
        Dim pLineSymbol As ISimpleLineSymbol
        Set pLineSymbol = New SimpleLineSymbol
        With pLineSymbol
            .Width = 1
            .Color = pColor
            .Style = esriSLSDashDotDot
        End With
        Set pSym = pLineSymbol
 
    Case esriGeometryPolygon    ' setup a fill symbol
        Dim pFillSymbol As ISimpleFillSymbol
        Set pFillSymbol = New SimpleFillSymbol
        With pFillSymbol
            .Color = pColor
            .Style = esriSFSBackwardDiagonal
        End With
        Set pSym = pFillSymbol
  
    Case Else
        MsgBox "Invalid feature type"
        GoTo EndProc
  
  End Select
' --------------------------------------------------
    
  ' create a new CustomSimpleRend
  Dim pRend As IFeatureRenderer
  Set pRend = New CustomSimpleRenderer.CustomSimpleRend
  
  ' set symbol.  we must use ISimpleRenderer interface
  Dim pSimpleRend As ISimpleRenderer
  Set pSimpleRend = pRend
  Set pSimpleRend.Symbol = pSym
  
  Dim pGeoFL As IGeoFeatureLayer
  Set pGeoFL = pFeatLyr
  
  ' finally, set the new renderer to the layer and refresh the map
  Set pGeoFL.Renderer = pRend
  pDoc.ActiveView.Refresh
  pDoc.UpdateContents</P><P>  GoTo EndProc</P><P>ErrHand:
    MsgBox "TestRenderer " ; Err.Description
EndProc:
    ' set all variables to nothing
    Set pApp = Nothing
    Set pDoc = Nothing
    Set pMap = Nothing
    Set pFeatLyr = Nothing
    Set pColor = Nothing
    Set pSym = Nothing
    Set pMarkerSym = Nothing
    Set pLineSymbol = Nothing
    Set pFillSymbol = Nothing
    Set pRend = Nothing
    Set pSimpleRend = Nothing
    Set pGeoFL = Nothing
    Exit Sub
End Sub
You should see that the default renderer for the first feature layer in the map gets replaced by CustomSimpleRend.
Save the ArcMap document as "CustomSimpleRenderer.mxd". Exit ArcMap.
Start ArcMap again and open "CustomSimpleRenderer.mxd" file. You should see that the layer is still drawng with your the symbol assigned by CustomSimpleRend.
You can change the symbology of the rendered layer by double clicking on the name of the layer and browsing to the Symbology tab.
The symbology can also be changed directly through the layer's entry in the Table of Contents (TOC). Right click on the symbol to change it's color. Double click to change other properties, or to select a different symbol.
The TOC entry will also display on any legend that includes the layer</P>
签 名: 不能超过 250 个字符 文字将出现在您发表的文章的结尾处。
举报 回复(0) 喜欢(0)     评分
游客

返回顶部