VB.Net - ArcGIS 10: ISimpleMarkerSymbol and IStyleGalleryItem

447
3
09-04-2013 03:11 AM
New Contributor
Dear all:

I would like to asign different marker symbols to an unique value renderer. But at the line "pMarkerSymbol1 = pStyleGalleryItem.Item" in the Do while ... Loop it gives me an error.

I have to use the ISimpleMarkerSymbol because I have to change the Outline.

Thanks for your help.
Anika

   Sub prueba()

        Dim pBlack As IColor
        pBlack = New RgbColor
        pBlack.RGB = RGB(0, 0, 0)

        Dim pMarkerSymbol1 As ISimpleMarkerSymbol = New SimpleMarkerSymbol
        Dim pMarkerSymbol2 As ISimpleMarkerSymbol = New SimpleMarkerSymbol
        Dim pMarkerSymbol3 As ISimpleMarkerSymbol = New SimpleMarkerSymbol
        Dim pMarkerSymbol4 As ISimpleMarkerSymbol = New SimpleMarkerSymbol

        Dim pMxDoc As IMxDocument
        Dim pMap As IMap
        Dim pFLayer As IFeatureLayer

        pMxDoc = My.ArcMap.Document
        pMap = pMxDoc.FocusMap
        pFLayer = pMap.Layer(0)

        Dim pMxApp As IMxApplication
        Dim pGeoFLayer As IGeoFeatureLayer
        Dim pSDisplay As IScreenDisplay

        pMxApp = My.ThisApplication
        pGeoFLayer = pFLayer
        pSDisplay = pMxApp.Display
        Dim pSRenderer As ISimpleRenderer

        pSRenderer = New SimpleRenderer
        Dim pStyleGallery As IStyleGallery
        pStyleGallery = pMxDoc.StyleGallery
        'Dim pStyleGalleryClass As IStyleGalleryClass
        Dim pEnumStyGall As IEnumStyleGalleryItem

        Dim pStyleGalleryItem As IStyleGalleryItem
        pEnumStyGall = pStyleGallery.Items("marker symbols", "ESRI.Style", "")
        pEnumStyGall.Reset()
        pStyleGalleryItem = pEnumStyGall.Next



        Do While Not pStyleGalleryItem Is Nothing
            If pStyleGalleryItem.Name = "Simple Circle 1" Then
                pMarkerSymbol1 = pStyleGalleryItem.Item
                Debug.Print(pStyleGalleryItem.Name)
                Exit Do
            End If
            pStyleGalleryItem = pEnumStyGall.Next
        Loop


        Do While Not pStyleGalleryItem Is Nothing
            If pStyleGalleryItem.Name = "Circle 4" Then
                pMarkerSymbol2 = pStyleGalleryItem.Item
                Debug.Print(pStyleGalleryItem.Name)
                Exit Do
            End If
            pStyleGalleryItem = pEnumStyGall.Next
        Loop


        Do While Not pStyleGalleryItem Is Nothing
            If pStyleGalleryItem.Name = "Square 6" Then
                pMarkerSymbol3 = pStyleGalleryItem.Item
                Debug.Print(pStyleGalleryItem.Name)
                Exit Do
            End If
            pStyleGalleryItem = pEnumStyGall.Next
        Loop


        Do While Not pStyleGalleryItem Is Nothing
            If pStyleGalleryItem.Name = "Triangle 4" Then
                pMarkerSymbol4 = pStyleGalleryItem.Item
                Debug.Print(pStyleGalleryItem.Name)
                Exit Do
            End If
            pStyleGalleryItem = pEnumStyGall.Next
        Loop


        pMarkerSymbol1.Color = pBlack
        pMarkerSymbol2.Color = pBlack
        pMarkerSymbol3.Color = pBlack
        pMarkerSymbol4.Color = pBlack

        pMarkerSymbol1.Size = 6
        pMarkerSymbol2.Size = 6
        pMarkerSymbol3.Size = 6
        pMarkerSymbol4.Size = 6

        pMarkerSymbol1.Outline = 2
        pMarkerSymbol2.Outline = 2
        pMarkerSymbol3.Outline = 2
        pMarkerSymbol4.Outline = 2

        Dim pUniqueValueRenderer As IUniqueValueRenderer
        pUniqueValueRenderer = New UniqueValueRenderer

        Dim pTable As ITable
        Dim pDisplayTable As IDisplayTable
        pDisplayTable = pGeoFLayer
        pTable = pDisplayTable.DisplayTable

        With pUniqueValueRenderer
            .FieldCount = 1
            .Field(0) = pTable.Fields.Field(pTable.FindField("CodCita")).Name()
            .UseDefaultSymbol = False
            .AddValue(1, "Propia", pMarkerSymbol1)
            .AddValue(2, "OtroAutor", pMarkerSymbol2)
            .AddValue(3, "SinConfirmar", pMarkerSymbol3)
            .AddValue(4, "Cultivado", pMarkerSymbol4)
        End With

        pGeoFLayer.Renderer = pUniqueValueRenderer
        pMxDoc.UpdateContents()
        pMxDoc.ActiveView.Refresh()

    End Sub
