ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / KnowledgeGraphLayerIDSet Class / FromKnowledgeGraph Method / FromKnowledgeGraph(Uri,KnowledgeGraphFilterType) Method
A Uri link to a knowledge graph service or file-based knowledge graph
The type of named type objects to include in the filter set.
Example

In This Topic
    FromKnowledgeGraph(Uri,KnowledgeGraphFilterType) Method
    In This Topic
    Creates a KnowledgeGraphLayerIDSet with a particular filter type. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax

    Parameters

    knowledgeGraphPathOrServiceUri
    A Uri link to a knowledge graph service or file-based knowledge graph
    filterType
    The type of named type objects to include in the filter set.

    Return Value

    Exceptions
    ExceptionDescription
    The knowledgeGraphPathOrServiceUri is null.
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Example
    Create a Link Chart Containing All Records for a KG
    {
      await QueuedTask.Run(() =>
      {
        //Create the link chart and show it
        //build the IDSet using KnowledgeGraphFilterType.AllNamedObjects
        var idSet = KnowledgeGraphLayerIDSet.FromKnowledgeGraph(
          kg, KnowledgeGraphFilterType.AllNamedObjects);
        var linkChart = MapFactory.Instance.CreateLinkChart(
                          "KG Link Chart", kg, idSet);
        FrameworkApplication.Panes.CreateMapPaneAsync(linkChart);
      });
    }
    Create a link chart with all the entities of the Knowledge Graph
    {
      await QueuedTask.Run(() =>
      {
        using (var kg_for_lc = new KnowledgeGraph(
          new KnowledgeGraphConnectionProperties(new Uri(url))))
        {
          var idSet = KnowledgeGraphLayerIDSet.FromKnowledgeGraph(
            kg_for_lc, KnowledgeGraphFilterType.AllEntities);
          var newLinkChart = MapFactory.Instance.CreateLinkChart(
            "All_Entities link chart", kg_for_lc, idSet);
        }
        ;
      });
    }
    Create a link chart based on a template link chart
    {
      // note that the template link chart MUST use the same KG server
    
      await QueuedTask.Run(() =>
      {
        // find the existing link chart by name
        var projectItem = Project.Current.GetItems<MapProjectItem>()
        .FirstOrDefault(pi => pi.Name == "Acme Link Chart");
        var linkChartMap = projectItem?.GetMap();
        if (linkChartMap == null)
          return;
    
        //Create a connection properties
        var kg_props2 =
            new KnowledgeGraphConnectionProperties(new Uri(url));
        try
        {
          //Open a connection
          using (var kg_for_lc = new KnowledgeGraph(kg_props2))
          {
            //Add all entities to the link chart
            var idSet = KnowledgeGraphLayerIDSet.FromKnowledgeGraph(
                  kg_for_lc, KnowledgeGraphFilterType.AllEntities);
            //Create the new link chart and show it
            var newLinkChart = MapFactory.Instance.CreateLinkChart(
                              "KG from Template", kg_for_lc, idSet, linkChartMap.URI);
            FrameworkApplication.Panes.CreateMapPaneAsync(newLinkChart);
          }
        }
        catch (Exception ex)
        {
          System.Diagnostics.Debug.WriteLine(ex.ToString());
        }
      });
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.3 or higher.
    See Also