ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / BasicFeatureLayer Class / GetFeatureOutline Method
The viewer on which the layer's features are being displayed
The type of outline to generate (from which features)
Example

In This Topic
    GetFeatureOutline Method
    In This Topic
    Get an outline geometry created from the geometries of the set of input features. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Function GetFeatureOutline( _
       ByVal view As MapView, _
       ByVal outlineType As FeatureOutlineType _
    ) As Geometry
    public Geometry GetFeatureOutline( 
       MapView view,
       FeatureOutlineType outlineType
    )

    Parameters

    view
    The viewer on which the layer's features are being displayed
    outlineType
    The type of outline to generate (from which features)

    Return Value

    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    MapView is null
    Unsupported geometry type
    Feature outline failed.
    Remarks
    The view must be initialized or null will be returned. The layer must be set visible in the view (i.e. visibility turned "on"). The outline geometry will be created from all the features, just the selected features, or just the features visible within the current view extent (FeatureOutlineType.All, Selected, or Visible respectively). The feature outline geometry is returned in the spatial reference of the input mapview's associated Map
    Note: A null geometry can be returned, for example, FeatureOutlineType.Selected and no features are selected, FeatureOutlineType.Visible and no features are visible within the current view extent, and so on.
    Feature layers with Multipatch geometry type are not supported.
    Example
    Querying a feature layer with a spatial filter
    {
        var layers = map.GetLayersAsFlattenedList().OfType<FeatureLayer>();
        var layerToQuery = layers.FirstOrDefault(f => f.Name == "USNationalParks");
        if (layerToQuery == null) return;
    
        string whereClause = "RecreationVisitsTotal > 1000000"; //More than million visitors a year
    
        var spatialDefnLayer = layers.FirstOrDefault(f => f.Name == "AllUSStates");
        if (spatialDefnLayer == null) return;
        try
        {
            if (MapView.Active == null) return;
            //Note: needs to be called on the MCT
            // Set the spatial filter geometry
            //Get the geometry from the selected features in the feature layer
            var spatialClauseGeom = spatialDefnLayer.GetFeatureOutline(MapView.Active, FeatureOutlineType.Selected);
            //Create the definition query
            DefinitionQuery definitionQuery = new DefinitionQuery
            {
                WhereClause = whereClause,
                Name = $"{layerToQuery.Name}"
            };
            //Setting the spatial filter to the Definition Query
            if (definitionQuery.CanSetFilterGeometry(spatialClauseGeom))
            {
                definitionQuery.SetFilterGeometry(spatialClauseGeom);
            }
    
            layerToQuery.InsertDefinitionQuery(definitionQuery);
            layerToQuery.SetActiveDefinitionQuery(definitionQuery.Name);
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine($"Error querying feature layer: {ex.Message}");
        }
    }
    Apply A Definition Query Filter With a Filter Geometry to a Feature Layer
    {
        var greatLakes = map.GetLayersAsFlattenedList()
              .OfType<FeatureLayer>().First(l => l.Name == "Great Lakes");
        var usa_states = map.GetLayersAsFlattenedList()
        .OfType<FeatureLayer>().First(l => l.Name == "US_States");
        //name must be unique
        var def_query = new DefinitionQuery("GreatLakes",
                              "NAME in ('Huron','Michigan','Erie')");
    
        //create a filter geometry - in this example we will use the outline geometry
        //of all visible features from a us states layer...the filter geometry will be
        //intersected with the layer feature geometry when added to the def query
        var filter_geom = usa_states.GetFeatureOutline(mapView, FeatureOutlineType.Visible);
        //other options...
        //var filter_geom = usa_states.GetFeatureOutline(mapView, FeatureOutlineType.All);
        //var filter_geom = usa_states.GetFeatureOutline(mapView, FeatureOutlineType.Selected);
    
        //Geometry must have a valid SR and be point, multi-point, line, or poly
        //Note: needs to be called on the MCT
        if (def_query.CanSetFilterGeometry(filter_geom))
        {
            def_query.SetFilterGeometry(filter_geom);
        }
    
        //Apply the def query
        greatLakes.InsertDefinitionQuery(def_query);
        //Set it active
        greatLakes.SetActiveDefinitionQuery(def_query.Name);
    
        //or....also - set it active when it is inserted
        //greatLakes.InsertDefinitionQuery(def_query, true);
    }
    Get Feature Outlines from a Feature Layer
    {
        var greatLakes = map.GetLayersAsFlattenedList()
              .OfType<FeatureLayer>().First(l => l.Name == "Great Lakes");
        var michigan = map.GetBookmarks().First(b => b.Name == "Michigan");
    
        //get all features - multiple feature geometries are always returned as a
        //single multi-part
        var all_features_outline = greatLakes.GetFeatureOutline(mapView, FeatureOutlineType.All);
    
        //or get just the outline of selected features
        var qry = new QueryFilter()
        {
            SubFields = "*",
            WhereClause = "NAME in ('Huron','Michigan','Erie')"
        };
        greatLakes.Select(qry);
        var sel_features_outline = greatLakes.GetFeatureOutline(
            mapView, FeatureOutlineType.Selected);
        greatLakes.ClearSelection();
    
        //or just the visible features
        mapView?.ZoomTo(michigan);
        var visible_features_outline = greatLakes.GetFeatureOutline(
            mapView, FeatureOutlineType.Visible);
    }
    Requirements

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

    ArcGIS Pro version: 3.5 or higher.
    See Also