In v2.8.1 EditOperation Modify method not working correctly with European comma decimal separator

3588
25
08-05-2021 11:00 AM
KarenMeinstein
Occasional Contributor

My company's software is used internationally so we test with different operating system (Windows) regional settings (i.e., various country specific numeric formats).  One section of our code uses the EditOperation Modify method to change some geometries.  This code works fine in ArcGIS Pro v2.6.x and v2.7.x with different regional settings, but in v2.8.1 when the regional settings are set to a region that uses a comma instead of a decimal point as the decimal separator, it no longer works correctly.  Specifically, the changed geometries end up with shape area = 0 and they disappear from the map.  If I go into the Windows 10 region settings and manually change the decimal symbol to a point, it works fine again, so the decimal separator is the problem.  Has anyone else encountered this?  Any work-arounds?  This seems to be a bug....

0 Kudos
25 Replies
KarenMeinstein
Occasional Contributor

Hi Wolf,

I tried using my own data with your code, and it doesn't work in there even with a regular decimal point!  I'm not sure what's going on.  I've attached a project for you to take a look at and my changes to the visual studio solution.  This code is changing objectID 117 in the Modify feature to class to the geometry from objectID 1 in the Source feature class.  

Note that in my existing code it still works correctly with a decimal point but not with  a decimal comma in 2.8, but it works with both in 2.6.x and 2.7.x.  Also, the code with developed in 2.6, but it builds fine and works fine (except for this one issue) in 2.8.

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Thanks Karen,

Thangs for the sample data.   I am able to replicate what you are seeing with your data, however, in my tests the copied geometry is 'nulled' regardless on my language / region settings.  I will let you know what i find. 

0 Kudos
KarenMeinstein
Occasional Contributor

Thanks Wolf!  I'm glad you were able to replicate it.  I was seeing the same thing - it doesn't work regardless of region setting.  It's in my original code that it only fails with the European number settings.  

I hope you are able to solve this issue - it would be really helpful!

Karen

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Karen, 

 We are still trying to figure out what exactly is causing this issue.  It appears to be data related.  In the meantime I received a workaround that will fix this issue for the time being.   The workaround writes over the 'null' geometry in an EditOperation call back, it is using the Geodatabase API to do so.  The Geodatabase API doesn't seem to have any problems  with the data.  I modified the code you sent me with the EditOperation call back workaround below. 

        protected override async void OnClick()
        {
            var sourceLayerName = "Source";
            var modifyLayerName = "Modify";
            var SourceFieldName = "OBJECTID";
            var ModifyFieldName = "OBJECTID";

            var selectionSourceQuery = $@"{SourceFieldName} = 1";
            var selectionModifyQuery = $@"{ModifyFieldName} = 117";

            var sourceLayer = MapView.Active.Map.GetLayersAsFlattenedList().Where((l) => l.Name == sourceLayerName).FirstOrDefault() as FeatureLayer;
            if (sourceLayer == null)
            {
                MessageBox.Show($@"Unable to find {sourceLayerName} in the active map");
                return;
            }
            var modifyLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(f => f.Name == modifyLayerName);
            if (modifyLayer == null)
            {
                MessageBox.Show($@"Unable to find {modifyLayerName} in the active map");
                return;
            }
            await QueuedTask.Run(() =>
            {
                // search the source for the matching parcel record
                // copy only one polygon
                Geometry sourcePolygon = null;

                using (var cursor = sourceLayer.Search(new QueryFilter() { WhereClause = selectionSourceQuery }))
                {
                    if (cursor.MoveNext())
                    {
                        using (var myFeature = cursor.Current as Feature)
                        {
                            sourcePolygon = myFeature.GetShape().Clone();
                        }
                    }
                }
                if (sourcePolygon == null)
                {
                    MessageBox.Show($@"The add-in was not able to find a parcel where '{selectionSourceQuery}' is true.");
                    return;
                }

                using (Table table = modifyLayer.GetTable())
                {
                    EditOperation editOperation = new EditOperation
                    {
                        Name = "Modify a geometry callback"
                    };
                    editOperation.Callback(context =>
                    {
                        QueryFilter filter = new QueryFilter { WhereClause = selectionModifyQuery };
                        using (RowCursor rowCursor = table.Search(filter, false))
                        {
                            while (rowCursor.MoveNext())
                            {
                                using (Feature feature = (Feature)rowCursor.Current)
                                {
                                    // In order to update the Map and/or the attribute table.
                                    // Has to be called before any changes are made to the row.
                                    context.Invalidate(feature);

                                    feature.SetShape(sourcePolygon);
                                    //After all the changes are done, persist it.
                                    feature.Store();

                                    // Has to be called after the store too.
                                    context.Invalidate(feature);
                                }
                            }
                        }
                    }, table);

                    // create the polygon feature
                    editOperation.Modify(modifyLayer, 117, sourcePolygon);
                    if (!editOperation.Execute())
                    {
                        MessageBox.Show($@"Unable to create a new '{sourceLayer}' record: {editOperation.ErrorMessage}");
                    }
                }
            });
        }

I will give you an update on our findings.   

0 Kudos
KarenMeinstein
Occasional Contributor

Thanks!  I will give this a try.  Will this call back operation work in Pro v2.6 and 2.7?

0 Kudos
KarenMeinstein
Occasional Contributor

Hi Wolf,

When I try this code I get an error on line 64 (SetShape)  that says "Geometry cannot have Z values".  This is using the same data I sent you.  

0 Kudos
KarenMeinstein
Occasional Contributor

Hi Wolf,

When I try this code I get an error on line 64 (SetShape) that says "Geometry cannot have z-values".  This is using the same data I sent you.

 

Karen

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Strange, both feature classes you sent me have 'No Z values'.   That would mean that z-values got added to the geometry.  Can you double check your feature classes ?  I used v 2.8.2.

Wolf_0-1628627274404.png

 

0 Kudos
KarenMeinstein
Occasional Contributor

Something was weird was going on with the data I was using (which was different that what I sent you).  It seems to be working now.  Yay!

Am I correct in assuming this line doesn't need to be in there?:

editOperation.Modify(modifyLayer, 117, sourcePolygon); 

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Yes, this should work fine with v2.6 and 2.7.

0 Kudos