|
- public void CreateTopology()
- {
- // Open the workspace and the required datasets.
- Type factoryType = Type.GetTypeFromProgID(
- "esriDataSourcesGDB.FileGDBWorkspaceFactory");
- IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance
- (factoryType);
- IWorkspace workspace = workspaceFactory.OpenFromFile(@
- "C:\arcgis\ArcTutor\BuildingaGeodatabase\Montgomery.gdb", 0);
- IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
- IFeatureDataset featureDataset = featureWorkspace.OpenFeatureDataset("Landbase");
- IFeatureClass blocksFC = featureWorkspace.OpenFeatureClass("Blocks");
- IFeatureClass parcelsFC = featureWorkspace.OpenFeatureClass("Parcels");
-
- // Attempt to acquire an exclusive schema lock on the feature dataset.
- ISchemaLock schemaLock = (ISchemaLock)featureDataset;
- try
- {
- schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
-
- // Create the topology.
- ITopologyContainer2 topologyContainer = (ITopologyContainer2)featureDataset;
- ITopology topology = topologyContainer.CreateTopology("Landbase_Topology",
- topologyContainer.DefaultClusterTolerance, - 1, "");
-
- // Add feature classes and rules to the topology.
- topology.AddClass(blocksFC, 5, 1, 1, false);
- topology.AddClass(parcelsFC, 5, 1, 1, false);
-
- AddRuleToTopology1(topology, esriTopologyRuleType.esriTRTAreaNoOverlap,
- "No Block Overlap", blocksFC);
-
- AddRuleToTopology2(topology,
- esriTopologyRuleType.esriTRTAreaCoveredByAreaClass,
- "ResParcels Covered by ResBlocks", parcelsFC, 1, blocksFC, 1);
- //上面两个拓扑方法如果有需要我再上传,个人觉得没有多大的问题
-
- // 验证拓扑规则
- IGeoDataset geoDataset = (IGeoDataset)topology;
- IEnvelope envelope = geoDataset.Extent;
- ValidateTopology(topology, envelope);
- }
- catch (COMException comExc)
- {
- throw new Exception(String.Format(
- "Error creating topology: {0} Message: {1}", comExc.ErrorCode,
- comExc.Message), comExc);
- }
- finally
- {
- schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
- }
- }
复制代码 但问题是:好像在拓扑规则添加的时候出了点问题(个人感觉可能是软件自身的问题),请看截图。
1是我用AE编写的代码添加的,2是我用AE自带的拓扑添加功能添加的,两者差别不用我说。我认为最有可能出错的地方就是这里了~恳请各位大侠能不吝赐教
|
|