Dividing the line by points

986
10
04-26-2022 05:07 AM
DavidMrázek
Occasional Contributor II

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
GKmieliauskas
Esri Regular Contributor

Hi,

Have tried EditOperation Split, SplitAtPoint, SplitAtPoints methods?

More info here:

https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/#topic20421.html 

API reference show less methods than intellisense.

DavidMrázek
Occasional Contributor II

How can I choose a non-existent Polyline feature created from a polygon boundary?

 while (polyCursor.MoveNext())
                {
var polyFeature1 = polyCursor.Current as Feature;
                    var oid = polyCursor.Current.GetObjectID();
                    var polygonGeometry1 = polyFeature1.GetShape() as Polygon;
 var polylineBorder = new PolylineBuilder(polygonGeometry1).ToGeometry();
apView.Active.SelectFeatures(polylineBorder);
                    var selectedFeatures = MapView.Active.Map.GetSelection();
                    editOperation.Split(selectedFeatures,pointsBorder);
                    editOperation.Execute();
0 Kudos
GKmieliauskas
Esri Regular Contributor

Lets start from the beginning.

What is final result of your task? Polyline Feature in FeatureLayer(FeatureClass) or Polyline Geometry?

If your result is Polyline Feature then you need to create Polyline Feature from polygon geometry and after that split created feature using EditOperation.

If your result is Polyline geometry then you can use GeometryEngine SplitAtPoint method. More info here:

ArcGIS Pro 2.9 API Reference Guide - SplitAtPoint Method—ArcGIS Pro

DavidMrázek
Occasional Contributor II

I would like to get geometries for which I would then create a Centroid. But when I do SplitAtPoint and insert points gradually, the same line as the original is created.

List<MapPoint> pointsBorder = new List<MapPoint>() { mPoint, midlePoint, mxPoint, mixPoint };
                    bool splitOccurred;
                    int partIndex;
                    int segmentIndex;
                    splitOccurred = true;
                    partIndex = 1;
                    segmentIndex = 0;
                    foreach (var pointBorder in pointsBorder)
                    {
                       var  splitMethod = GeometryEngine.Instance.SplitAtPoint(polylineBorder, pointBorder, false, false, out splitOccurred, out partIndex, out segmentIndex);
                        var mapPointCentroid = GeometryEngine.Instance.Centroid(splitMethod);
                        centerPoint.Add(mapPointCentroid);
                    }
attributes[field] = nameNom;
                    foreach (var aMapPoint in centerPoint)
                    {
                        attributes["SHAPE"] = aMapPoint;
                        attributes[attribute] = side[index];
                        index++;
                        createOperation.Create(points, attributes);
                    }

                    createOperation.Execute();

It looks like this:

centr.png

and should more or less look like this:

centr.png

0 Kudos
GKmieliauskas
Esri Regular Contributor

Your splitMethod variable returns result Multipart. So need to make cycle for each of Multipart parts and get centroid of part not of multipart.

DavidMrázek
Occasional Contributor II

Error: foreach statement cannot operate on variables of type 'Multipart' because 'Multipart' does not contain a public instance or extension definition for 'GetEnumerator'

what can i do with this?

0 Kudos
GKmieliauskas
Esri Regular Contributor
      foreach (var part in splitMethod.Parts)
      {
      }
DavidMrázek
Occasional Contributor II

It seems that I still have a bug in SplitAtPoint, because the length of the line is still the same even after Split.

0 Kudos
GKmieliauskas
Esri Regular Contributor

If your polylineBorder is polyline so you need change createPart parameter of  SplitAtPoint to "true".

"createPart - Determines if parts are to be created. MUST be false for polygons. For polylines, if true, the part on which the new split point falls is split into two parts with the newly added vertex serving as the end of the first part and the beginning of the second."

If it is polygon then you need to rearrange polygon to polyline and after make split .