Converting Symbology to a Representation (VB.NET)

4694
4
05-15-2014 08:04 AM
AMMConsulting
New Contributor
Hello,

I'm having trouble with converting a feature class to a representation that also converts its symbology to representation rules. I know this is possible within ArcMap. Basically what I'd like to do is to programmatically convert a feature class that is symbolized based on unique values to a representation which then contains a representation rule for each symbolized category.

Following the sample codes given by ESRI, I was able to convert a feature class to a representation that has no representation rules. I then tried to test out ESRI's sample code to convert a marker symbol into a representation symbol and adding this to the representation rules when converting the feature class. However, the marker did not show up in ArcMap (everything was a red square). I have a feeling that this is because the symbol I tried to use was one that we made ourselves and added to the style library as a picture marker symbol.

Unfortunately I'm having trouble finding enough resources to accomplish this myself so if anyone can point me in the right direction, I would really appreciate it! I've included my code below:

 Module Representation
    Public Sub CreateRepClass(ByVal layerName As String)
        Try
            Dim pMxDoc As IMxDocument
            Dim pMap As IMap
            Dim pLayer As IFeatureLayer
            Dim pFClass As IFeatureClass
            Dim index As Integer

            'Get the feature class I want to convert:
            pMxDoc = My.ArcMap.Application.Document
            pMap = pMxDoc.FocusMap
            index = FindLayer(layerName)
            pLayer = pMap.Layer(index)
            pFClass = pLayer.FeatureClass

            Dim pDataset As IDataset
            Dim pWorkspace As IWorkspace
            Dim pRepWSExt As IRepresentationWorkspaceExtension
            Dim pRules As IRepresentationRules

            'Get the workspace from the feature class:
            pDataset = pFClass
            pWorkspace = pDataset.Workspace
            pRepWSExt = GetRepWSExt(pWorkspace) 'Get the representation extension using function below

            'Get the representation rules using the function below:
            pRules = ConvertToRepMarker() 'New RepresentationRules

            'Create representation class from feature class and rules:
            pRepWSExt.CreateRepresentationClass(pFClass, pFClass.AliasName + "_Rep", "My_RuleID", "My_Override", True, pRules, Nothing)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Public Function GetRepWSExt(ByVal pWorkspace As IWorkspace) As IRepresentationWorkspaceExtension
        Dim pExtManager As IWorkspaceExtensionManager
        Dim pUID As IUID

        'Assign new UID
        pExtManager = pWorkspace
        pUID = New UID
        pUID.Value = "{FD05270A-8E0B-4823-9DEE-F149347C32B6}"

        'Find and return the representation workspace extension
        Dim pRepWSExt As IRepresentationWorkspaceExtension
        pRepWSExt = pExtManager.FindExtension(pUID)

        Return pRepWSExt
    End Function

    Public Function ConvertToRepMarker() As IRepresentationRules
        Dim pRepresentationRules As IRepresentationRules
        Dim pMarker As IMarkerSymbol
        Dim pRepresentationRule As IRepresentationRule
        Dim pRepRuleInit As IRepresentationRuleInit

        'Create new representation rules:
        pRepresentationRules = New RepresentationRules

        'Find the symbol from the style library using a function
        'This function has been tested before and works
        pMarker = FindSymbol("MarkerName", "Category")

        'Create new representation rule:
        pRepresentationRule = New RepresentationRule
        pRepRuleInit = pRepresentationRule
        pRepRuleInit.InitWithSymbol(pMarker)    'Convert marker symbol to representation

        'Give the rule a name:
        Dim ID As Long
        ID = pRepresentationRules.Add(pRepresentationRule)
        pRepresentationRules.Name(ID) = "TestRule"

        'Return the representation rules:
        Return pRepresentationRules
    End Function
End Module
0 Kudos
4 Replies
JeffMatson
Occasional Contributor III
Has the RuleID field of the feature class been calculated to a valid value for your rule?


Hello,

I'm having trouble with converting a feature class to a representation that also converts its symbology to representation rules. I know this is possible within ArcMap. Basically what I'd like to do is to programmatically convert a feature class that is symbolized based on unique values to a representation which then contains a representation rule for each symbolized category.

Following the sample codes given by ESRI, I was able to convert a feature class to a representation that has no representation rules. I then tried to test out ESRI's sample code to convert a marker symbol into a representation symbol and adding this to the representation rules when converting the feature class. However, the marker did not show up in ArcMap (everything was a red square). I have a feeling that this is because the symbol I tried to use was one that we made ourselves and added to the style library as a picture marker symbol.

