ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / FeatureSceneLayer Class / HasAssociatedFeatureService Property
Example

In This Topic
    HasAssociatedFeatureService Property
    In This Topic
    Gets whether the feature scene layer has an associated feature service.
    Syntax
    public bool HasAssociatedFeatureService {get;}
    Public ReadOnly Property HasAssociatedFeatureService As Boolean

    Property Value

    True if the feature scene layer has an associated feature service
    Example
    Determine if a FeatureSceneLayer supports editing
    {
      featSceneLayer = MapView.Active.Map.GetLayersAsFlattenedList()
                         .OfType<FeatureSceneLayer>().FirstOrDefault();
      if (!featSceneLayer.HasAssociatedFeatureService ||
          !featSceneLayer.IsEditable)
      {
        //not supported - exit the function
      }
      //TODO continue editing here...
    }
    Create a new Point feature in FeatureSceneLayer
    {
      //must support editing!
      if (!featSceneLayer.HasAssociatedFeatureService ||
          !featSceneLayer.IsEditable)
      {
        //not supported - exit the function
      }
    
      //Check geometry type...must be point in this example
      var editOp = new EditOperation()
      {
        Name = "Create new 3d point feature",
        SelectNewFeatures = true
      };
    
      var attributes = new Dictionary<string, object>();
      //mapPoint contains the new 3d point location
      attributes.Add("SHAPE", mapPoint);
      attributes.Add("TreeID", "1");
      editOp.Create(featSceneLayer, attributes);
      editOp.ExecuteAsync();
    }
    Delete all the selected features in FeatureSceneLayer
    {
      if (!featSceneLayer.HasAssociatedFeatureService ||
        !featSceneLayer.IsEditable)
      {
        return;
      }
      await QueuedTask.Run(() =>
      {
        var delOp = new EditOperation()
        {
          Name = "Delete selected features"
        };
        //Assuming we have a selection on the layer...
        delOp.Delete(featSceneLayer, featSceneLayer.GetSelection().GetObjectIDs());
        delOp.ExecuteAsync();
      });
    }
    Edit the attributes of a FeatureSceneLayer
    {
      //must support editing!
      if (!featSceneLayer.HasAssociatedFeatureService ||
          !featSceneLayer.IsEditable)
      {
        return;
      }
    
      await QueuedTask.Run(() =>
      {
        var editOp = new EditOperation()
        {
          Name = "Edit FeatureSceneLayer Attributes",
          SelectModifiedFeatures = true
        };
        //make an inspector
        var inspector = new Inspector();
        //get the attributes for the specified oid
        inspector.Load(featSceneLayer, oid);
        inspector["PermitNotes"] = "test";//modify
        editOp.Modify(inspector);
        editOp.Execute();//synchronous flavor
      });
    }
    Get the Associated Feature class
    {
      await QueuedTask.Run(() =>
      {
        if (featSceneLayer.HasAssociatedFeatureService)
        {
          using (var fc = featSceneLayer.GetFeatureClass())
          {
            //TODO query underlying feature class
          }
        }
      });
    }
    Select features via the MapView
    {
      //assume the geometry used in SelectFeaturesEx() is coming from a
      //map tool...
      //SketchType = SketchGeometryType.Rectangle;
      //SketchOutputMode = SketchOutputMode.Screen;
    
      var mapView = MapView.Active;
      if (mapView == null)
        return;
    
      await QueuedTask.Run(() =>
      {
        var result = mapView.SelectFeaturesEx(geometry);
        //Get scene layers with selections
        var scene_layers = result.ToDictionary<FeatureSceneLayer>();
        foreach (var kvp in scene_layers)
        {
          var scene_layer = kvp.Key as FeatureSceneLayer;
          var sel_oids = kvp.Value;
          //If there are attributes then get them
          if (scene_layer.HasAssociatedFeatureService)
          {
            var insp = new Inspector();
            foreach (var objectid in sel_oids)
            {
              insp.Load(scene_layer, objectid);
              //TODO something with retrieved attributes
            }
          }
        }
      });
    }
    Has Associated FeatureService
    {
      if (featSceneLayer.HasAssociatedFeatureService)
      {
        //Can Select and Search...possibly edit
      }
    }
    Search Rows on the FeatureSceneLayer
    {
      if (!featSceneLayer.HasAssociatedFeatureService)
      {
        return;//Search and Select not supported
      }
    
      //Multipatch (Object3D) or point?
      //var is3dObject = ((ISceneLayerInfo)featSceneLayer).SceneServiceLayerType
      //                                  == esriSceneServiceLayerType.Object3D;
      var is3dObject = featSceneLayer.FeatureSceneLayerType == FeatureSceneLayerType.Object3D;
      await QueuedTask.Run(() =>
      {
        var queryFilter = new QueryFilter
        {
          WhereClause = "Name = 'Ponderosa Pine'",
          SubFields = "*"
        };
    
        int rowCount = 0;
        //or select... var select = featSceneLayer.Select(queryFilter)
        using (RowCursor rowCursor = featSceneLayer.Search(queryFilter))
        {
          while (rowCursor.MoveNext())
          {
            using (var feature = rowCursor.Current as Feature)
            {
              oid = feature.GetObjectID();
              var shape = feature.GetShape();
              var attrib = feature["Name"];
              if (is3dObject)
              {
                //shape is a multipatch
              }
              else
              {
                //shape is a point
              }
              rowCount += 1;
            }
          }
        }
      });
    }
    Hide Selected features and Show Hidden features
    {
      if (featSceneLayer.HasAssociatedFeatureService)
      {
        return;//Search and Select not supported
      }
    
      await QueuedTask.Run(() =>
      {
        QueryFilter qf = new QueryFilter()
        {
          ObjectIDs = new List<long>() { 6069, 6070, 6071 },
          SubFields = "*"
        };
        featSceneLayer.Select(qf, SelectionCombinationMethod.New);
    
        featSceneLayer.HideSelectedFeatures();
        var selectionCount = featSceneLayer.SelectionCount;
    
        featSceneLayer.ShowHiddenFeatures();
        selectionCount = featSceneLayer.SelectionCount;
      });
    }
    Use Select or Search with a Spatial Query
    {
      var mapView = MapView.Active;
      if (mapView == null)
        return;
    
      await QueuedTask.Run(() =>
      {
        if (!featSceneLayer.HasAssociatedFeatureService)
        {
          return;//no search or select
        }
    
        //Select all features within the current map view
        var sz = mapView.GetViewSize();
        var map_pt1 = mapView.ClientToMap(new System.Windows.Point(0, sz.Height));
        var map_pt2 = mapView.ClientToMap(new System.Windows.Point(sz.Width, 0));
    
        //Convert to an envelope
        var temp_env = EnvelopeBuilderEx.CreateEnvelope(map_pt1, map_pt2, mapView.Map.SpatialReference);
    
        //Project if needed to the layer spatial ref
        SpatialReference sr = null;
        using (var fc = featSceneLayer.GetFeatureClass())
        using (var fdef = fc.GetDefinition())
        {
          sr = fdef.GetSpatialReference();
        }
    
        var env = GeometryEngine.Instance.Project(temp_env, sr) as Envelope;
    
        //Set up a query filter
        var sf = new SpatialQueryFilter()
        {
          FilterGeometry = env,
          SpatialRelationship = SpatialRelationship.Intersects,
          SubFields = "*"
        };
    
        //Select against the feature service
        var select = featSceneLayer.Select(sf);
        if (select.GetCount() > 0)
        {
          //enumerate over the selected features
          using (var rc = select.Search())
          {
            while (rc.MoveNext())
            {
              using (var feature = rc.Current as Feature)
              {
                oid = feature.GetObjectID();
                //etc.
              }
            }
          }
        }
        mapView.Map.ClearSelection();
      });
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also