Select to view content in your preferred language

Dividing the line by points

1425
10
04-26-2022 05:07 AM
DavidMrázek
Frequent Contributor

Hi,

I want to ask if it is possible to split a polyline without creating a new FeatureLayer? I have a Polygon boundary (rectangle) redesigned to PolyLine and a Point on every corner, and I would like to divide Polyline by these points.

 await QueuedTask.Run(() =>
            {
                var minX = "ExtentMinX";
                var minY = "ExtentMinY";
                var maxX = "ExtentMaxX";
                var maxY = "ExtentMaxY";
                FeatureClass listFc = lyrList.GetTable() as FeatureClass;
                var polyCursor = fc.Search(queryFilter);
                cps.Progressor.Max = (uint) steps;
                cps.Progressor.Message = "Probíhá ";
                var centerPoint = new List<MapPoint>();
                Dictionary<string, object> attributes = new Dictionary<string, object>();
                List<string> side = new List<string>() {"Dolni", "Levá", "Horní", "Pravá"};
                object[] extentMinX = {"ExtentMinX EXTENT_MIN_X"};
                object[] extentMinY = {"ExtentMinY EXTENT_MIN_Y"};
                object[] extentMaxX = {"ExtentMaxX EXTENT_MAX_X"};
                object[] extentMaxY = {"ExtentMaxY EXTENT_MAX_Y"};
                object[] extent = {extentMinX, extentMinY, extentMaxX, extentMaxY};
                object[] listParameter = {lyrList, extent};
                StartATask("management.CalculateGeometryAttributes", listParameter);
                while (polyCursor.MoveNext() && !cps.Progressor.CancellationToken.IsCancellationRequested)
                {
                    cps.Progressor.Value += 1;
                    cps.Progressor.Status = cps.Progressor.Value + @" z " + cps.Progressor.Max + @" hotovo.";
                    var polygons = new List<Polygon>();
                    var editOperation = new EditOperation();
                    var polyFeature1 = polyCursor.Current as Feature;
                    var oid = polyCursor.Current.GetObjectID();
                    var polygonGeometry1 = polyFeature1.GetShape() as Polygon;
                    Row row = polyCursor.Current;
                    var pointMinX = (double) row[minX];
                    var pointMinY = (double) row[minY];
                    var pointMaxX = (double) row[maxX];
                    var pointMaxY = (double) row[maxY];
                    TableDefinition tableDefinition = listFc.GetDefinition();
                    int nameIndex = tableDefinition.FindField(text);
                    string nameNom = row.GetOriginalValue(nameIndex) as String;
                    var polylineBorder = new PolylineBuilder(polygonGeometry1).ToGeometry();//I would like to divide this Polyline.                                   
                    MapPointBuilder minPoint = new MapPointBuilder(pointMinX, pointMinY,
                        SpatialReferenceBuilder.CreateSpatialReference(5514));
                    MapPoint mPoint = minPoint.ToGeometry() as MapPoint;
                    MapPointBuilder midPoint = new MapPointBuilder(pointMinX, pointMaxY,
                        SpatialReferenceBuilder.CreateSpatialReference(5514));
                    MapPoint midlePoint = midPoint.ToGeometry() as MapPoint;
                    MapPointBuilder maxPoint = new MapPointBuilder(pointMaxX, pointMaxY,
                        SpatialReferenceBuilder.CreateSpatialReference(5514));
                    MapPoint mxPoint = maxPoint.ToGeometry() as MapPoint;
                    MapPointBuilder midxPoint = new MapPointBuilder(pointMaxX, pointMinY,
                        SpatialReferenceBuilder.CreateSpatialReference(5514));
                    MapPoint mixPoint = midxPoint.ToGeometry() as MapPoint;
                    List<MapPoint> pointsBorder = new List<MapPoint>() {mPoint, midlePoint, mxPoint, mixPoint};//Divided by these points.

 

I know about the SplitLineAtPoint division, but a new FeatureClass is being created there.

 

I will be happy for any advice or idea.

 

David

0 Kudos
10 Replies
DavidMrázek
Frequent Contributor

When I create it like this:

List<MapPoint> pointsBorder = new List<MapPoint>() { mPoint, midlePoint, mxPoint, mixPoint };
                    bool splitOccurred = true;
                    int partIndex = 0;
                    int segmentIndex = 1;
                    Multipart splitMethod = splitMethodB as Multipart;
                    foreach (var pointBorder in pointsBorder)
                    {
                        splitMethod = GeometryEngine.Instance.SplitAtPoint(polylineBorder, pointBorder, false, true, out splitOccurred, out partIndex, out segmentIndex);
                        splitList.Add(splitMethod);
                    }

                    foreach (var parts in splitList)
                    {
                        foreach (var part in parts.Parts)
                        {
                            Polyline polylineFromSegments = PolylineBuilder.CreatePolyline(part);
                            var mapPointCentroid = GeometryEngine.Instance.Centroid(polylineFromSegments);
                            centerPoint.Add(mapPointCentroid);
                        }
                    }

The length of the line changes with each step, first 2500 which corresponds to half the lower edge, then 6500 which corresponds to the sum of half the lower edge and the whole left edge, next is 11500 which is the whole upper left and half lower and then it drops to 6500 and 2500, so I have no idea what's going on. The result is as follows:

next.png

0 Kudos