ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / KnowledgeGraphLayerCreationParams Class
Members Example

In This Topic
    KnowledgeGraphLayerCreationParams Class
    In This Topic
    Represents an object to initialize and create a KnowledgeGraphLayer with pre-defined properties such as a filter set, visibility, etc..
    Object Model
    KnowledgeGraphLayerCreationParams ClassLayer ClassLayer ClassLayer ClassLayer ClassLayer ClassCIMDataConnection ClassKnowledgeGraphLayerIDSet ClassItem ClassKnowledgeGraph ClassCIMLayerDocument Class
    Syntax
    public class KnowledgeGraphLayerCreationParams : LayerCreationParams 
    Public Class KnowledgeGraphLayerCreationParams 
       Inherits LayerCreationParams
    Example
    Create a KG Layer containing all Entity and Relate types
    QueuedTask.Run(() =>
    {
      //With a connection to a KG established or source uri available...
      //Create a KnowledgeGraphLayerCreationParams
      var kg_params = new KnowledgeGraphLayerCreationParams(kg)
      {
        Name = "KG_With_All_Types",
        IsVisible = false
      };
      //Or
      var kg_params2 = new KnowledgeGraphLayerCreationParams(new Uri(url))
      {
        Name = "KG_With_All_Types",
        IsVisible = false
      };
      //Call layer factory with map or group layer container. 
      //A KG layer containing a feature layer and/or standalone table per
      //entity and relate type (except provenance) is created
      var kg_layer = LayerFactory.Instance.CreateLayer<KnowledgeGraphLayer>(
          kg_params, map);
    
    });
    Create a KG Layer containing a subset of Entity and Relate types
    QueuedTask.Run(() =>
    {
      //To create a KG layer (on a map or link chart) with a subset of
      //entities and relates, you must create an "id set". The workflow
      //is very similar to how you would create a SelectionSet.
    
      //First, create a dictionary containing the names of the types to be
      //added plus a corresponding list of ids (just like with a selection set).
      //Note: null or an empty list means add all records for "that" type..
      var kg_datamodel = kg.GetDataModel();
      //Arbitrarily get the name of the first entity and relate type
      var first_entity = kg_datamodel.GetEntityTypes().Keys.First();
      var first_relate = kg_datamodel.GetRelationshipTypes().Keys.First();
    
      //Make entries in the dictionary for each
      var dict = new Dictionary<string, List<long>>();
      dict.Add(first_entity, new List<long>());//Empty list means all records
      dict.Add(first_relate, null);//null list means all records
      //or specific records - however the ids are obtained
      //dict.Add(entity_or_relate_name, new List<long>() { 1, 5, 18, 36, 78});
    
      //Create the id set...
      var idSet = KnowledgeGraphLayerIDSet.FromDictionary(kg, dict);
    
      //Create the layer params and assign the id set
      var kg_params = new KnowledgeGraphLayerCreationParams(kg)
      {
        Name = "KG_With_ID_Set",
        IsVisible = false,
        IDSet = idSet
      };
    
      //Call layer factory with map or group layer container
      //A KG layer containing just the feature layer(s) and/or standalone table(s)
      //for the entity and/or relate types + associated records will be created
      var kg_layer = LayerFactory.Instance.CreateLayer<KnowledgeGraphLayer>(
          kg_params, map);
    
    });
    Using LayerFactory.Instance.CanCreateLayer with KG Create Layer Params
    QueuedTask.Run(() =>
    {
      //Feature class and/or standalone tables representing KG entity and
      //relate types can only be added to a map (or link chart) as a child
      //of a KnowledgeGraph layer....
    
      //For example:
      var fc = kg.OpenDataset<FeatureClass>("Some_Entity_Or_Relate_Name");
      try
      {
        //Attempting to create a feature layer containing the returned fc
        //NOT ALLOWED - can only be a child of a KG layer
        var fl_params_w_kg = new FeatureLayerCreationParams(fc);
        //CanCreateLayer will return false
        if (!(LayerFactory.Instance.CanCreateLayer<FeatureLayer>(
          fl_params_w_kg, map)))
        {
          System.Diagnostics.Debug.WriteLine(
            $"Cannot create a feature layer for {fc.GetName()}");
          return;
        }
        //This will throw an exception
        LayerFactory.Instance.CreateLayer<FeatureLayer>(fl_params_w_kg, map);
      }
      catch (Exception ex)
      {
        System.Diagnostics.Debug.WriteLine(ex.ToString());
      }
    
      //Can only be added as a child of a parent KG
      var dict = new Dictionary<string, List<long>>();
      dict.Add(fc.GetName(), new List<long>());
      var kg_params = new KnowledgeGraphLayerCreationParams(kg)
      {
        Name = $"KG_With_Just_{fc.GetName()}",
        IsVisible = false,
        IDSet = KnowledgeGraphLayerIDSet.FromDictionary(kg, dict)
      };
      var kg_layer = LayerFactory.Instance.CreateLayer<KnowledgeGraphLayer>(
        kg_params, map);
    
    });
    Inheritance Hierarchy

    System.Object
       ArcGIS.Desktop.Mapping.MapMemberCreationParams
          ArcGIS.Desktop.Mapping.LayerCreationParams
             ArcGIS.Desktop.Mapping.KnowledgeGraphLayerCreationParams

    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.2 or higher.
    See Also