ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Core.Data.Topology Namespace / Topology Class / Validate Method
The ValidationDescription which describes the details of the validate operation.
Example

In This Topic
    Validate Method (Topology)
    In This Topic
    Ensures data integrity by validating the features in a topology in the area specified by ValidationDescription.Extent against a pre-defined set of topology rules. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax

    Parameters

    description
    The ValidationDescription which describes the details of the validate operation.

    Return Value

    A ValidationResult that describes the result of the operation.
    Exceptions
    ExceptionDescription
    description is null.
    This operation cannot be invoked inside ArcGIS.Core.Data.Geodatabase.ApplyEdits or when an edit operation is in progress.
    A geodatabase-related exception has occurred.
    Remarks

    Dirty areas represent areas where the spatial integrity of the topology has not been validated. When a topology is first created, the entire dataset is considered dirty. Subsequently, dirty areas are created anytime a feature's geometry or subtype is modified or topology rules are added or removed. A topology validation is an operation to clean up dirty areas. The operation entails snapping features together within a cluster tolerance and test for rule violations. Any feature that violates one or more topology rules will result in a topology error, which can be marked (i.e., promoted) as an exception.

    This operation generates its own editing transaction and therefore cannot be wrapped inside a separate transaction.

    When writing an ArcGIS Pro add-in, the extension method ArcGIS.Core.Data.CoreDataExtensions.ValidateInEditOperation should be used instead. This extension method will create an edit operation on the Pro undo/redo stack and redraw any affected layers.

    Example
    ValidateTopology
    public void ValidateTopology()
    {
      using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\TestData\GrandTeton.gdb"))))
      using (Topology topology = geodatabase.OpenDataset<Topology>("Backcountry_Topology"))
      {
        // If the topology currently does not have dirty areas, calling Validate() returns an empty envelope.
    
        ValidationResult result = topology.Validate(new ValidationDescription(topology.GetExtent()));
        Console.WriteLine($"'AffectedArea' after validating a topology that has not been edited => {result.AffectedArea.ToJson()}");
    
        // Now create a feature that purposely violates the "PointProperlyInsideArea" topology rule.  This action will
        // create dirty areas.
    
        Feature newFeature = null;
    
        try
        {
          // Fetch the feature in the Campsites feature class whose objectID is 2.  Then create a new geometry slightly
          // altered from this and use it to create a new feature.
    
          using (Feature featureViaCampsites2 = GetFeature(geodatabase, "Campsites", 2))
          {
            Geometry currentGeometry = featureViaCampsites2.GetShape();
            Geometry newGeometry = GeometryEngine.Instance.Move(currentGeometry, (currentGeometry.Extent.XMax / 8),
              (currentGeometry.Extent.YMax / 8));
    
            using (FeatureClass campsitesFeatureClass = featureViaCampsites2.GetTable())
            using (FeatureClassDefinition definition = campsitesFeatureClass.GetDefinition())
            using (RowBuffer rowBuffer = campsitesFeatureClass.CreateRowBuffer())
            {
              rowBuffer[definition.GetShapeField()] = newGeometry;
    
              geodatabase.ApplyEdits(() =>
              {
                newFeature = campsitesFeatureClass.CreateRow(rowBuffer);
              });
            }
          }
    
          // After creating a new feature in the 'Campsites' participating feature class, the topology's state should be 
          // "Unanalyzed" because it has not been validated.
    
          Console.WriteLine($"The topology state after an edit has been applied => {topology.GetState()}");
    
          // Now validate the topology.  The result envelope corresponds to the dirty areas.
    
          result = topology.Validate(new ValidationDescription(topology.GetExtent()));
          Console.WriteLine($"'AffectedArea' after validating a topology that has just been edited => {result.AffectedArea.ToJson()}");
    
          // After Validate(), the topology's state should be "AnalyzedWithErrors" because the topology currently has errors.
    
          Console.WriteLine($"The topology state after validate topology => {topology.GetState()}");
    
          // If there are no dirty areas, the result envelope should be empty.
    
          result = topology.Validate(new ValidationDescription(topology.GetExtent()));
          Console.WriteLine($"'AffectedArea' after validating a topology that has just been validated => {result.AffectedArea.ToJson()}");
        }
        finally
        {
          if (newFeature != null)
          {
            geodatabase.ApplyEdits(() =>
            {
              newFeature.Delete();
            });
    
            newFeature.Dispose();
          }
        }
    
        // Validate again after deleting the newly-created feature.
    
        topology.Validate(new ValidationDescription(topology.GetExtent()));
      }
    }
    
    private Feature GetFeature(Geodatabase geodatabase, string featureClassName, long objectID)
    {
      using (FeatureClass featureClass = geodatabase.OpenDataset<FeatureClass>(featureClassName))
      {
        QueryFilter queryFilter = new QueryFilter()
        {
          ObjectIDs = new List<long>() { objectID }
        };
    
        using (RowCursor cursor = featureClass.Search(queryFilter))
        {
          System.Diagnostics.Debug.Assert(cursor.MoveNext());
          return (Feature)cursor.Current;
        }
      }
    }
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also