ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / KnowledgeGraphLayerIDSet Class / FromKnowledgeGraph Method / FromKnowledgeGraph(Uri,KnowledgeGraphFilterType) Method
A Uri link to a knowledge graph service.
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
    Public Overloads Shared Function FromKnowledgeGraph( _
       ByVal knowledgeGraphServiceUri As Uri, _
       ByVal filterType As KnowledgeGraphFilterType _
    ) As KnowledgeGraphLayerIDSet

    Parameters

    knowledgeGraphServiceUri
    A Uri link to a knowledge graph service.
    filterType
    The type of named type objects to include in the filter set.

    Return Value

    Exceptions
    ExceptionDescription
    The knowledgeGraphServiceUri 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
    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
    string url =
            @"https://acme.server.com/server/rest/services/Hosted/AcmeKnowledgeGraph/KnowledgeGraphServer";
    
    QueuedTask.Run(() =>
    {
      using (var kg = new KnowledgeGraph(new KnowledgeGraphConnectionProperties(new Uri(url))))
      {
        var idSet = KnowledgeGraphLayerIDSet.FromKnowledgeGraph(
          kg, KnowledgeGraphFilterType.AllEntities);
        var newLinkChart = MapFactory.Instance.CreateLinkChart(
          "All_Entities link chart", kg, idSet);
      };
    });
    
    Create a link chart based on a template link chart
    // note that the template link chart MUST use the same KG server
    
    string url =
            @"https://acme.server.com/server/rest/services/Hosted/AcmeKnowledgeGraph/KnowledgeGraphServer";
    
    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_props =
          new KnowledgeGraphConnectionProperties(new Uri(url));
      try
      {
        //Open a connection
        using (var kg = new KnowledgeGraph(kg_props))
        {
          //Add all entities to the link chart
          var idSet = KnowledgeGraphLayerIDSet.FromKnowledgeGraph(
                kg, KnowledgeGraphFilterType.AllEntities);
          //Create the new link chart and show it
          var newLinkChart = MapFactory.Instance.CreateLinkChart(
                            "KG from Template", kg, idSet, linkChartMap.URI);
          FrameworkApplication.Panes.CreateMapPaneAsync(newLinkChart);
        }
      }
      catch (Exception ex)
      {
        System.Diagnostics.Debug.WriteLine(ex.ToString());
      }
    });
    
    
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.3 or higher.
    See Also