ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / KnowledgeGraphLayer Class
Members Example

In This Topic
    KnowledgeGraphLayer Class
    In This Topic
    A knowledge graph layer is a composite layer with a knowledge graph as its data source.
    Object Model
    KnowledgeGraphLayer ClassLayer ClassStandaloneTable ClassCIMDataConnection ClassKnowledgeGraph ClassTimeExtent ClassCIMBaseLayer ClassElevationTypeDefinition ClassKnowledgeGraphLayerIDSet ClassSpatialReference ClassTimeParameters ClassSurfaceZsResult ClassMap ClassILayerContainer InterfaceEnvelope Class
    Syntax
    Remarks
    The knowledge graph layer contains knowledge graph feature layers and knowledge graph tables. One knowledge graph feature layer is created within the knowledge graph composite layer per entity and relationship type when the entity and relationship instances can have spatial features. A standalone table is created within the knowledge graph composite layer per entity and relationship type that is nonspatial.
    Example
    Getting a Connection from a KnowledgeGraphLayer
    var kgLayer = MapView.Active.Map.GetLayersAsFlattenedList()
            .OfType<KnowledgeGraphLayer>().FirstOrDefault();
    
    
    QueuedTask.Run(() =>
    {
      // use the layer directly
      KnowledgeGraph datastore = kgLayer.GetDatastore();
      
      // or you can use any of the sub items since
      //KnowledgeGraphLayer is a composite layer - get the first 
      // child feature layer or standalone table
      var featlayer = kgLayer?.GetLayersAsFlattenedList()?
                      .OfType<FeatureLayer>()?.FirstOrDefault();
      KnowledgeGraph kg = null;
      if (featlayer != null)
      {
        using (var fc = featlayer.GetFeatureClass())
          kg = fc.GetDatastore() as KnowledgeGraph;
        //TODO use KnowledgeGraph
      }
      else
      {
        //try standalone table
        var stbl = kgLayer?.GetStandaloneTablesAsFlattenedList()?
                        .FirstOrDefault();
        if (stbl != null)
        {
          using (var tbl = stbl.GetTable())
            kg = tbl.GetDatastore() as KnowledgeGraph;
          //TODO use KnowledgeGraph
        }
      }
    });
    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);
    
    });
    SubLayers of a KnowledgeGraph Layer
    var map = MapView.Active.Map;
    var kgLayer = map.GetLayersAsFlattenedList().OfType<KnowledgeGraphLayer>().FirstOrDefault();
    if (kgLayer == null)
      return;
    
    if (map.MapType == MapType.LinkChart)
    {
      // if map is of MapType.LinkChart then the first level
      // children of the kgLayer are of type LinkChartFeatureLayer
      var childLayers = kgLayer.Layers;
      foreach (var childLayer in childLayers)
      {
        if (childLayer is LinkChartFeatureLayer lcFeatureLayer)
        {
          var isEntity = lcFeatureLayer.IsEntity;
          var isRel = lcFeatureLayer.IsRelationship;
    
          // TODO - continue processing
        }
      }
    }
    else if (map.MapType == MapType.Map)
    {
      // if map is of MapType.Map then the children of the
      // kgLayer are the standard Featurelayer and StandAloneTable
      var chidlren = kgLayer.GetMapMembersAsFlattenedList();
      foreach (var child in chidlren)
      {
        if (child is FeatureLayer fl)
        {
          // TODO - process the feature layer
        }
        else if (child is StandaloneTable st)
        {
          // TODO - process the standalone table
        }
      }
    }
    
    
    Inheritance Hierarchy

    System.Object
       ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase
          ArcGIS.Desktop.Mapping.MapMember
             ArcGIS.Desktop.Mapping.Layer
                ArcGIS.Desktop.Mapping.CompositeLayer
                   ArcGIS.Desktop.Mapping.CompositeLayerWithTables
                      ArcGIS.Desktop.Mapping.KnowledgeGraphLayer

    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.2 or higher.
    See Also