Skip to content

Instantly share code, notes, and snippets.

@steveoh steveoh/splitline.cs
Last active Dec 8, 2017

Embed
What would you like to do?
split a line based on a user click
var shape = (Polyline)row["Shape"];
var point = (MapPoint)GeometryEngine.Instance.Project(userClickGeometry, shape.SpatialReference);
var proximity = GeometryEngine.Instance.NearestPoint(shape, point);
var distance = proximity.Distance * 2;
var vertices = new List<Coordinate2D>
{
new Coordinate2D(point),
new Coordinate2D(proximity.Point),
};
var polyline = PolylineBuilder.CreatePolyline(vertices, point.SpatialReference);
var extension = GeometryEngine.Instance.MovePointAlongLine(polyline, distance, false, 0,
SegmentExtension.ExtendEmbedded);
vertices.Add(new Coordinate2D(extension));
polyline = PolylineBuilder.CreatePolyline(vertices, point.SpatialReference);
var parts = GeometryEngine.Instance.Cut(shape, polyline);
var totalLength = shape.Length;
var polylines = parts.Select(x => (Polyline)x).ToArray();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.