Skip to content

Instantly share code, notes, and snippets.

@steveoh
Last active December 8, 2017 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveoh/4a7c85ed2a43aa7f46ba670e71f111e0 to your computer and use it in GitHub Desktop.
Save steveoh/4a7c85ed2a43aa7f46ba670e71f111e0 to your computer and use it in GitHub Desktop.
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