Select to view content in your preferred language

Copying Feature From On Featurelayer to Another - SaveEdits not working?!

2351
2
09-14-2011 10:24 PM
NicholasFloersch
Deactivated User
Hi all,

I am trying to duplicate features, as graphics, one at a time, as selected by a user, from a 'read only' FeatureLayer into a 'work space' FeatureLayer. Honestly this seems like it should be easy, but I'm missing something.

The code I am posting below compiles and runs. The graphics objects are not null and appear properly defined. I'm doing only a shallow copy of the source feature graphic to create the duplicate, but I have no idea if that is a problem because ... despite having event handlers for SaveEditsFailed, EndSaveEdits, and BeginSaveEdits, when I finally call SaveEdits(), absolutely nothing happens as far as I can tell. I am trying to call SaveEdits(), and then just in case I'm way off, I'm calling the Save() command in my Editor object on the map. Despite the three event handlers that seem like I should at least see one of them called, and each event handler with a MessageBox and breakpoint, the event handlers never get called.

Yes the FeatureLayer "SubAreas" that I am trying to save to is set as editable on the server, and is valid. I tried "AutoSave = true" for it, but had the same result, so that is set to false now.

When I call SubAreaLayer.Graphics.Insert(...) I can see, after multiple calls, the number of graphics objects inside of the graphics collection for SubAreaLayer grows. But it never saves the graphics back to the FeatureLayer... when execution of the app ends, they all go away. I tried SubAreaLayer.Graphics.Add(...) as well - same result of graphics collection growing over multiple calls, but nothing be saved in the end.

Here is my code chunk:
private void AddSubToScenario(Guid LUID, Guid SID)
{
    MainPage MP = (MainPage)((MainContainer)App.Current.RootVisual).LayoutRoot.Children[0];
    FeatureLayer SubAreaLayer = (FeatureLayer)MP.CPMap.Layers["SubAreas"];
    FeatureLayer LandUnitLayer = (FeatureLayer)MP.CPMap.Layers["SplitLinesPLUs"];
    
    SubAreaLayer.SaveEditsFailed += new EventHandler<TaskFailedEventArgs>(SubAreaLayer_SaveEditsFailed);
    SubAreaLayer.EndSaveEdits += new EventHandler<EndEditEventArgs>(SubAreaLayer_EndSaveEdits);
    SubAreaLayer.BeginSaveEdits += new EventHandler<BeginEditEventArgs>(SubAreaLayer_BeginSaveEdits);
    
    MP.editorMainMap.LayerIDs = new[] { "SubAreas" }; // in case it matters?
    
    Graphic copiedFeature = new Graphic();
    Graphic sourceFeature = LandUnitLayer.SelectedGraphics.FirstOrDefault();
    
    copiedFeature.Geometry = sourceFeature.Geometry;
    copiedFeature.Symbol = sourceFeature.Symbol;
    
    copiedFeature.Attributes["OBJECTID"] = sourceFeature.Attributes["OBJECTID"];
    copiedFeature.Attributes["LandUseID"] = sourceFeature.Attributes["LandUseId"];
    copiedFeature.Attributes["PlanningLandUnitID"] = sourceFeature.Attributes["PlanningLandUnitId"];
    copiedFeature.Attributes["SubareaID"] = Guid.NewGuid();
    SubAreaLayer.Graphics.Insert(0, copiedFeature); // I did try '.Add(...)' as well, same result either way.
    
    SubAreaLayer.SaveEdits(); // Nothing Happens! No SaveEdit related events fire? No Errors?
    
    if (MP.editorMainMap.Save.CanExecute(null)) MP.editorMainMap.Save.Execute(null); // Maybe??
    SubAreaLayer.Update();
}
void SubAreaLayer_BeginSaveEdits(object sender, BeginEditEventArgs e)
{
    MessageBox.Show("Copying Graphic Between Feature Layers Started");
}
void SubAreaLayer_EndSaveEdits(object sender, EndEditEventArgs e)
{
    MessageBox.Show("Copying Graphic Between Feature Layers Ended");
}
void SubAreaLayer_SaveEditsFailed(object sender, TaskFailedEventArgs e)
{
    MessageBox.Show("Copying Graphic Between Feature Layers Failed");
}
And here is the XAML for the FeatureLayer...
<esri:FeatureLayer 
    ID="SplitLinesPLUs" 
    Url="http://SOMESERVER/ArcGIS/rest/services/Editing/SplitLinesPLUs/MapServer/0" 
    Renderer="{StaticResource TransFillSelRenderer}"
    OutFields="*"
    Mode="SelectionOnly" 
    SelectionColor="{x:Null}" 
    Opacity="0.75"
    Visible="False">
</esri:FeatureLayer>
<esri:FeatureLayer 
    ID="SubAreas" 
    Url="http://SOMESERVER/ArcGIS/rest/services/Editing/SubAreas/MapServer/0" 
    OutFields="*"
    Mode="OnDemand"
    Visible="False"
    AutoSave="False">
</esri:FeatureLayer>
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
No clue except that your feature layer might be read-only.

Check that in your code  : if (SubAreaLayer.IsReadOnly) MessageBox.......
0 Kudos
NicholasFloersch
Deactivated User
No clue except that your feature layer might be read-only.

Check that in your code  : if (SubAreaLayer.IsReadOnly) MessageBox.......


It must have been the 2:30am brain fart...

A) Thanks so much for the reply. The result that retuned WAS "yes, this is read only" ... which lead me to triple-check the FeatureLayer...

B) I quickly noticed, um, the URL is wrong for the layer:
http://SOMESERVER/ArcGIS/rest/services/Editing/SubAreas/MapServer/0

Should Be
http://SOMESERVER/ArcGIS/rest/services/Editing/SubAreas/FeatureServer/0


And yet I might have spent hours more looking at the code and not the map services because I was so convinced they were setup right... which they are... but I was using the wrong rest endpoint.

Thank you!!!
Nick
0 Kudos