Select to view content in your preferred language

Refresh Map after modifying features with addin?

158
6
Tuesday
KerryAlley
Frequent Contributor

I see that I'm not the first person who can't get map layers to refresh/redraw after feature geometries have been modified. I have an addin that updates the geometry and attributes of selected features. The attribute updates are immediately visible in the attribute table, but geometry updates are not, unless I save edits, and then close and re-open Pro.

I've tried:

 

 

MapView.Active.Redraw(true)

 

 

and:

 

 

myFeatureLayer.SetDataConnection((CIMFeatureDatasetDataConnection)myFeatureLayer.GetDataConnection())

 

 


I'm using Pro 3.3, and myFeatureClass's data connection (Json) is:

 

 

{
  "type": "CIMFeatureDatasetDataConnection",
  "featureDataset": "GDB_HMSDev.HMSADMIN.KerrySandbox",
  "workspaceConnectionString": "ENCRYPTED_PASSWORD_UTF8=00022e684a474377616152656c6f7a763650316344487555664e68764d523255577766652b50366a714e7457374c343d2a00;ENCRYPTED_PASSWORD=00022e68385049416956586c766d4f566e64316f46466a4367764b4e443157626e374a494d4c624641786b466543343d2a00;SERVER=aotgis;INSTANCE=sde:sqlserver:aotgis;DBCLIENT=sqlserver;DB_CONNECTION_PROPERTIES=aotgis;DATABASE=GDB_HMSDev;USER=HMSADMIN;VERSION=sde.DEFAULT;AUTHENTICATION_MODE=DBMS",
  "workspaceFactory": "SDE",
  "dataset": "GDB_HMSDev.HMSADMIN.Nodes_1",
  "datasetType": "esriDTFeatureClass"
}

 

 

 

Here's the Edit Operation code, and I can provide the rest of the addin code if necessary.  Any Suggestions?

 

 

// Edit Operation
var updateDangleNodeAndLegShapes = new EditOperation() { Name = "Add Node and Legs" };

// Modify Node
nodeInspector["SHAPE"] = newNode;
nodeInspector["NodeClass"] = "testing_addin";

// Modify NodeLeg
var newLeg = SharedMethods.makeLeg(singlePolyline, startEnd);
var legInspector = new Inspector();
legInspector.Load(legsMapMember, selectedFeatures[legsMapMember].First()); // This works because only one nodeLeg is selected
legInspector["SHAPE"] = newLeg;

updateDangleNodeAndLegShapes.Modify(nodeInspector);
updateDangleNodeAndLegShapes.Modify(legInspector);

if (!updateDangleNodeAndLegShapes.IsEmpty)
{
    var result = updateDangleNodeAndLegShapes.Execute(); //Execute will return true if the operation was successful and false if not.
    if (result)
    {
        MapView.Active.Redraw(true); // doesn't refresh
        nodesMapMember.SetDataConnection((CIMFeatureDatasetDataConnection)nodesMapMember.GetDataConnection());  // doesn't refresh
        legsMapMember.SetDataConnection((CIMFeatureDatasetDataConnection)legsMapMember.GetDataConnection());  // doesn't refresh
        MessageBox.Show(string.Format("Features modified"));
    }
    else
    {
        MessageBox.Show("Feature not created. Error: {0}", updateDangleNodeAndLegShapes.ErrorMessage);
    }
}

 

 

In case this makes a difference: My workflow for using the addin is to edit a feature in one feature layer manually using the EditVertices tool, and then I select features from two other feature layers, and execute my addin button to edit those selected features.


Thanks for any insight! 🙂

0 Kudos
6 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

Working with Inspector and EditOperation has some limitations.

All features loaded into the inspector must be from the same feature layer. Only feature values that are modified in the inspector are applied to the loaded feature(s). If tables are joined to the feature layer then the joined attributes are loaded also.

You can't use Modify and Inspector in cycle. Only last Modify will be executed. Your workflow must be like this: Load, Modify, Execute, Load, Modify, Execute... If you want to have possibility undo in one operation, you need to use CreateChainedOperation. I would recommend do not use inspector in your case. There are plenty of overloads of Modify methods which you could use for your workflow without inspector and execute all modifications at once.

More info about Editing here.

KerryAlley
Frequent Contributor

Thanks for your quick response!

I have different inspectors (nodeInspector and legInspector) for the two features from different feature layers that I'm modifying. Is that possible as long as I'm not re-using the inspectors and if the changes in the two inspectors are independent of each other?

Regarding your inspector comments, I can switch to using attribute dictionaries instead of inspectors, i.e. use

 

updateDangleNodeAndLeg.Modify(nodesMapMember, nodeoid, nodeDict); //or use row instead of nodesMapMember

 

instead of:

 

updateDangleNodeAndLeg.Modify(nodeInspector);

 

 

But is there an easy way to create an attribute dictionary from a row or a feature instead of from an inspector? I'm currently using:

 

var nodeDict = nodeInspector.ToDictionary(a => a.FieldName, a => a.CurrentValue);

 

(and I'm too embarrassed to say how long it took me to find *that* solution!) 

Oh, and how do I get rid of all the blank lines from these posts? If I delete the following lines from the html manually, it adds even more! 😅

 

<p>&nbsp;</p>

 

Thanks again for your help!!

0 Kudos
GKmieliauskas
Esri Regular Contributor

You don't need to copy all feature/row values to dictionary. You need fill dictionary with field values, you want to change, only. All other original field values will not be modified.

            // Modify Node
            updateDangleNodeAndLegShapes.Modify(nodesMapMember, selectedFeatures[nodesMapMember].First(),
                new Dictionary<string, object>() { { "SHAPE", newNode }, { "NodeClass", "testing_addin" } });

            // Modify NodeLeg
            updateDangleNodeAndLegShapes.Modify(legsMapMember as Layer, selectedFeatures[legsMapMember].First(), newLeg);

 

KerryAlley
Frequent Contributor

(Edit note: This question is now moot... see the following post)

I updated my addin so that it no longer modifies features using inspectors, but I still have the issue of the map not refreshing (otherwise the edits still seem to complete successfully).

Does this mean that my assumption that I don't need to chain edits is incorrect? My assumption is based on the following (from my previous post above):

"I have different inspectors (nodeInspector and legInspector) for the two features from different feature layers that I'm modifying. Is that possible as long as I'm not re-using the inspectors and if the changes in the two inspectors are independent of each other?"

Thanks again!

0 Kudos
KerryAlley
Frequent Contributor

I thought I had already tested this, but... 

My original code actually seems to work fine with or without inspectors. As far as I can tell, the problem was that I was executing the addin while there were unsaved manual edits (in the same SDE workspace). The unsaved feature was referenced in (but not modified by) the addin. Is there any way around having to save manual edits before executing an editing addin? Would I have to switch to using classic edit sessions in Pro?

0 Kudos
GKmieliauskas
Esri Regular Contributor

You could check if exists unsaved manual edit and ask user to save them and try to start your tool/button again. We use that workflow in our applications.

Call HasEdits method from Datastore.