Public Overloads Sub Create( _ ByVal indexDescription As IndexDescription _ )
public void Create( IndexDescription indexDescription )
Parameters
- indexDescription
- Indicates the ArcGIS.Core.Data.Index to be created.
Public Overloads Sub Create( _ ByVal indexDescription As IndexDescription _ )
public void Create( IndexDescription indexDescription )
| Exception | Description |
|---|---|
| System.ArgumentNullException | indexDescription is null. |
| System.InvalidOperationException | Memory ArcGIS.Core.Data.Geodatabase does not support indexes. |
| System.InvalidOperationException | Attribute indexes must be ascending on KnowledgeGraphs |
| System.InvalidOperationException | User defined spatial indexes cannot be added to a knowledge graph |
| ArcGIS.Core.CalledOnWrongThreadException | This method or property must be called within the lambda passed to QueuedTask.Run. |
{
// Must be called within QueuedTask.Run
void CreatingTableWithIndex(SchemaBuilder schemaBuilder)
{
FieldDescription nameFieldDescription = FieldDescription.CreateStringField("Name", 50);
FieldDescription addressFieldDescription = FieldDescription.CreateStringField("Address", 200);
// Creating a feature class, 'Buildings' with two fields
TableDescription tableDescription = new TableDescription("Buildings",
new List<FieldDescription>() { nameFieldDescription, addressFieldDescription });
// Enqueue DDL operation to create a table
TableToken tableToken = schemaBuilder.Create(tableDescription);
// Creating an attribute index named as 'Idx'
AttributeIndexDescription attributeIndexDescription = new AttributeIndexDescription("Idx", new TableDescription(tableToken),
new List<string> { nameFieldDescription.Name, addressFieldDescription.Name });
// Enqueue DDL operation to create an attribute index
schemaBuilder.Create(attributeIndexDescription);
// Execute build indexes operation
bool isBuildSuccess = schemaBuilder.Build();
}
}
{
// Must be called within QueuedTask.Run
void AddingIndexes(SchemaBuilder schemaBuilder, FeatureClassDefinition featureClassDefinition)
{
// Field names to add in the attribute index
string fieldName = featureClassDefinition.GetFields().First(f => f.AliasName.Contains("Name")).Name;
string fieldAddress = featureClassDefinition.GetFields().First(f => f.AliasName.Contains("Address")).Name;
// Creating an attribute index with index name 'Idx' and two participating fields' name
AttributeIndexDescription attributeIndexDescription = new AttributeIndexDescription("Idx",
new TableDescription(featureClassDefinition), new List<string> { fieldName, fieldAddress });
// Enqueue DDL operation for an attribute index creation
schemaBuilder.Create(attributeIndexDescription);
// Creating the spatial index
SpatialIndexDescription spatialIndexDescription = new SpatialIndexDescription(new FeatureClassDescription(featureClassDefinition));
// Enqueue DDL operation for the spatial index creation
schemaBuilder.Create(spatialIndexDescription);
// Execute build indexes operation
bool isBuildSuccess = schemaBuilder.Build();
if (!isBuildSuccess)
{
IReadOnlyList<string> errors = schemaBuilder.ErrorMessages;
// Iterate and handle errors
}
}
}
{
// Must be called within QueuedTask.Run
void CreateTableWithSubtypes(SchemaBuilder schemaBuilder)
{
// Creating a 'Building' table with the subtype field 'BuildingType'
FieldDescription buildingType = new FieldDescription("BuildingType", FieldType.Integer);
FieldDescription buildingName = new FieldDescription("Name", FieldType.String);
TableDescription tableDescription = new TableDescription("Building", new List<FieldDescription> { buildingName, buildingType });
// Add the building type subtype with three subtypes - Business, Marketing, Security
tableDescription.SubtypeFieldDescription = new SubtypeFieldDescription(buildingType.Name,
new Dictionary<int, string> { { 1, "Business" }, { 2, "Marketing" }, { 3, "Security" } })
{
DefaultSubtypeCode = 3 // Assigning 'Security' building type as the default subtype
};
schemaBuilder.Create(tableDescription);
schemaBuilder.Build();
}
}
{
// Must be called within QueuedTask.Run
void CreateRelationshipWithRelationshipRules(SchemaBuilder schemaBuilder)
{
// Creating a 'BuildingType' table with two fields - BuildingType and BuildingTypeDescription
FieldDescription buildingType = FieldDescription.CreateIntegerField("BuildingType");
FieldDescription buildingTypeeDescription = FieldDescription.CreateStringField("BuildingTypeDescription", 100);
TableDescription buildingTypeDescription = new TableDescription("BuildingType",
new List<FieldDescription>() { buildingType, buildingTypeeDescription });
TableToken buildingtypeToken = schemaBuilder.Create(buildingTypeDescription);
// Creating a 'Building' feature class with three fields - BuildingId, Address, and BuildingType
FieldDescription buildingId = FieldDescription.CreateIntegerField("BuildingId");
FieldDescription buildingAddress = FieldDescription.CreateStringField("Address", 100);
FieldDescription usageSubType = FieldDescription.CreateIntegerField("UsageSubtype");
FeatureClassDescription featureClassDescription = new FeatureClassDescription("Building",
new List<FieldDescription> { buildingId, buildingAddress, buildingType, usageSubType },
new ShapeDescription(GeometryType.Polygon, SpatialReferences.WGS84));
// Set subtype details (optional)
featureClassDescription.SubtypeFieldDescription = new SubtypeFieldDescription(usageSubType.Name,
new Dictionary<int, string> { { 1, "Marketing" }, { 2, "Utility" } });
FeatureClassToken buildingToken = schemaBuilder.Create(featureClassDescription);
// Creating a 1:M relationship between the 'Building' feature class and 'BuildingType' table
RelationshipClassDescription relationshipClassDescription = new RelationshipClassDescription(
"BuildingToBuildingType", new FeatureClassDescription(buildingToken), new TableDescription(buildingtypeToken),
RelationshipCardinality.OneToMany, buildingType.Name, buildingType.Name)
{
RelationshipType = RelationshipType.Composite
};
// Adding relationship rules for the 'Marketing' subtype
relationshipClassDescription.RelationshipRuleDescriptions.Add(new RelationshipRuleDescription(1, null));
schemaBuilder.Create(relationshipClassDescription);
schemaBuilder.Build();
}
}
{
// Must be called within QueuedTask.Run
void CreateAttributedRelationship(SchemaBuilder schemaBuilder)
{
// Creating a 'BuildingType' table with two fields - BuildingType and BuildingTypeDescription
FieldDescription buildingType = FieldDescription.CreateIntegerField("BuildingType");
FieldDescription buildingTypeeDescription = FieldDescription.CreateStringField("BuildingTypeDescription", 100);
TableDescription buildingTypeDescription = new TableDescription("BuildingType",
new List<FieldDescription>() { buildingType, buildingTypeeDescription });
TableToken buildingtypeToken = schemaBuilder.Create(buildingTypeDescription);
// Creating a 'Building' feature class with three fields - BuildingId, Address, and BuildingType
FieldDescription buildingId = FieldDescription.CreateIntegerField("BuildingId");
FieldDescription buildingAddress = FieldDescription.CreateStringField("Address", 100);
FeatureClassDescription featureClassDescription = new FeatureClassDescription("Building",
new List<FieldDescription> { buildingId, buildingAddress, buildingType },
new ShapeDescription(GeometryType.Polygon, SpatialReferences.WGS84));
FeatureClassToken buildingToken = schemaBuilder.Create(featureClassDescription);
// Creating M:M relationship between the 'Building' feature class and 'BuildingType' table
AttributedRelationshipClassDescription attributedRelationshipClassDescription =
new AttributedRelationshipClassDescription("BuildingToBuildingType",
new FeatureClassDescription(buildingToken),
new TableDescription(buildingtypeToken), RelationshipCardinality.ManyToMany, "OBJECTID", "BuildingID",
"OBJECTID", "BuildingTypeID");
// Adding optional attribute field in the intermediate table - 'OwnershipPercentage' field
attributedRelationshipClassDescription.FieldDescriptions.Add(FieldDescription.CreateIntegerField("OwnershipPercentage"));
schemaBuilder.Create(attributedRelationshipClassDescription);
schemaBuilder.Build();
}
}
{
await QueuedTask.Run(() =>
{
using (var kg = GetKnowledgeGraph(url))
{
var entity_name = "PhoneCall";
//indexes are managed on the GDB objects...
var entity_table_def = kg.GetDefinition<TableDefinition>(entity_name);
var entity_table_desc = new TableDescription(entity_table_def);
var entity_table_flds = entity_table_def.GetFields();
AttributeIndexDescription attr_index1 = null;
AttributeIndexDescription attr_index2 = null;
foreach (var fld in entity_table_flds)
{
//index the first string field
if (fld.FieldType == FieldType.String && attr_index1 == null)
{
if (fld.Name == "ESRI__ID")//special case
continue;
//Index _must_ be ascending for KG
attr_index1 = new AttributeIndexDescription(
"Index1", entity_table_desc, new List<string> { fld.Name })
{
IsAscending = true
};
}
//index the first numeric field (if there is one)
if ((fld.FieldType == FieldType.BigInteger ||
fld.FieldType == FieldType.Integer ||
fld.FieldType == FieldType.Single ||
fld.FieldType == FieldType.SmallInteger ||
fld.FieldType == FieldType.Double) && attr_index2 == null)
{
attr_index2 = new AttributeIndexDescription(
"Index2", entity_table_desc, new List<string> { fld.Name })
{
IsAscending = true,
IsUnique = true //optional - unique if all values are to be unique in the index
};
}
if (attr_index1 != null && attr_index2 != null) break;
}
if (attr_index1 == null && attr_index2 == null)
return; //nothing to index
//Run the schema builder
try
{
SchemaBuilder sb = new(kg);
if (attr_index1 != null)
sb.Create(attr_index1);
if (attr_index2 != null)
sb.Create(attr_index2);
if (!kg.ApplySchemaEdits(sb))
{
var err_msg = string.Join(",", sb.ErrorMessages.ToArray());
System.Diagnostics.Debug.WriteLine($"Create index error: {err_msg}");
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
});
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)