Last active
December 8, 2017 02:48
-
-
Save steveoh/4a7c85ed2a43aa7f46ba670e71f111e0 to your computer and use it in GitHub Desktop.
split a line based on a user click
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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