public static void Subtract(ITopology pTopology, ITopologyErrorFeature pTopoErrorFeat) { IGeometry geometry; string[] strArray; frmSelectMergeFeature feature3; IFeatureClass class2 = (pTopology as IFeatureClassContainer).get_ClassByID(pTopoErrorFeat.OriginClassID); IFeatureClass class3 = null; try { if (pTopoErrorFeat.DestinationClassID != 0) { class3 = (pTopology as IFeatureClassContainer).get_ClassByID(pTopoErrorFeat.DestinationClassID); } } catch { } IFeature feature = null; IFeature feature2 = null; ITopologicalOperator shapeCopy = null; switch (pTopoErrorFeat.TopologyRuleType) { case esriTopologyRuleType.esriTRTAreaNoOverlap: feature = class2.GetFeature(pTopoErrorFeat.OriginOID); feature2 = class2.GetFeature(pTopoErrorFeat.DestinationOID); geometry = (feature.ShapeCopy as ITopologicalOperator).Difference((pTopoErrorFeat as IFeature).Shape); if (!geometry.IsEmpty) { feature.Shape = geometry; feature.Store(); break; } feature.Delete(); break; case esriTopologyRuleType.esriTRTAreaCoveredByAreaClass: feature = class2.GetFeature(pTopoErrorFeat.OriginOID); shapeCopy = feature.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Difference((pTopoErrorFeat as IFeature).Shape); if (!geometry.IsEmpty) { feature.Shape = geometry; feature.Store(); return; } feature.Delete(); return; case esriTopologyRuleType.esriTRTAreaAreaCoverEachOther: strArray = new string[] { class2.AliasName + "-" + pTopoErrorFeat.OriginOID, class3.AliasName + "-" + pTopoErrorFeat.DestinationOID }; feature3 = new frmSelectMergeFeature { FeatureInfos = strArray, Text = "删除" }; if (feature3.ShowDialog() == DialogResult.OK) { feature = class2.GetFeature(pTopoErrorFeat.OriginOID); feature2 = class3.GetFeature(pTopoErrorFeat.DestinationOID); if (feature3.SelectedIndex != 0) { shapeCopy = feature2.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Difference((pTopoErrorFeat as IFeature).Shape); if (geometry.IsEmpty) { feature2.Delete(); } else { feature2.Shape = geometry; feature2.Store(); } return; } shapeCopy = feature.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Difference((pTopoErrorFeat as IFeature).Shape); if (!geometry.IsEmpty) { feature.Shape = geometry; feature.Store(); return; } feature.Delete(); } return; case ((esriTopologyRuleType)6): case (esriTopologyRuleType.esriTRTAreaNoOverlapArea | esriTopologyRuleType.esriTRTAreaNoGaps): return; case esriTopologyRuleType.esriTRTAreaCoveredByArea: if (pTopoErrorFeat.OriginOID <= 0) { feature2 = class3.GetFeature(pTopoErrorFeat.DestinationOID); geometry = (feature2.ShapeCopy as ITopologicalOperator).Difference((pTopoErrorFeat as IFeature).Shape); if (geometry.IsEmpty) { feature2.Delete(); } else { feature2.Shape = geometry; feature2.Store(); } return; } feature = class2.GetFeature(pTopoErrorFeat.OriginOID); geometry = (feature.ShapeCopy as ITopologicalOperator).Difference((pTopoErrorFeat as IFeature).Shape); if (!geometry.IsEmpty) { feature.Shape = geometry; feature.Store(); return; } feature.Delete(); return; case esriTopologyRuleType.esriTRTAreaNoOverlapArea: feature = class2.GetFeature(pTopoErrorFeat.OriginOID); feature2 = class3.GetFeature(pTopoErrorFeat.DestinationOID); geometry = (feature.ShapeCopy as ITopologicalOperator).Difference((pTopoErrorFeat as IFeature).Shape); if (!geometry.IsEmpty) { feature.Shape = geometry; feature.Store(); } else { feature.Delete(); } geometry = (feature2.ShapeCopy as ITopologicalOperator).Difference((pTopoErrorFeat as IFeature).Shape); if (geometry.IsEmpty) { feature2.Delete(); } else { feature2.Shape = geometry; feature2.Store(); } return; case esriTopologyRuleType.esriTRTLineCoveredByAreaBoundary: feature = class2.GetFeature(pTopoErrorFeat.OriginOID); shapeCopy = feature.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Difference((pTopoErrorFeat as IFeature).Shape); if (!geometry.IsEmpty) { feature.Shape = geometry; feature.Store(); return; } feature.Delete(); return; case esriTopologyRuleType.esriTRTLineNoOverlap: strArray = new string[] { class2.AliasName + "-" + pTopoErrorFeat.OriginOID, class2.AliasName + "-" + pTopoErrorFeat.DestinationOID }; feature3 = new frmSelectMergeFeature { FeatureInfos = strArray }; if (feature3.ShowDialog() == DialogResult.OK) { feature = class2.GetFeature(pTopoErrorFeat.OriginOID); feature2 = class2.GetFeature(pTopoErrorFeat.DestinationOID); if (feature3.SelectedIndex != 0) { shapeCopy = feature2.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Difference((pTopoErrorFeat as IFeature).Shape); if (geometry.IsEmpty) { feature2.Delete(); } else { feature2.Shape = geometry; feature2.Store(); } return; } shapeCopy = feature.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Difference((pTopoErrorFeat as IFeature).Shape); if (!geometry.IsEmpty) { feature.Shape = geometry; feature.Store(); return; } feature.Delete(); } return; case esriTopologyRuleType.esriTRTLineNoIntersection: strArray = new string[] { class2.AliasName + "-" + pTopoErrorFeat.OriginOID, class2.AliasName + "-" + pTopoErrorFeat.DestinationOID }; feature3 = new frmSelectMergeFeature { FeatureInfos = strArray }; if (feature3.ShowDialog() == DialogResult.OK) { feature = class2.GetFeature(pTopoErrorFeat.OriginOID); feature2 = class2.GetFeature(pTopoErrorFeat.DestinationOID); if (feature3.SelectedIndex != 0) { shapeCopy = feature2.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Difference((pTopoErrorFeat as IFeature).Shape); if (geometry.IsEmpty) { feature2.Delete(); } else { feature2.Shape = geometry; feature2.Store(); } return; } shapeCopy = feature.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Difference((pTopoErrorFeat as IFeature).Shape); if (!geometry.IsEmpty) { feature.Shape = geometry; feature.Store(); return; } feature.Delete(); } return; case esriTopologyRuleType.esriTRTLineNoIntersectOrInteriorTouch: strArray = new string[] { class2.AliasName + "-" + pTopoErrorFeat.OriginOID, class2.AliasName + "-" + pTopoErrorFeat.DestinationOID }; feature3 = new frmSelectMergeFeature { FeatureInfos = strArray, Text = "删除" }; if (feature3.ShowDialog() == DialogResult.OK) { feature = class2.GetFeature(pTopoErrorFeat.OriginOID); feature2 = class2.GetFeature(pTopoErrorFeat.DestinationOID); if (feature3.SelectedIndex != 0) { geometry = (feature2.ShapeCopy as ITopologicalOperator).Difference( (pTopoErrorFeat as IFeature).Shape); if (geometry.IsEmpty) { feature2.Delete(); } else { feature2.Shape = geometry; feature2.Store(); } return; } geometry = (feature.ShapeCopy as ITopologicalOperator).Difference((pTopoErrorFeat as IFeature).Shape); if (geometry.IsEmpty) { feature.Delete(); } else { feature.Shape = geometry; feature.Store(); } } return; default: return; } geometry = (feature2.ShapeCopy as ITopologicalOperator).Difference((pTopoErrorFeat as IFeature).Shape); if (geometry.IsEmpty) { feature2.Delete(); } else { feature2.Shape = geometry; feature2.Store(); } }
public static void Merge(ITopology pTopology, ITopologyErrorFeature pTopoErrorFeat) { frmSelectMergeFeature feature; IGeometry geometry; IFeature feature2; IFeature feature3; ITopologicalOperator shapeCopy; IFeatureClass class2 = (pTopology as IFeatureClassContainer).get_ClassByID(pTopoErrorFeat.OriginClassID); IFeatureClass class3 = null; try { if (pTopoErrorFeat.DestinationClassID != 0) { class3 = (pTopology as IFeatureClassContainer).get_ClassByID(pTopoErrorFeat.DestinationClassID); } } catch { } string[] strArray = new string[2]; switch (pTopoErrorFeat.TopologyRuleType) { case esriTopologyRuleType.esriTRTAreaNoOverlap: strArray[0] = class2.AliasName + "-" + pTopoErrorFeat.OriginOID; strArray[1] = class2.AliasName + "-" + pTopoErrorFeat.DestinationOID; feature = new frmSelectMergeFeature { FeatureInfos = strArray }; if (feature.ShowDialog() == DialogResult.OK) { feature2 = class2.GetFeature(pTopoErrorFeat.OriginOID); feature3 = class2.GetFeature(pTopoErrorFeat.DestinationOID); if (feature.SelectedIndex == 0) { shapeCopy = feature2.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Union(feature3.Shape); feature2.Shape = geometry; feature2.Store(); feature3.Delete(); } else { shapeCopy = feature3.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Union(feature2.Shape); feature3.Shape = geometry; feature3.Store(); feature2.Delete(); } } break; case esriTopologyRuleType.esriTRTAreaNoOverlapArea: strArray[0] = class2.AliasName + "-" + pTopoErrorFeat.OriginOID; strArray[1] = class3.AliasName + "-" + pTopoErrorFeat.DestinationOID; feature = new frmSelectMergeFeature { FeatureInfos = strArray }; if (feature.ShowDialog() == DialogResult.OK) { feature2 = class2.GetFeature(pTopoErrorFeat.OriginOID); feature3 = class3.GetFeature(pTopoErrorFeat.DestinationOID); if (feature.SelectedIndex == 0) { shapeCopy = feature2.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Union(feature3.Shape); feature2.Shape = geometry; feature2.Store(); feature3.Delete(); } else { shapeCopy = feature3.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Union(feature2.Shape); feature3.Shape = geometry; feature3.Store(); feature2.Delete(); } } break; case esriTopologyRuleType.esriTRTLineNoPseudos: strArray[0] = class2.AliasName + "-" + pTopoErrorFeat.OriginOID; strArray[1] = class3.AliasName + "-" + pTopoErrorFeat.DestinationOID; feature = new frmSelectMergeFeature { FeatureInfos = strArray }; if (feature.ShowDialog() == DialogResult.OK) { feature2 = class2.GetFeature(pTopoErrorFeat.OriginOID); feature3 = class3.GetFeature(pTopoErrorFeat.DestinationOID); if (feature.SelectedIndex == 0) { shapeCopy = feature2.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Union(feature3.Shape); feature2.Shape = geometry; feature2.Store(); feature3.Delete(); } else { geometry = (feature3.ShapeCopy as ITopologicalOperator).Union(feature2.Shape); feature3.Shape = geometry; feature3.Store(); feature2.Delete(); } } break; } }