private ITopology mTopology;
private IEnvelope mValidateEnvelope;
public void UpdateTopologyResult(ITopology pTopology,IEnvelope pEnvelope)
{
this.mTopology = pTopology;
this.mValidateEnvelope = pEnvelope;
this.UpdateTopologyResult();
}
private void UpdateTopologyResult()
{
this.lvErrors.Items.Clear();
if (this.mTopology == null) return;
if (this.mValidateEnvelope == null
|| this.mValidateEnvelope.IsEmpty )
{
this.mValidateEnvelope = (this.mTopology as IGeoDataset).Extent;
}
IErrorFeatureContainer ArcGIS EnginerrorContainer = this.mTopology as IErrorFeatureContainer;
if (ArcGIS EnginerrorContainer == null) return;
List<ITopologyErrorFeature> ArcGIS EnginerrorList = new List<ITopologyErrorFeature>();
List<esriTopologyRuleType> aTypeList = new List<esriTopologyRuleType>();
#region 获取规则类型
ITopologyRuleContainer aRuleList = this.mTopology as ITopologyRuleContainer;
I
EnumRule aRuleEnum = aRuleList.Rules;
ITopologyRule aRule = aRuleEnum.Next() as ITopologyRule ;
while (aRule != null)
{
if (!aTypeList.Contains(aRule.TopologyRuleType))
{
aTypeList.Add(aRule.TopologyRuleType);
}
aRule = aRuleEnum.Next() as ITopologyRule;
}
#endregion
#region 将错误提取到列表中
foreach (esriTopologyRuleType aRuleType in aTypeList)
{
try
{
IEnumTopologyErrorFeature ArcGIS EnginenumErrorFeature = ArcGIS EnginerrorContainer.get_ErrorFeaturesByRuleType
(this.mEditor.MapControl.SpatialReference
, aRuleType, this.mValidateEnvelope, true, true);
ITopologyErrorFeature ArcGIS EnginerrorFeature = ArcGIS EnginenumErrorFeature.Next();
while (ArcGIS Engine
rrorFeature != null)
{
ArcGIS EnginerrorList.Add(ArcGIS EnginerrorFeature);
ArcGIS EnginerrorFeature = ArcGIS EnginenumErrorFeature.Next();
}
}
catch (Exception ex) { }
}
#endregion
#region 将错误显示出来
int idx = 0;
this.lvErrors .BeginUpdate ();
foreach (ITopologyErrorFeature ArcGIS EnginerrorFeature in ArcGIS EnginerrorList)
{
idx++;
ITopologyRule aTopRule = ArcGIS EnginerrorFeature.TopologyRule as ITopologyRule;
ListViewItem aItem = new ListViewItem(idx.ToString());
aItem.SubItems.Add(this.TranslateTopologyRule (ArcGIS EnginerrorFeature .TopologyRule as ITopologyRule ));
aItem.SubItems.Add(this.GetFeatureClassName(aTopRule.OriginClassID));
aIt
em.SubItems.Add(ArcGIS EnginerrorFeature.OriginOID.ToString());
aItem.SubItems.Add(this.GetFeatureClassName(aTopRule.DestinationClassID));
aItem.SubItems.Add(ArcGIS EnginerrorFeature.DestinationOID.ToString());
aItem.SubItems.Add(GeometryHelper.ShapeTypeName(ArcGIS EnginerrorFeature.ShapeType));
if(idx%2==0)
aItem.BackColor =Color.Wheat ;
aItem.Tag = ArcGIS EnginerrorFeature;
this.lvErrors .Items.Add (aItem);
}
this.lvErrors .EndUpdate ();
#endregion
}
private void btnSearch_Click(object sender, EventArgs e)
{
this.UpdateTopologyResult();
}
private string TranslateTopologyRule(ITopologyRule aRule)
{
string srcClassName = this.GetFeatureClassName(aRule.OriginClassID);
string destClassName = this.GetFeatureClassName(aRule.DestinationClassID);
string rRuleName = aRule.TopologyRuleType.ToString();
switch (aRule.TopologyRuleType)
{
case esriTopologyRuleType.esriTRTAreaNoOverlap:
{
rRuleName = srcClassName + "不能互相覆盖";
break;
}
case esriTopologyRuleType.esriTRTAreaBoundaryCoveredByLine:
{
rRuleName = srcClassName + "边界必须被" + destClassName + "覆盖";
break;
}
case esriTopologyRuleType.esriTRTLineNoOverlap:rRuleName = srcClassName + "不能互相叠合";
break;
}
case esriTopologyRuleType.esriTRTLineCoveredByAreaBoundary:
{
&n
bsp; rRuleName = srcClassName + "必须压在" + destClassName + "边界上";
break;
}
default:
{
rRuleName = aRule.TopologyRuleType.ToString();
break;
}
}
return rRuleName;
}
private Dictionary<int, IFeatureClass> mClassTable=new Dictionary<int,IFeatureClass> ();
private IFeatureClass OpenFeatureClass(int pID)
{
IFeatureClass rClass = null;
if (mClassTable.ContainsKey(pID))
{
rClass= mClassTable[pID];
}
else
{
rClass=DatabaseHelper.GetFeatureClass(this.FeatureWorkspace as IWorkspace
, pID);
this.mClassTable[pID] = rClass;
}
return rClass;
}
private string GetFeatureClassName(int pID)
{
IFeatureClass aClass = this.OpenFeatureClass(pID);
if (aClass == null) return "";
return aClass.AliasName;
}
public static IFeatureClass GetFeatureClass(IWorkspace pWorkspace, int pID)
{
IFeatureClass rClassObj=null;
IFeatureWorkspace wkSpace = pWorkspace as IFeatureWorkspace;
if (wkSpace == null) return null;
List<string> aContainerList = QueryFeatureDatasetName(pWorkspace, true, true);
foreach (string aContainer in aContainerList)
{
try
{
IFeatureDataset fds = wkSpace.OpenFeatureDataset(aContainer);
IFeatureClassContainer aContainerObj = fds as IFeatureClassContainer;
rClassObj = aConta
inerObj.get_ClassByID(pID);
if (rClassObj != null)
break;
}
catch (Exception ex) { }
}
return rClassObj;
}