Unfortunately I'm having trouble finding enough resources to accomplish this myself so if anyone can point me in the right direction, I would really appreciate it! I've included my code below:

 Module Representation
    Public Sub CreateRepClass(ByVal layerName As String)
        Try
            Dim pMxDoc As IMxDocument
            Dim pMap As IMap
            Dim pLayer As IFeatureLayer
            Dim pFClass As IFeatureClass
            Dim index As Integer

            'Get the feature class I want to convert:
            pMxDoc = My.ArcMap.Application.Document
            pMap = pMxDoc.FocusMap
            index = FindLayer(layerName)
            pLayer = pMap.Layer(index)
            pFClass = pLayer.FeatureClass

            Dim pDataset As IDataset
            Dim pWorkspace As IWorkspace
            Dim pRepWSExt As IRepresentationWorkspaceExtension
            Dim pRules As IRepresentationRules

            'Get the workspace from the feature class:
            pDataset = pFClass
            pWorkspace = pDataset.Workspace
            pRepWSExt = GetRepWSExt(pWorkspace) 'Get the representation extension using function below

            'Get the representation rules using the function below:
            pRules = ConvertToRepMarker() 'New RepresentationRules

            'Create representation class from feature class and rules:
            pRepWSExt.CreateRepresentationClass(pFClass, pFClass.AliasName + "_Rep", "My_RuleID", "My_Override", True, pRules, Nothing)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Public Function GetRepWSExt(ByVal pWorkspace As IWorkspace) As IRepresentationWorkspaceExtension
        Dim pExtManager As IWorkspaceExtensionManager
        Dim pUID As IUID

        'Assign new UID
        pExtManager = pWorkspace
        pUID = New UID
        pUID.Value = "{FD05270A-8E0B-4823-9DEE-F149347C32B6}"

        'Find and return the representation workspace extension
        Dim pRepWSExt As IRepresentationWorkspaceExtension
        pRepWSExt = pExtManager.FindExtension(pUID)

        Return pRepWSExt
    End Function

    Public Function ConvertToRepMarker() As IRepresentationRules
        Dim pRepresentationRules As IRepresentationRules
        Dim pMarker As IMarkerSymbol
        Dim pRepresentationRule As IRepresentationRule
        Dim pRepRuleInit As IRepresentationRuleInit

        'Create new representation rules:
        pRepresentationRules = New RepresentationRules

        'Find the symbol from the style library using a function
        'This function has been tested before and works
        pMarker = FindSymbol("MarkerName", "Category")

        'Create new representation rule:
        pRepresentationRule = New RepresentationRule
        pRepRuleInit = pRepresentationRule
        pRepRuleInit.InitWithSymbol(pMarker)    'Convert marker symbol to representation

        'Give the rule a name:
        Dim ID As Long
        ID = pRepresentationRules.Add(pRepresentationRule)
        pRepresentationRules.Name(ID) = "TestRule"

        'Return the representation rules:
        Return pRepresentationRules
    End Function
End Module
0 Kudos
AMMConsulting
New Contributor
Hi Jeff,

Thank you for your advice. I got the symbol to show up by using the Calculate Representation Rule programmatically.

Would you, or anyone, know how to assign the representation rules to features based on their attribute information?

Originally I had symbolized the feature class based on two attribute fields using the unique values renderer. I thought that there would be a way to convert the symbolized feature class to a representation which would also convert its symbology into representation rules using ArcObjects (much like it does in ArcMap). Is this possible?

If not, would querying the attributes and assigning the rules to each individual feature work?

Thanks,
Stewart
0 Kudos
JeffMatson
Occasional Contributor III

Originally I had symbolized the feature class based on two attribute fields using the unique values renderer. I thought that there would be a way to convert the symbolized feature class to a representation which would also convert its symbology into representation rules using ArcObjects (much like it does in ArcMap). Is this possible?


Perhaps update the ConvertToRepMarker function to accept a feature layer as input.  Then loop through the UniqueValueRenderer for your target layer, create a new rule for each symbol and add it to the pRepresentationRules object.
After that, select features by attributes and calculate the correct RuleID for each group.
0 Kudos
AMMConsulting
New Contributor
Thanks Jeff. I'll try doing it that way.

- Stewart
0 Kudos