ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data.Topology Namespace / TopologyGraph Class / FindClosestElement<T> Method
The type of topological element.
The location used to find the nearest topological element to it.
The search radius units for queryPoint.
Example

In This Topic
    FindClosestElement<T> Method
    In This Topic
    Finds a topological element in the topology graph closest to the location specified by queryPoint that is also within searchRadius units. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Function FindClosestElement(Of T As TopologyElement)( _
       ByVal queryPoint As MapPoint, _
       ByVal searchRadius As Double _
    ) As T
    public T FindClosestElement<T>( 
       MapPoint queryPoint,
       double searchRadius
    )
    where T: TopologyElement

    Parameters

    queryPoint
    The location used to find the nearest topological element to it.
    searchRadius
    The search radius units for queryPoint.

    Type Parameters

    T
    The type of topological element.

    Return Value

    The topological element of type T nearest to queryPoint if it exists; otherwise, null.
    Exceptions
    ExceptionDescription
    A geodatabase-related exception has occurred.
    Example
    Find closest element from a topology graph
    {
      static void FindClosestElement()
      {
        using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\TestData\GrandTeton.gdb"))))
        using (ArcGIS.Core.Data.Topology.Topology topology = geodatabase.OpenDataset<ArcGIS.Core.Data.Topology.Topology>("Backcountry_Topology"))
        {
          // Build a topology graph using the extent of the topology dataset.
          topology.BuildGraph(topology.GetExtent(), (topologyGraph) =>
          {
            MapPoint queryPointViaCampsites12 = null;
    
            using (Feature campsites12 = GetFeature(geodatabase, "Campsites", 12))
            {
              queryPointViaCampsites12 = campsites12.GetShape() as MapPoint;
            }
    
            double searchRadius = 1.0;
    
            TopologyElement topologyElementViaCampsites12 = topologyGraph.FindClosestElement<TopologyElement>(queryPointViaCampsites12, searchRadius);
            IReadOnlyList<FeatureInfo> parentFeatures = topologyElementViaCampsites12.GetParentFeatures();
    
            Console.WriteLine("The parent features that spawn 'topologyElementViaCampsites12' are:");
            foreach (FeatureInfo parentFeature in parentFeatures)
            {
              Console.WriteLine($"\t{parentFeature.FeatureClassName}; OID: {parentFeature.ObjectID}");
            }
    
            TopologyNode topologyNodeViaCampsites12 = topologyGraph.FindClosestElement<TopologyNode>(queryPointViaCampsites12, searchRadius);
    
            if (topologyNodeViaCampsites12 != null)
            {
              // There exists a TopologyNode nearest to the query point within searchRadius units.
            }
    
            TopologyEdge topologyEdgeViaCampsites12 = topologyGraph.FindClosestElement<TopologyEdge>(queryPointViaCampsites12, searchRadius);
    
            if (topologyEdgeViaCampsites12 != null)
            {
              // There exists a TopologyEdge nearest to the query point within searchRadius units.
            }
          });
        }
      }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also