ArcGIS Engine 개발 Geodatabase 코드 (5) - Relationship Class
설명: 이 코드는 ArcGIS Engine 초보자나 Geodatabase 개발에 관심이 있는 친구에게 적용됩니다. 만약에 Engine 버전이 9.3.1보다 높으면 관련 인터페이스가 바뀔 수 있습니다. 이것은 사용자 스스로 수정해야 하지만 똑똑한 사용자는 코드의 허용 여부에 국한되지 않습니다. 다른 사람의 인터페이스 사용 방법을 배울 수도 있습니다.모델을 개발하는 것이 가장 중요하다.
버전 인터페이스 차이점 참조:http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Type_changes_between_9_3_and_10/000100000408000000/
다음 예는 주로 코드를 사용하여 관계 클래스를 만드는 것이다
using System;
using System.IO;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
namespace EditingDemo
{
public class EditingDemo
{
public static void Main(string[] args)
{
#region Licensing
// Set up the licencing. NOTE: This sample assumes that you are using ArcInfo Desktop.
// You will need to adjust this code if using ArcEngine or ArcEditor.
IAoInitialize aoInitialize = new AoInitializeClass();
esriLicenseStatus licenseStatus = aoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo);
if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
{
Console.WriteLine("Unable to check-out an ArcInfo license, error code is {0}", licenseStatus);
return;
}
#endregion
#region Data Setup
// If any data is leftover from previous runs, delete it.
if (Directory.Exists("Riverside.gdb"))
{
Directory.Delete("Riverside.gdb", true);
}
// Copy the geodatabase from the data directory to this directory.
Type tempFactoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
IWorkspaceFactory tempWorkspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(tempFactoryType);
IWorkspaceName sourceWorkspace = new WorkspaceNameClass
{
PathName = @"..\..\..\Data\Riverside.gdb",
WorkspaceFactoryProgID = "esriDataSourcesGDB.FileGDBWorkspaceFactory"
};
IWorkspaceName copiedWorkspace = null;
tempWorkspaceFactory.Copy(sourceWorkspace, Environment.CurrentDirectory, out copiedWorkspace);
#endregion
try
{
// Open the test data.
Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
IWorkspace workspace = workspaceFactory.OpenFromFile("Riverside.gdb", 0);
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
// Open the feature classes that will participate in the relationship class.
IFeatureClass polesFeatureClass = featureWorkspace.OpenFeatureClass("Utility_Poles");
IFeatureClass transformersFeatureClass = featureWorkspace.OpenFeatureClass("Transformers");
// Open the feature dataset where the relationship class will be stored.
IFeatureDataset featureDataset = featureWorkspace.OpenFeatureDataset("Electric");
IRelationshipClassContainer relClassContainer = (IRelationshipClassContainer)featureDataset;
// Create a composite relationship class.
IRelationshipClass relationshipClass = relClassContainer.CreateRelationshipClass("PolesToTransformers",
polesFeatureClass, transformersFeatureClass, "supports", "is located on",
esriRelCardinality.esriRelCardinalityOneToMany, esriRelNotification.esriRelNotificationForward,
true, false, null, "Pole_ID", "", "Pole_ID", "");
// Set the first relationship class rule.
// One Pole (subtype: Wood) can hold a minimum of 0 and a maximum of 3 transformers.
// A Transformer must be related to one and only one Utility Pole.
IRelationshipRule relationshipRule = new RelationshipRuleClass
{
OriginClassID = polesFeatureClass.ObjectClassID,
OriginSubtypeCode = 1, // Wooden pole subtype
OriginMaximumCardinality = 1,
OriginMinimumCardinality = 1,
DestinationClassID = transformersFeatureClass.ObjectClassID,
DestinationSubtypeCode = 0,
DestinationMaximumCardinality = 3,
DestinationMinimumCardinality = 0
};
// Add the rule to the relationship class.
relationshipClass.AddRelationshipRule(relationshipRule);
// Set the second relationship class rule.
// One Pole (subtype: Steel) can hold a minimum of 0 and a maximum of 5 transformers,
// a Transformer must be related to one and only one Utility Pole.
IRelationshipRule relationshipRule2 = new RelationshipRuleClass
{
OriginClassID = polesFeatureClass.ObjectClassID,
OriginSubtypeCode = 2, // Steel pole subtype
OriginMaximumCardinality = 1,
OriginMinimumCardinality = 1,
DestinationClassID = transformersFeatureClass.ObjectClassID,
DestinationSubtypeCode = 0,
DestinationMaximumCardinality = 5,
DestinationMinimumCardinality = 0
};
relationshipClass.AddRelationshipRule(relationshipRule2);
// Validate the relationship rules to identify invalid features.
IValidation validation = (IValidation)polesFeatureClass;
ISelectionSet selectionSet = validation.Validate(null, null);
Console.WriteLine("There are {0} features that are violating the relationship rules.", selectionSet.Count);
// Display the Object IDs of poles that are violating the relationship rules.
IEnumIDs enumIDs = selectionSet.IDs;
enumIDs.Reset();
int oid = -1;
while ((oid = enumIDs.Next()) != -1)
{
Console.WriteLine("Invalid Pole OID = {0}", oid);
}
}
catch (COMException ComEx)
{
Console.WriteLine("An error occurred: {0}, Error Code: {1}", ComEx.Message, ComEx.ErrorCode);
}
catch (Exception exc)
{
Console.WriteLine("An error occurred: {0}", exc.Message);
}
finally
{
Console.WriteLine("Done.");
}
aoInitialize.Shutdown();
}
}
}
관련 소스 코드 및 테스트 데이터
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.