Reply
0 Kudos
3 Replies
Regular Contributor II
what is the error?
Reply
0 Kudos
New Contributor
Hello once more and dear agray1:

I have changed the code a little bit. The error is now on the line "pSMS1 = pMarkerSym" in the following bloque
        Dim pSMS1 As ISimpleMarkerSymbol
        pSMS1 = pMarkerSym
        pSMS1.OutlineSize = 30

The different styles are assigned to objects of the MarkerSymbol - Class. But I need objects of the SimpleMarkerSymbol - Class in order to change the outlinesize. I tried to change Interfaces in the line pSMS1 = pMarkerSym. I supposed it is a "Type Inheritance" but it gives me an error and ArcMap closes.

Then I also like to change the fill symbol but I haven´t go so far.

Thanks for your help!
Anika



   Sub ChangeMarkerUVRSimpleEj()

        Dim pMxDoc As IMxDocument
        Dim pMap As IMap
        Dim pFLayer As IFeatureLayer

        'Get the first layer in the map
        pMxDoc = My.ArcMap.Document
        pMap = pMxDoc.FocusMap
        pFLayer = pMap.Layer(0)

        Dim pMxApp As IMxApplication
        Dim pGeoFLayer As IGeoFeatureLayer
        Dim pSDisplay As IScreenDisplay

        pMxApp = My.ArcMap.Application
        pGeoFLayer = pFLayer
        pSDisplay = pMxApp.Display

        Dim pStyleGallery As IStyleGallery
        Dim pStyleGalleryClass As IStyleGalleryClass
        Dim pStyleGalleryItem As IStyleGalleryItem
        pStyleGallery = pMxDoc.StyleGallery

        'Select the symbol type and the style you want to use
        Dim pEnumStyGall As IEnumStyleGalleryItem
        pEnumStyGall = pStyleGallery.Items("marker symbols", "ESRI.Style", "")

        pStyleGalleryItem = pEnumStyGall.Next

        Dim pMarkerSym As IMarkerSymbol

        'loop through the style gallery to find the marker symbol
        'called Circle 1
        Do While Not pStyleGalleryItem Is Nothing
            If pStyleGalleryItem.Name = "Circle 1" Then
                pMarkerSym = pStyleGalleryItem.Item
                Debug.Print(pStyleGalleryItem.Name)
                Exit Do
            End If
            pStyleGalleryItem = pEnumStyGall.Next
        Loop

        'Change the color to red
        Dim pColor As IRgbColor
        pColor = New RgbColor
        With pColor
            .Red = 250
            .Green = 0
            .Blue = 0
        End With
        pMarkerSym.Color = pColor
        pMarkerSym.Size = 30
        pGeoFLayer.Draw(esriDrawPhase.esriDPGeography, pSDisplay, pSDisplay.CancelTracker)

        Dim pSMS1 As ISimpleMarkerSymbol
        pSMS1 = pMarkerSym
        pSMS1.OutlineSize = 30

        Dim pUniqueValueRenderer As IUniqueValueRenderer
        pUniqueValueRenderer = New UniqueValueRenderer

        Dim pTable As ITable
        Dim pDisplayTable As IDisplayTable
        pDisplayTable = pGeoFLayer
        pTable = pDisplayTable.DisplayTable

        With pUniqueValueRenderer
            .FieldCount = 1
            .Field(0) = pTable.Fields.Field(pTable.FindField("CodCita")).Name()
            .UseDefaultSymbol = False
            .AddValue(1, "Propia", pSMS1)
            .AddValue(2, "OtroAutor", pMarkerSym)
        End With

        pGeoFLayer.Renderer = pUniqueValueRenderer
        pMxDoc.UpdateContents()
        pMxDoc.ActiveView.Refresh()
    End Sub
Reply
0 Kudos
Regular Contributor II
I can only help if you post the content of the error.
Reply
0 Kudos