ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Core.Geometry Namespace / Geometry Class / Clone Method
Example

In This Topic
    Clone Method (Geometry)
    In This Topic
    Clones this geometry instance. As geometry objects are immutable and hence never change, the clone returned will be this object rather than a copy of this instance.
    Syntax
    public Geometry Clone()
    Public Function Clone() As Geometry

    Return Value

    A geometry
    Remarks

    For Internal Use Only:
    In some geodatabase operations it may make sense for a geometry to be set to be recycling for performance or internal resource allocation reasons. In this scenario the geometry's content may change via some external code (i.e. GDB NextFeature). Consequently, the Clone method will return a new geometry with the copied contents of this instance rather than the original object. This cloned geometry should be passed to the code requiring the geometry object.

    Example
    Construct a MapPoint
    // Use a builder convenience method or use a builder constructor.
    
    // create a 3d point with M
    MapPoint pt = MapPointBuilderEx.CreateMapPoint(1.0, 2.0, 3.0, 4.0);
    
    
    // builderEx constructors don't need to run on the MCT.
    MapPointBuilderEx mb = new MapPointBuilderEx(1.0, 2.0, 3.0, 4.0);
    // do something with the builder
    
    MapPoint ptWithM = mb.ToGeometry();
    
    
    MapPoint clone = ptWithM.Clone() as MapPoint;
    MapPoint anotherM = MapPointBuilderEx.CreateMapPoint(ptWithM);
    
    
    MapPointBuilderEx builderEx = new MapPointBuilderEx(1.0, 2.0, 3.0);
    builderEx.HasM = true;
    builderEx.M = 4.0;
    
    pt = builderEx.ToGeometry() as MapPoint;
    
    
    // or another alternative with builderEx constructor
    builderEx = new MapPointBuilderEx(1.0, 2.0, true, 3.0, true, 4.0, false, 0);
    pt = builderEx.ToGeometry() as MapPoint;
    
    
    // or use a builderEx convenience method
    pt = MapPointBuilderEx.CreateMapPoint(1.0, 2.0, 3.0, 4.0);
    
    Get the individual parts of a multipart feature
    /// <summary>
    /// This method takes an input multi part geometry and breaks the parts into individual standalone geometries.
    /// This method must be called on the MCT. Use QueuedTask.Run.
    /// </summary>
    /// <param name="inputGeometry">The geometry to be exploded into the individual parts.</param>
    /// <returns>An enumeration of individual parts as standalone geometries. The type of geometry is maintained, i.e.
    /// if the input geometry is of type Polyline then each geometry in the return is of type Polyline as well.
    /// If the input geometry is of type Unknown then an empty list is returned.</returns>
    /// <remarks>This method must be called on the MCT. Use QueuedTask.Run.</remarks>
    public IEnumerable<Geometry> MultipartToSinglePart(Geometry inputGeometry)
    {
      // list holding the part(s) of the input geometry
      List<Geometry> singleParts = new List<Geometry>();
    
      // check if the input is a null pointer or if the geometry is empty
      if (inputGeometry == null || inputGeometry.IsEmpty)
        return singleParts;
    
      // based on the type of geometry, take the parts/points and add them individually into a list
      switch (inputGeometry.GeometryType)
      {
        case GeometryType.Envelope:
          singleParts.Add(inputGeometry.Clone() as Envelope);
          break;
        case GeometryType.Multipatch:
          singleParts.Add(inputGeometry.Clone() as Multipatch);
          break;
        case GeometryType.Multipoint:
          var multiPoint = inputGeometry as Multipoint;
    
          foreach (var point in multiPoint.Points)
          {
            // add each point of collection as a standalone point into the list
            singleParts.Add(point);
          }
          break;
        case GeometryType.Point:
          singleParts.Add(inputGeometry.Clone() as MapPoint);
          break;
        case GeometryType.Polygon:
          var polygon = inputGeometry as Polygon;
    
          foreach (var polygonPart in polygon.Parts)
          {
            // use the PolygonBuilderEx turning the segments into a standalone 
            // polygon instance
            singleParts.Add(PolygonBuilderEx.CreatePolygon(polygonPart));
          }
          break;
        case GeometryType.Polyline:
          var polyline = inputGeometry as Polyline;
    
          foreach (var polylinePart in polyline.Parts)
          {
            // use the PolylineBuilderEx turning the segments into a standalone
            // polyline instance
            singleParts.Add(PolylineBuilderEx.CreatePolyline(polylinePart));
          }
          break;
        case GeometryType.Unknown:
          break;
        default:
          break;
      }
    
      return singleParts;
    }
    
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also