Showing topology erros on map.

523
1
03-20-2012 07:04 AM
RobertoOliveira
New Contributor III
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;

try
{
    schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

    // 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)
    {
        System.Windows.Forms.MessageBox.Show("Error!");
        // TODO: add the topology to the current document!! HOW!?
    }
    else
        System.Windows.Forms.MessageBox.Show("No error!");
}
catch (Exception ex)
{
 ...
}
finally
{
    // unlock
    schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
}
0 Kudos
1 Reply
RobertoOliveira
New Contributor III
Forget, it's more simple than I thought.

Only think that I want is add the topology in the current document, and this is how I made:

// current document
IMap map = ArcMap.Document.ActiveView.FocusMap;

// create a topologyLayer
ITopologyLayer topologyLayer = new TopologyLayerClass();
topologyLayer.Topology = topology;

// create a layer from topology
ILayer tpErrors = topologyLayer as ILayer;
tpErrors.Name = "Errors";

// finally, add the layer
map.AddLayer(tpErrors);
0 Kudos