AE拓扑检查原理

1.创建拓扑

2.选择参与拓扑的要素类

3.再向拓扑集添加拓扑规则(AddTopologyRule);

4.拓扑验证(Validate).


 

下面给出拓扑的核心代码,笔者经过试验,确实可行!

1.通过传入工作空间打开数据集;传入参与拓扑的要素类在数据集中的Index,从而把他们添加到拓扑集内部

 public ITopology create_topology(IWorkspace myWSp, string[] FCIndex, string TopologyName)
        {
            IEnumDataset myEDS = myWSp.get_Datasets(esriDatasetType.esriDTFeatureDataset);
            IDataset myDS = myEDS.Next();
            if (myDS != null)
            {
                DS_Name = myDS.Name;
                IFeatureDataset myFDS = myDS as IFeatureDataset;

                //IWorkspace myWSp = DS as IWorkspace;

                IFeatureClassContainer myFCContainer = myFDS as IFeatureClassContainer;
                //要素类容器
                ITopologyContainer myTopologyContainer = myFDS as ITopologyContainer;
                ITopology myTopology = myTopologyContainer.CreateTopology(TopologyName, myTopologyContainer.DefaultClusterTolerance, -1, "");
                int count = 0;
                while (count < FCIndex.Length)
                {
                    myTopology.AddClass(myFCContainer.get_Class(int.Parse(FCIndex[count])), 5, 1, 1, false);
                    count++;
                }
                return myTopology;
            }
            else
            {
                MessageBox.Show("Error,your Dataset is not a standar DataSet which can be uesed to created topology!");
                return null;
            }


        }

2.1(单要素拓扑)向拓扑集中添加拓扑规则。AddRuleToTopology1(拓扑集,拓扑规则枚举,规则名,拓扑要素类)

public void AddRuleToTopology1(ITopology topology, esriTopologyRuleType ruleType,
String ruleName, IFeatureClass featureClass)
        {
            // Create a topology rule.
            ITopologyRule topologyRule = new TopologyRuleClass();
            topologyRule.TopologyRuleType = ruleType;
            topologyRule.Name = ruleName;
            topologyRule.OriginClassID = featureClass.FeatureClassID;
            topologyRule.AllOriginSubtypes = true;

            // Cast the topology to the ITopologyRuleContainer interface and add the rule.
            ITopologyRuleContainer topologyRuleContainer = (ITopologyRuleContainer)topology;
            if (topologyRuleContainer.get_CanAddRule(topologyRule))
            {
                topologyRuleContainer.AddRule(topologyRule);
            }
            else
            {
                throw new ArgumentException("Could not add specified rule to the topology.");
            }
        

2.2(双要素拓扑)AddRuleToTopology2(拓扑集,Rule,拓扑规则名,Featureclass1(下面例子),Featureclass2)

例:如果要检查面只能包含一个点,Featureclass1:面,Rule:AreaContainOnePoint,Featureclass2:点。

public void AddRuleToTopology2(ITopology topology, esriTopologyRuleType ruleType,String ruleName, 
I<span style="font-family: Arial, Helvetica, sans-serif;">FeatureClass originClass, IFeatureClass destinationClass)</span>
        {
            // Create a topology rule.
            ITopologyRule topologyRule = new TopologyRuleClass();
            topologyRule.TopologyRuleType = ruleType;
            topologyRule.Name = ruleName;
            topologyRule.OriginClassID = originClass.FeatureClassID;
            topologyRule.AllOriginSubtypes = true ;
            //topologyRule.OriginSubtype = originSubtype;
            topologyRule.DestinationClassID = destinationClass.FeatureClassID;
            topologyRule.AllDestinationSubtypes = true;
            //topologyRule.DestinationSubtype = destinationSubtype;

            // Cast the topology to the ITopologyRuleContainer interface and add the rule.
            ITopologyRuleContainer topologyRuleContainer = (ITopologyRuleContainer)topology;
          
                if (topologyRuleContainer.get_CanAddRule(topologyRule))
                {
                    topologyRuleContainer.AddRule(topologyRule);
                }
                else
                {
                    throw new ArgumentException("Could not add specified rule to the topology.");
                }
            
           
        }
3.拓扑验证 ValidateTopology(拓扑集,拓扑范围)

public void ValidateTopology(ITopology topology, IEnvelope envelope)
        {
            // Get the dirty area within the provided envelope.
            IPolygon locationPolygon = new PolygonClass();
            ISegmentCollection segmentCollection = (ISegmentCollection)locationPolygon;
            segmentCollection.SetRectangle(envelope);
            IPolygon polygon = topology.get_DirtyArea(locationPolygon);

            // If a dirty area exists, validate the topology.
            if (!polygon.IsEmpty)
            {
                // Define the area to validate and validate the topology.
                IEnvelope areaToValidate = polygon.Envelope;
                IEnvelope areaValidated = topology.ValidateTopology(areaToValidate);
            }
        }

这个是完全的的代码,写了好几天资源分10分 请酌情使用~

http://download.csdn.net/detail/u013523101/7709451


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值