

Public NotInheritable Class KnowledgeGraph Inherits ArcGIS.Core.Data.Datastore Implements System.IDisposable
public sealed class KnowledgeGraph : ArcGIS.Core.Data.Datastore, System.IDisposable
{
await QueuedTask.Run(() =>
{
//Create a connection properties
var kg_props =
new KnowledgeGraphConnectionProperties(new Uri(url));
try
{
//Open a connection
using (var kg = new KnowledgeGraph(kg_props))
{
//TODO...use the KnowledgeGraph
}
}
catch (GeodatabaseNotFoundOrOpenedException ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
});
}
{
await QueuedTask.Run(() =>
{
//Starting at 3.7, users can connect to a _file_ knowledge graph
//The extension for a file kg is ".knowledgegraph"
// Any path you want
string kgPath = @"C:\Data\KG\Filebased_KG";
string kgFileName = @"Test_File_KG.knowledgegraph";
var kg_full_path = System.IO.Path.Combine(kgPath, kgFileName);
var kg_props = new KnowledgeGraphConnectionProperties(new Uri(kg_full_path));
try
{
//Open a connection
using (var kg = new KnowledgeGraph(kg_props))
{
//TODO...use the File KnowledgeGraph
var i = 0;
//Get the featureclass definitions from the KG datastore
var fc_defs = kg.GetDefinitions<FeatureClassDefinition>();
//For each feature class definition, get the corresponding
//feature class. Note: The name of the feature class will match
//the name of its corresponding KnowledgeGraph named object type
//in the KnowledgeGraph graph data model
foreach (var fc_def in fc_defs)
{
var fc_name = fc_def.GetName();
System.Diagnostics.Debug.WriteLine($"FeatureClass[{i++}] {fc_name}");
}
}
}
catch (GeodatabaseNotFoundOrOpenedException ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
});
}
{
//var kgLayer = MapView.Active.Map.GetLayersAsFlattenedList()
// .OfType<KnowledgeGraphLayer>().FirstOrDefault();
await 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
}
}
});
}
System.Object
ArcGIS.Core.CoreObjectsBase
ArcGIS.Core.Data.Datastore
ArcGIS.Core.Data.Knowledge.KnowledgeGraph
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)