ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Core.Geometry Namespace / MapPointBuilderEx Class / Z Property
Example

In This Topic
    Z Property (MapPointBuilderEx)
    In This Topic
    Gets or sets the Z-coordinate.
    Syntax
    public double Z {get; set;}
    Public Property Z As Double
    Remarks
    When the Z-value is set, the HasZ property is set to true. If this builder is not Z-Aware, then a default value of 0 is returned.
    Example
    MapPoint Builder Properties
    {
      // MapPointBuilderEx constructors can run on any thread.
    
      MapPoint point1 = null;
      MapPoint point2 = null;
    
      SpatialReference spatialReference = SpatialReferenceBuilder.CreateSpatialReference(54004);
    
      MapPointBuilderEx mapPointBuilder = new MapPointBuilderEx(100, 200, spatialReference);
      SpatialReference sr = mapPointBuilder.SpatialReference; // sr != null
      int wkid = sr.Wkid; // wkid = 54004
      bool hasZ = mapPointBuilder.HasZ;   // hasZ = false
      bool hasM = mapPointBuilder.HasM;   // hasM = false
      bool hasID = mapPointBuilder.HasID; // hasID = false
      bool isEmpty = mapPointBuilder.IsEmpty; // isEmpty = false
      double x = mapPointBuilder.X;   // x = 100
      double y = mapPointBuilder.Y;   // y = 200
      double z = mapPointBuilder.Z;   // z = 0, default value
      double m = mapPointBuilder.M;   // m is NaN, default value
      double id = mapPointBuilder.ID; // id = 0, default value
    
      // Do something with the builder
      mapPointBuilder.Z = 12; // Setting the z-value automatically sets HasZ property to true
    
      point1 = mapPointBuilder.ToGeometry();
      sr = point1.SpatialReference; // sr != null
      wkid = sr.Wkid; // wkid = 54004
      hasZ = point1.HasZ;   // hasZ = true
      hasM = point1.HasM;   // hasM = false
      hasID = point1.HasID; // hasID = false
      x = point1.X;   // x = 100
      y = point1.Y;   // y = 200
      z = point1.Z;   // z = 12
      m = point1.M;   // m is NaN, default value
      id = point1.ID; // id = 0, default value
    
      // Change some of the builder properties
      mapPointBuilder.SetValues(11, 22);
      mapPointBuilder.HasZ = false;
      mapPointBuilder.HasM = true;
      mapPointBuilder.M = 44;
    
      // Create another point
      point2 = mapPointBuilder.ToGeometry();
    
      bool isEqual = point1.IsEqual(point2); // isEqual = false
    
      // Set the builder to empty
      // Sets X and Y to NaN. Sets other attributes to the default values.
      // Does not change the attribute awareness.
      mapPointBuilder.SetEmpty();
    
      MapPoint point3 = mapPointBuilder.ToGeometry();
      sr = point3.SpatialReference; // sr != null
      wkid = sr.Wkid; // wkid = 54004
      hasZ = point3.HasZ;        // hasZ = false
      hasM = point3.HasM;        // hasM = true
      hasID = point3.HasID;      // hasID = false
      isEmpty = point3.IsEmpty;  // isEmpty = true
      x = point3.X;              // x is NaN
      y = point3.Y;              // y is NaN
      z = point3.Z;              // z = 0, default value
      m = point3.M;              // m is NaN, default value
      id = point3.ID;            // ID = 0, default value
    
      // Create a builder from a point
      mapPointBuilder = new MapPointBuilderEx(point2); // point1 = (11, 22, 0, 44, 0)
      sr = mapPointBuilder.SpatialReference; // sr != null
      wkid = sr.Wkid; // wkid = 54004
      hasZ = mapPointBuilder.HasZ;        // hasZ = false
      hasM = mapPointBuilder.HasM;        // hasM = true
      hasID = mapPointBuilder.HasID;      // hasID = false
      isEmpty = mapPointBuilder.IsEmpty;  // isEmpty = false
      x = mapPointBuilder.X;              // x = 11
      y = mapPointBuilder.Y;              // y = 22
      z = mapPointBuilder.Z;              // z = 0, default value
      m = mapPointBuilder.M;              // m = 44
      id = mapPointBuilder.ID;            // ID = 0, default value
    
      // Setting attribute values automatically sets the corresponding flag to true
      mapPointBuilder.Z = 150;
      mapPointBuilder.ID = 2;
    
      // Remove the spatial reference
      mapPointBuilder.SpatialReference = null;
    
      MapPoint point4 = mapPointBuilder.ToGeometry() as MapPoint;
      sr = point3.SpatialReference; // sr = null
      hasZ = point3.HasZ;        // hasZ = true
      hasM = point3.HasM;        // hasM = true
      hasID = point3.HasID;      // hasID = true
      isEmpty = point3.IsEmpty;  // isEmpty = false
      x = point3.X;              // x = 11
      y = point3.Y;              // y = 22
      z = point3.Z;              // z = 150
      m = point3.M;              // m = 44
      id = point3.ID;            // ID = 2
    }
    Create 3D Polyline and set Z-values while preserving curve segments
    {
      PolylineBuilderEx polylineBuilder = new PolylineBuilderEx(polyline);
      polylineBuilder.HasZ = true;
    
      // The HasZ property is set to true for all the points in
      // polyline3D when you call ToGeometry().
      Polyline polyline3D = polylineBuilder.ToGeometry();
    
      // For this example, create Z-values.
      // You may want to pass them in as a parameter.
      int numPoints = polyline3D.PointCount;
      double[] zValues = new double[numPoints];
      for (int i = 0; i < numPoints; i++)
      {
        zValues[i] = i % 2 == 0 ? 2 : 1;
      }
    
      // We need to know at which point index each part starts
      int partPointIndex = 0;
      int numParts = polyline3D.PartCount;
    
      for (int i = 0; i < numParts; i++)
      {
        var part = polyline3D.Parts[i];
        int numSegmentsInPolyline3D = part.Count;
    
        for (int j = 0; j < numSegmentsInPolyline3D; j++)
        {
          Segment segment = part[j];
    
          MapPointBuilderEx pointBuilder = new MapPointBuilderEx(segment.StartPoint);
          pointBuilder.Z = zValues[partPointIndex++];
          MapPoint startPoint = pointBuilder.ToGeometry();
    
          // Make sure that the end point of this segment is the same as the start point of the next segment
          pointBuilder = new MapPointBuilderEx(segment.EndPoint);
          pointBuilder.Z = zValues[partPointIndex];
          MapPoint endPoint = pointBuilder.ToGeometry();
    
          SegmentType segmentType = segment.SegmentType;
          SegmentBuilderEx segmentBuilder = null;
          switch (segmentType)
          {
            case SegmentType.Line:
              segmentBuilder = new LineBuilderEx((LineSegment)segment);
              break;
            case SegmentType.Bezier:
              segmentBuilder = new CubicBezierBuilderEx((CubicBezierSegment)segment);
              break;
            case SegmentType.EllipticArc:
              segmentBuilder = new EllipticArcBuilderEx((EllipticArcSegment)segment);
              break;
          }
    
          // Only change the start and end point which now have Z-values set.
          // This will preserve the curve if the segment is an EllipticArcSegment or CubicBezierSegment.
          segmentBuilder.StartPoint = startPoint;
          segmentBuilder.EndPoint = endPoint;
          segment = segmentBuilder.ToSegment();
    
          polylineBuilder.ReplaceSegment(i, j, segment);
        }
    
        // Move point index for the next part
        partPointIndex++;
      }
    
      polyline3D = polylineBuilder.ToGeometry();
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also