ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data Namespace / Feature Class / GetShape Method
Example

In This Topic
    GetShape Method (Feature)
    In This Topic
    Gets the geometry of this feature. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Function GetShape() As Geometry
    public Geometry GetShape()

    Return Value

    The geometry of this feature.
    Exceptions
    ExceptionDescription
    This feature's type of shape (i.e., geometry) is not supported.
    A geodatabase-related exception has occurred.
    Example
    Retrieve Geometry from Geodatabase
    {
      // methods need to run on the MCT
      ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        try
        {
          // open a gdb
          using (ArcGIS.Core.Data.Geodatabase gdb =
                    new ArcGIS.Core.Data.Geodatabase(
                        new FileGeodatabaseConnectionPath(new Uri(@"c:\Temp\MyDatabase.gdb"))))
          {
            //Open a featureClass 
            using (ArcGIS.Core.Data.FeatureClass featureClass =
                           gdb.OpenDataset<ArcGIS.Core.Data.FeatureClass>("Polygon"))
            {
    
              ArcGIS.Core.Data.QueryFilter filter =
                         new ArcGIS.Core.Data.QueryFilter()
                         {
                           WhereClause = "OBJECTID = 6"
                         };
    
              // get the row
              using (ArcGIS.Core.Data.RowCursor rowCursor =
                                     featureClass.Search(filter, false))
              {
                while (rowCursor.MoveNext())
                {
                  using (var row = rowCursor.Current)
                  {
                    long oid = row.GetObjectID();
    
                    // get the shape from the row
                    ArcGIS.Core.Data.Feature feature = row as ArcGIS.Core.Data.Feature;
                    Polygon polygon = feature.GetShape() as Polygon;
    
                    // do something here
                  }
                }
              }
            }
          }
        }
        catch (Exception ex)
        {
          // error - handle appropriately
        }
      });
    }
    Change map frame extent to single feature with 15 percent buffer
    {
      //Change map frame extent to single feature with 10 percent buffer
    
      //Note: Must be on QueuedTask.Run
    
      //Reference the mapframe and its associated map
      Map m = mapFrame.Map;
    
      //Reference a feature layer and build a query (to return a single feature)
      FeatureLayer fl = m.FindLayers("GreatLakes").First() as FeatureLayer;
      QueryFilter qf = new QueryFilter();
      string whereClause = "NAME = 'Lake Erie'";
      qf.WhereClause = whereClause;
    
      //Zoom to the feature
      using (ArcGIS.Core.Data.RowCursor rowCursor = fl.Search(qf))
      {
        while (rowCursor.MoveNext())
        {
          //Get the shape from the row and set extent
          using (var feature = rowCursor.Current as ArcGIS.Core.Data.Feature)
          {
            Polygon polygon = feature.GetShape() as Polygon;
            Envelope env = polygon.Extent as Envelope;
            mapFrame.SetCamera(env);
    
            //Zoom out 15 percent
            Camera cam = mapFrame.Camera;
            cam.Scale = cam.Scale * 1.15;
            mapFrame.SetCamera(cam);
          }
        }
      }
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also