Showing topology erros on map.

Discussion created by tobe81cwb on Mar 20, 2012
Latest reply on Mar 20, 2012 by tobe81cwb
Hello all,

I'm having a little problem with my program.

My map is on a geodatabase, and I'm creating a topology programmatically, with all the rules, and validations.
Then, if the topology have any error, show a message to the user, and I like to show the topology error on map too.

But my problem is, how I add the topology to the TOC?
Maybe is simple, maybe not, but I don't know how!

Any help?

My code:
// connect to the ArcSDE
IWorkspace workSpace = ArcSDEWorkspace(connectionsProperty);

// create a workspace
IFeatureWorkspace featureWorkspace = workSpace as IFeatureWorkspace;

// open the feature dataset
IFeatureDataset featureDataset = featureWorkspace.OpenFeatureDataset("TopologyTest");

// get the feature classes
IFeatureClass ShapeA = featureWorkspace.OpenFeatureClass("ShapeA");
IFeatureClass ShapeB = featureWorkspace.OpenFeatureClass("ShapeB");

// lock
ISchemaLock schemaLock = featureDataset as ISchemaLock;


    // create the topology
    ITopologyContainer2 topologyContainer = featureDataset as ITopologyContainer2;
    ITopology topology = topologyContainer.CreateTopology("tpTest", topologyContainer.DefaultClusterTolerance, -1, "");

    // add the feature class to the topology
    topology.AddClass(ShapeA, 5, 1, 1, false);
    topology.AddClass(ShapeB, 5, 1, 1, false);

    // add the rules
    AddRuleToTopology(topology, esriTopologyRuleType.esriTRTAreaCoveredByArea, "My Rule", ShapeB, 1, ShapeA, 1);

    // validate topology
    IGeoDataset geoDataset = topology as IGeoDataset;
    IEnvelope envelope = geoDataset.Extent;
    ValidateTopology(topology, envelope);

    // check if the topology has some error
    if (topology.State == esriTopologyState.esriTSAnalyzedWithErrors)
        // TODO: add the topology to the current document!! HOW!?
        System.Windows.Forms.MessageBox.Show("No error!");
catch (Exception ex)
    // unlock