ArcGIS Pro 3.6 API Reference Guide
ArcGIS.Core.Data.Knowledge.Analytics Namespace / PathsEntitiesAndRelationships Class / ToKnowledgeGraphIDSet Method
The type of result content to include in the id set
Example

In This Topic
    ToKnowledgeGraphIDSet Method (PathsEntitiesAndRelationships)
    In This Topic
    Converts the entities and relationships from the FFP results into a ArcGIS.Core.Data.Knowledge.KnowledgeGraphIDSet.
    Syntax
    public KnowledgeGraphIDSet ToKnowledgeGraphIDSet( 
       KGResultContentFromFFP resultContent
    )
    Public Function ToKnowledgeGraphIDSet( _
       ByVal resultContent As KGResultContentFromFFP _
    ) As KnowledgeGraphIDSet

    Parameters

    resultContent
    The type of result content to include in the id set

    Return Value

    Remarks
    Note: Use KGResultContentFromFFP.EntitiesAndRelationships to update both entities and relationships on a link chart (eg via map.AppendToLinkChart(kgLayerIdSet) or via MapFactory.Instance.CreateLinkChart("name", kg, kgLayerIdSet) and use KGResultContentFromFFP.OnlyPathsOriginEntities to return the subset of entity uids that can be used as link chart root nodes.
    Example
    Create Link Chart from FFP Results
        //using ArcGIS.Core.Data.Knowledge.Extensions;
    
        await QueuedTask.Run(async() =>
        {
            var ffp_config = new CIMFilteredFindPathsConfiguration();
            ffp_config.Name = "Create Link Chart from FFP Results";
    //set up config
    //...
            
            var results = kg.RunFilteredFindPaths(ffp_config);
    
            var pathsEntitiesAndRelationships = results.ExtractPathsEntitiesAndRelationships(null);
    
            //Create a KG layer id set
            var kgLayerIdSet = KnowledgeGraphLayerIDSet.FromKnowledgeGraphIDSet(
                pathsEntitiesAndRelationships.ToKnowledgeGraphIDSet(
                    KGResultContentFromFFP.EntitiesAndRelationships));
    
            //Create a brand new link chart with the results and show it
            var linkChart = MapFactory.Instance.CreateLinkChart(
                                                "KG Intro", kg, kgLayerIdSet);
    
            var mapPane = await FrameworkApplication.Panes.CreateMapPaneAsync(linkChart);
            var linkChartView = mapPane.MapView;
    
            //Change layout algo to match the default used by the UI after FFP
            await linkChartView.SetLinkChartLayoutAsync(
                KnowledgeLinkChartLayoutAlgorithm.Hierarchical_TopToBottom);
    
            //Set root nodes - they correspond to the origin nodes of the result paths
            var kgLayerIdSetForRootNodes = KnowledgeGraphLayerIDSet.FromKnowledgeGraphIDSet(
                pathsEntitiesAndRelationships.ToKnowledgeGraphIDSet(
                    KGResultContentFromFFP.OnlyPathsOriginEntities));
    
            //To correctly identify the ids in the link chart we must change the ids
            //from Geodatabase oids returned in the KnowledgeGraphLayerIDSet to the
    //temporary/synthetic oids used by layers in the link chart...
            var kg_layer = linkChart.GetLayersAsFlattenedList().OfType<KnowledgeGraphLayer>().First();
            var mapMembers = kg_layer.GetMapMembersAsFlattenedList();
            var oidDict = kgLayerIdSetForRootNodes.ToOIDDictionary();
            var mmDict = new Dictionary<MapMember, List<long>>();
            foreach (var kvp in oidDict)
            {
                var named_type = kvp.Key;
                foreach (var mm in mapMembers)
                {
                    if (mm is LinkChartFeatureLayer fl_lc && fl_lc.IsEntity)
                    {
                        if (fl_lc.GetTypeName().ToLower() == named_type.ToLower())
                        {
                            var lc_oids = new List<long>();
                            //these oids are from the geodatabase
                            var oid_field = $"{fl_lc.GetTypeName()}.objectid";
                            var id_list = string.Join(',', kvp.Value.ToArray());
                            var where = $"{fl_lc.GetTypeName()}.objectid IN ({id_list})";
    
                            var qf = new ArcGIS.Core.Data.QueryFilter()
                            {
                                WhereClause = where,
                                SubFields = $"LC.OID,{oid_field}"//the 'LC.OID' oids are the ones
                                               //we need for the mapmember id set
                                               //in the link chart
                            };
                            var rc = fl_lc.Search(qf);
                            var oid_idx = rc.FindField(oid_field);
                            while (rc.MoveNext())
                            {
                                var oid = (long)rc.Current[oid_idx];
                                var lc_oid = rc.Current.GetObjectID();
                                lc_oids.Add(lc_oid);
                            }
                            rc.Dispose();
                            mmDict[fl_lc] = lc_oids;
                            break;
                        }
                    }
                }
            }
    
            var mmIdSet = MapMemberIDSet.FromDictionary(mmDict);
            linkChartView.SetRootNodes(mmIdSet);
        });
    Append to Link Chart from FFP Results
    //using ArcGIS.Core.Data.Knowledge.Extensions;
    
    var linkChartView = MapView.Active;
    
    await QueuedTask.Run(async () =>
    {
        var ffp_config = new CIMFilteredFindPathsConfiguration();
        ffp_config.Name = "Append to Link Chart from FFP Results";
        //set up config
        //...
    
        var results = kg.RunFilteredFindPaths(ffp_config);
    
        var pathsEntitiesAndRelationships = results.ExtractPathsEntitiesAndRelationships(null);
    
        //Create a KG layer id set
        var kgLayerIdSet = KnowledgeGraphLayerIDSet.FromKnowledgeGraphIDSet(
            pathsEntitiesAndRelationships.ToKnowledgeGraphIDSet(
                KGResultContentFromFFP.EntitiesAndRelationships));
    
        var map = linkChartView.Map;
    
        if (!map.CanAppendToLinkChart(kgLayerIdSet))
            return;//not compatible
    
        map.AppendToLinkChart(kgLayerIdSet);
        //switch layout algo
        var algo = linkChartView.GetLinkChartLayout();
        if (algo != KnowledgeLinkChartLayoutAlgorithm.Hierarchical_TopToBottom)
        {
            //Change layout algo to match the default used by the UI after FFP
            await linkChartView.SetLinkChartLayoutAsync(
                KnowledgeLinkChartLayoutAlgorithm.Hierarchical_TopToBottom);
        }
    
        //To set link chart root nodes see 'Create Link Chart from FFP Results'
    });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.6 or higher.
    See Also