Save a Join

345
2
03-01-2012 01:39 PM
GeorgeFaraj
Occasional Contributor III
I seem to remember seeing some code to do this and now I can't even remember what to call it. If I have created a Join using a memoryRelationshipFactory then I am using it dynamically. What is it called if I want the Join fields to become part of the featureLayer? (In other words to actually be physically a part of the shapefile?) Isn't there a way to import a join's schema and data into the shapefile?
0 Kudos
2 Replies
PriyankaMehta
New Contributor
Hi,
   I am not too sure of what problem you are exactly facing, but I guess this might help. This code joins layer to layer


        Dim pFeatLayer As IFeatureLayer
        Dim pFeatLayerjn As IFeatureLayer
        Dim pDispTable As IDisplayTable
        Dim pFCLayer As IFeatureClass
        Dim pTLayer As ITable
        Dim pActiveView As IActiveView

        pMxDoc = My.ArcMap.Document
        pMap = pMxDoc.FocusMap
        pActiveView = pMap
        pMap.ClearSelection()
        pActiveView.Refresh()


        Dim pTLayer2 As ITable
        If pMap.LayerCount < 2 Then
            MsgBox("Must have at least two layer", MsgBoxStyle.Information)
            Exit Function
        End If

        ''''''''''''''''*****************************''''''''''''''''''''''''''

        pFeatLayerjn = FindLayerByName(pMap, LayerName)  
        If pFeatLayerjn Is Nothing Then
            MsgBox("Could not find Layer " & LayerName & "for joining", MsgBoxStyle.Exclamation)
            Exit Function
        End If

        pDispTable = pFeatLayerjn
        pFCLayer = pDispTable.DisplayTable
        pTLayer = pFCLayer

        pFeatLayer = pMap.Layer(0)   
        pDispTable = pFeatLayer
        pFCLayer = pDispTable.DisplayTable
        pTLayer2 = pFCLayer
       
        Dim strJnField As String
        Dim JnField2 As String

        strJnField = joinfield1           ''''''' FID
        JnField2 = joinfield2             ''''''' PntName

        ' Create virtual relate
        Dim pMemRelFact As IMemoryRelationshipClassFactory
        Dim pRelClass As IRelationshipClass

        pMemRelFact = New MemoryRelationshipClassFactory
        pRelClass = pMemRelFact.Open("LayertoLayer", pTLayer2, strJnField, pTLayer, JnField2, "forward", "backward", esriRelCardinality.esriRelCardinalityOneToOne)

        ' use Relate to perform a join
        Dim pDispRC As IDisplayRelationshipClass
pDispRC = pFeatLayer
pDispRC.DisplayRelationshipClass(pRelClass, esriJoinType.esriLeftOuterJoin)

  
        MsgBox("Fields Joined", MsgBoxStyle.Information)



Referring this one might also help

http://forums.esri.com/Thread.asp?c=93&f=992&t=97996&mc=3#msgid274992


Regards,
Priyanka
0 Kudos
GeorgeFaraj
Occasional Contributor III
Hi,
   I am not too sure of what problem you are exactly facing, but I guess this might help. This code joins layer to layer

Referring this one might also help

http://forums.esri.com/Thread.asp?c=93&f=992&t=97996&mc=3#msgid274992


Regards,
Priyanka


Thanks! But isn't there a way to export a join to a feature class?  That is what I am searching for.  The Joined fields actually become part of the feature class.
0 Kudos