CreateLinkChart(String,KnowledgeGraph,KnowledgeGraphLayerIDSet,String) Method
Creates a link chart map (a map of type MapType.LinkChart) with a specified knowledge graph datastore.
This method must be called on the MCT. Use QueuedTask.Run.
Parameters
- name
- The name of the map.
- knowledgeGraph
- A knowledge graph datastore.
- idSet
- A set of Named Object types and record ids that sets the content of the Knowledge Graph layer. See KnowledgeGraphLayerIDSet.
- templateLinkChartPath
- The path to a link chart to use as a template for layout and styling. Use null or an empty string to create the link chart with the default layout and styling. If specified, the template link chart must use the same knowledge graph service as .
Return Value
A
map of type MapType.LinkChart.
Create a LinkChart from a subset of an existing LinkChart IDSet
var map = MapView.Active.Map;
if (map.MapType != MapType.LinkChart)
return;
// find the KG layer
var kgLayer = map.GetLayersAsFlattenedList().OfType<KnowledgeGraphLayer>().FirstOrDefault();
if (kgLayer == null)
return;
// find the first LinkChartFeatureLayer in the KG layer
var lcFeatureLayer = kgLayer.GetLayersAsFlattenedList().OfType<LinkChartFeatureLayer>().FirstOrDefault();
if (lcFeatureLayer != null)
return;
QueuedTask.Run(() =>
{
// get the KG
var kg = kgLayer.GetDatastore();
// get the ID set of the KG layer
var idSet = kgLayer.GetIDSet();
// get the named object type in the KG that the LinkChartFeatureLayer represents
var typeName = lcFeatureLayer.GetTypeName();
// if there are items in the ID Set for this type
if (idSet.Contains(typeName))
{
// build a new ID set containing only these records
var dict = idSet.ToOIDDictionary();
var oids = dict[typeName];
var newDict = new Dictionary<string, List<long>>();
newDict.Add(typeName, oids);
var newIDSet = KnowledgeGraphLayerIDSet.FromDictionary(kg, newDict);
// now create a new link chart using just this subset of records
MapFactory.Instance.CreateLinkChart("subset LinkChart", kg, newIDSet);
}
});
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());
}
});
Checking KnowledgeGraphLayerException
// running on QueuedTask
var dict = new Dictionary<string, List<long>>();
dict.Add("person", new List<long>()); //Empty list means all records
dict.Add("made_call", null); //null list means all records
// or specific records - however the ids are obtained
dict.Add("phone_call", new List<long>() { 1, 5, 18, 36, 78 });
// make the id set
var idSet = KnowledgeGraphLayerIDSet.FromDictionary(kg, dict);
try
{
//Create the link chart and show it
var linkChart = MapFactory.Instance.CreateLinkChart(
"KG With ID Set", kg, idSet);
FrameworkApplication.Panes.CreateMapPaneAsync(linkChart);
}
catch (KnowledgeGraphLayerException e)
{
// get the invalid named types
// remember that the named types are case-sensitive
var invalidNamedTypes = e.InvalidNamedTypes;
// do something with the invalid named types
// for example - log or return to caller to show message to user
}
Target Platforms: Windows 11, Windows 10
ArcGIS Pro version: 3.3 or higher.