{
// list of points
List<MapPoint> pointsForBuilder = new List<MapPoint>
{
MapPointBuilderEx.CreateMapPoint(0, 0, 2, 3, 1),
MapPointBuilderEx.CreateMapPoint(1, 1, 5, 6),
MapPointBuilderEx.CreateMapPoint(2, 1, 6),
MapPointBuilderEx.CreateMapPoint(0, 0)
};
// will have attributes because it is created with convenience method
Polyline polylineWithAttrs = PolylineBuilderEx.CreatePolyline(pointsForBuilder);
bool hasZ = polylineWithAttrs.HasZ; // hasZ = true
bool hasM = polylineWithAttrs.HasM; // hasM = true
bool hasID = polylineWithAttrs.HasID; // hasID = true
// will not have attributes because it is specified as a parameter
Polyline polylineWithoutAttrs =
PolylineBuilderEx.CreatePolyline(pointsForBuilder, AttributeFlags.None);
hasZ = polylineWithoutAttrs.HasZ; // hasZ = false
hasM = polylineWithoutAttrs.HasM; // hasM = false
hasID = polylineWithoutAttrs.HasID; // hasID = false
// will have attributes because it is created with convenience method
Polygon polygonWithAttrs = PolygonBuilderEx.CreatePolygon(pointsForBuilder);
hasZ = polygonWithAttrs.HasZ; // hasZ = true
hasM = polygonWithAttrs.HasM; // hasM = true
hasID = polygonWithAttrs.HasID; // hasID = true
// will not have attributes because it is specified as a parameter
Polygon polygonWithoutAttrs =
PolygonBuilderEx.CreatePolygon(pointsForBuilder, AttributeFlags.None);
hasZ = polygonWithoutAttrs.HasZ; // hasZ = false
hasM = polygonWithoutAttrs.HasM; // hasM = false
hasID = polygonWithoutAttrs.HasID; // hasID = false
// will not have attributes because it is specified as a parameter
PolylineBuilderEx polylineB =
new PolylineBuilderEx(pointsForBuilder, AttributeFlags.None);
hasZ = polylineB.HasZ; // hasZ = false
hasM = polylineB.HasM; // hasM = false
hasID = polylineB.HasID; // hasID = false
// will have attributes because it is passed an attributed polyline
polylineB = new PolylineBuilderEx(polylineWithAttrs);
hasZ = polylineB.HasZ; // hasZ = true
hasM = polylineB.HasM; // hasM = true
hasID = polylineB.HasID; // hasID = true
// will not have attributes because it is passed a non-attributed polyline
polylineB = new PolylineBuilderEx(polylineWithoutAttrs);
hasZ = polylineB.HasZ; // hasZ = false
hasM = polylineB.HasM; // hasM = false
hasID = polylineB.HasID; // hasID = false
// will not have attributes because it is specified as a parameter
PolygonBuilderEx polygonB = new PolygonBuilderEx(pointsForBuilder, AttributeFlags.None);
hasZ = polygonB.HasZ; // hasZ = false
hasM = polygonB.HasM; // hasM = false
hasID = polygonB.HasID; // hasID = false
// will have attributes because it is passed an attributed polygon
polygonB = new PolygonBuilderEx(polygonWithAttrs);
hasZ = polygonB.HasZ; // hasZ = true
hasM = polygonB.HasM; // hasM = true
hasID = polygonB.HasID; // hasID = true
// will not have attributes because it is passed a non-attributed polygon
polygonB = new PolygonBuilderEx(polygonWithoutAttrs);
hasZ = polygonB.HasZ; // hasZ = true
hasM = polygonB.HasM; // hasM = true
hasID = polygonB.HasID; // hasID = true
}
{
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();
}
{
// define a polyline
MapPoint startPointZ = MapPointBuilderEx.CreateMapPoint(1, 1, 5);
MapPoint endPointZ = MapPointBuilderEx.CreateMapPoint(20, 1, 5);
Polyline polylineZ = PolylineBuilderEx.CreatePolyline([startPointZ, endPointZ]);
// define a split point
MapPoint splitPointAboveLine = MapPointBuilderEx.CreateMapPoint(10, 10, 10);
// split the polyline at the point. Don't project the split point onto the line, don't create a new part
var splitPolyline = GeometryEngine.Instance.SplitAtPoint(polylineZ, splitPointAboveLine, false, false, out bool splitOccurred, out int partIndex, out int segmentIndex);
// splitOccurred = true
// partIndex = 0
// segmentIndex = 1
// splitPolyline.PointCount = 3
// splitPolyline.PartCount = 1
// splitPolyline coordinates are (1, 1, 5), (10, 10, 10), (20, 1, 5)
// split the polyline at the point. dont project the split point onto the line, do create a new part
splitPolyline = GeometryEngine.Instance.SplitAtPoint(polylineZ, splitPointAboveLine, false, false, out splitOccurred, out partIndex, out segmentIndex);
// splitOccurred = true
// partIndex = 1
// segmentIndex = 0
// splitPolyline.PointCount = 4
// splitPolyline.PartCount = 2
// splitPolyline first part coordinates are (1, 1, 5), (10, 10, 10)
// splitPolyline second part coordinates are (10, 10, 10), (20, 1, 5)
// split the polyline at the point. do project the split point onto the line, don't create a new part
splitPolyline = GeometryEngine.Instance.SplitAtPoint(polylineZ, splitPointAboveLine, false, false, out splitOccurred, out partIndex, out segmentIndex);
// splitOccurred = true
// partIndex = 0
// segmentIndex = 1
// splitPolyline.PointCount = 3
// splitPolyline.PartCount = 1
// splitPolyline coordinates are (1, 1, 5), (10, 10, 5), (20, 1, 5)
// split the polyline at the point. do project the split point onto the line, do create a new part
splitPolyline = GeometryEngine.Instance.SplitAtPoint(polylineZ, splitPointAboveLine, false, false, out splitOccurred, out partIndex, out segmentIndex);
// splitOccurred = true
// partIndex = 1
// segmentIndex = 0
// splitPolyline.PointCount = 4
// splitPolyline.PartCount = 2
// splitPolyline first part coordinates are (1, 1, 5), (10, 10, 5)
// splitPolyline second part coordinates are (10, 10, 5), (20, 1, 5)
//
// try to split with a point that won't split the line - pt extends beyond the line
//
var pointAfterLine = MapPointBuilderEx.CreateMapPoint(50, 1, 10);
splitPolyline = GeometryEngine.Instance.SplitAtPoint(polylineZ, pointAfterLine, false, false, out splitOccurred, out partIndex, out segmentIndex);
// splitOccurred = false
// ignore partIndex, sgementIndex
// splitPolyline is the same as polylineZ
///
/// multipart polygon
///
List<Coordinate3D> coordsZ =
[
new Coordinate3D(10,10,5),
new Coordinate3D(10,20,5),
new Coordinate3D(20,20,5),
new Coordinate3D(20,10,5)
];
List<Coordinate3D> coordsZ_2ndPart =
[
new Coordinate3D(30,20,10),
new Coordinate3D(30,30,10),
new Coordinate3D(35,28,10),
new Coordinate3D(40,30,10),
new Coordinate3D(40,20,10)
];
var builder = new PolygonBuilderEx
{
HasZ = true
};
builder.AddPart(coordsZ);
builder.AddPart(coordsZ_2ndPart);
Polygon multipart = builder.ToGeometry();
// pointA is closer to the first part of the multipart - the split occurs in the first part
var pointA = MapPointBuilderEx.CreateMapPoint(22, 18, 7);
var splitPolygon = GeometryEngine.Instance.SplitAtPoint(multipart, pointA, false, false, out splitOccurred, out partIndex, out segmentIndex);
// splitPolygon.PointCount = 12
// splitPolygon.PartCount = 2
// splitPolygon first part coordinates (10, 10, 5), (10, 20, 5), (20, 20, 5), (22, 18, 7), (20, 10, 5), (10, 10, 5)
// pointB is midPoint between the 2 parts - no split will occur
var pointB = MapPointBuilderEx.CreateMapPoint(25, 20, 7);
splitPolygon = GeometryEngine.Instance.SplitAtPoint(multipart, pointB, true, false, out splitOccurred, out partIndex, out segmentIndex);
// splitOccurred = false
// ignore partIndex, sgementIndex
// splitPolyline is the same as polylineZ
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)