How to end editing

163
3
Jump to solution
04-21-2022 04:32 AM
DavidMrázek
Occasional Contributor II

Hi,

I have one problem trying to create points in the middle of all sides of polygons, creating points is not a problem in itself, but the subsequent assignment of the name to which polygon belongs.

Here is an example of where I create points:

private async Task ListFilter(CancelableProgressorSource cps, uint steps, FeatureClass fc, FeatureLayer lyrList, QueryFilter queryFilter, string text, FeatureLayer points, string field)
        {
            await QueuedTask.Run(() =>
            {
                FeatureClass listFc = lyrList.GetTable() as FeatureClass;
                var polyCursor = fc.Search(queryFilter);
                cps.Progressor.Max = (uint)steps;
                cps.Progressor.Message = "Probíhá ";
                var createOperation = new EditOperation();
                createOperation.Name = "Generovani bodu";
                createOperation.SelectNewFeatures = false;
                while (polyCursor.MoveNext() && !cps.Progressor.CancellationToken.IsCancellationRequested)
                {
                    cps.Progressor.Value += 1;
                    cps.Progressor.Status = cps.Progressor.Value + @" z " + cps.Progressor.Max + @" hotovo.";
                    var polyFeature1 = polyCursor.Current as Feature;
                    var polygonGeometry1 = polyFeature1.GetShape() as Polygon;
                    TableDefinition tableDefinition = listFc.GetDefinition();
                    int nameIndex = tableDefinition.FindField(text);
                    Row row = polyCursor.Current;
                    string nameNom = row.GetOriginalValue(nameIndex) as String;
                    var polylineBorder = new PolylineBuilder(polygonGeometry1).ToGeometry();
                    ReadOnlyPointCollection pts = polylineBorder.Points;
                    int quarterPts = polylineBorder.PointCount / 4;
                    int halfPts = polylineBorder.PointCount / 2;
                    List<MapPoint> pointList = new List<MapPoint>()
                    {
                        pts[0], pts[quarterPts], pts[halfPts], pts[quarterPts * 3]
                    }; 
                    foreach (var aMapPoint in pointList)
                    {
                        createOperation.Create(points, aMapPoint);
                    }
                    createOperation.Execute();
                    var spatialQueryInter = new SpatialQueryFilter()
                    {
                        FilterGeometry = polygonGeometry1,
                        SpatialRelationship = SpatialRelationship.Touches,
                    };
                    var polyCursor2 = points.Search(spatialQueryInter);
                    while (polyCursor2.MoveNext())
                    {
                        Row row1 = polyCursor2.Current;
                        row1[field] = nameNom.ToString();
                        row1.Store();// here it throws an error:ArcGIS.Core.Data.GeodatabaseRowException: 'Cannot call Store on a recycled row while editing.'

                    }

                }
            }, cps.Progressor);
        }

So it occurred to me before naming the edit itself, but I don't know how or I don't know if it's a good solution.

 

I will be happy for any help or advice.

Thank you David

0 Kudos
1 Solution

Accepted Solutions
GintautasKmieliauskas
Regular Contributor

Hi,

First thing, move 18-19 line before line 12. This is performance issue.

Second thing, EditOperation Execute method could be called only once. You call it in a cycle. There is 2 solution methods:

- move createOperation inside cycle.

- move Execute calling outside cycle.

Third thing. Store in 45 line could be used in EditOperation with callback. Mixing of different EditOperation approaches is not legal. You can use Modify method from EditOperation and call Execute after Modify (depending on the way you choose in second sugesstion). 

In some cases you can use chained operation.

More information here:

https://github.com/Esri/arcgis-pro-sdk/wiki/ProConcepts-Editing#performing-edits-in-pro 

View solution in original post

3 Replies
GintautasKmieliauskas
Regular Contributor

Hi,

First thing, move 18-19 line before line 12. This is performance issue.

Second thing, EditOperation Execute method could be called only once. You call it in a cycle. There is 2 solution methods:

- move createOperation inside cycle.

- move Execute calling outside cycle.

Third thing. Store in 45 line could be used in EditOperation with callback. Mixing of different EditOperation approaches is not legal. You can use Modify method from EditOperation and call Execute after Modify (depending on the way you choose in second sugesstion). 

In some cases you can use chained operation.

More information here:

https://github.com/Esri/arcgis-pro-sdk/wiki/ProConcepts-Editing#performing-edits-in-pro 

DavidMrázek
Occasional Contributor II

The link helped me a lot, thank you.

 

0 Kudos
AashisLamsal1
Esri Contributor

On line #40, set the recyclingCursor to `false`. It should store the row without exception. 

var polyCursor2 = points.Search(spatialQueryInter, false);

Additional info on recycling cursor.

 

0 Kudos