Editing Line Feature Layer

570
3
02-28-2011 01:55 AM
KeremCelik
New Contributor
Hi,

I have a problem about editing my line features in feature layer. I can add line features to featurelayer, but cannot edit its properties.

public void AddFeature()
{
 FeatureLayer f_layer = (FeatureLayer)Map.Layers["Links"];
 f_layer.DisableClientCaching = true;
 f_layer.UpdateCompleted += new EventHandler(f_layer_UpdateCompleted);
 f_layer.Update();
}
private void f_layer_UpdateCompleted(object sender, EventArgs e)
{
 FeatureLayer feature_layer = (FeatureLayer)Map.Layers["Links"];

 ESRI.ArcGIS.Client.Geometry.Polyline line = new ESRI.ArcGIS.Client.Geometry.Polyline();

 MapPoint point1 = new MapPoint(35,40,feature_layer.SpatialReference);
 MapPoint point2 = new MapPoint(36,41,feature_layer.SpatialReference);

 ESRI.ArcGIS.Client.Geometry.PointCollection point_collection = new ESRI.ArcGIS.Client.Geometry.PointCollection();

 point_collection.Add(point1);
 point_collection.Add(point2);

 line.Paths.Add(point_collection);
 line.SpatialReference = feature_layer.SpatialReference;

 Graphic graph = new Graphic();

 graph.Geometry = line;
 graph.Attributes["TypeID"] = 2;
 graph.Attributes["Custom1"] = "Value";

 feature_layer.Graphics.Add(graph);
}

public void EditFeature()
{
 FeatureLayer f_layer = (FeatureLayer)Map.Layers["Links"];
 f_layer.DisableClientCaching = true;
 f_layer.UpdateCompleted += new EventHandler(f_layer_UpdateCompleted);
 f_layer.EndSaveEdits += new EventHandler<EndEditEventArgs>(f_layer_EndSaveEdits);
 f_layer.SaveEditsFailed += new EventHandler<TaskFailedEventArgs>(f_layer_SaveEditsFailed);
 f_layer.Update(); 
}
private void f_layer_UpdateCompleted(object sender, EventArgs e)
{
 FeatureLayer feature_layer = (FeatureLayer)Map.Layers["Links"];
 
 feature_layer.Graphics[0].Attributes["TypeID"] = 3;
 feature_layer.Graphics[0].Attributes["Custom1"] = "New Value"; 
}
private void f_layer_EndSaveEdits(object sender, EndEditEventArgs e)
{
 MessageBox.Show("Feature Editted");
}
private void f_layer_SaveEditsFailed(object sender, TaskFailedEventArgs e)
{
 MessageBox.Show(e.Error.Message);
}


In the code above I can add feature by AddFeature function without any problem. But when I want to edit the feature I added in EditFeature funtion. After f_layer_UpdateCompleted event handler, I receive Unable to complete operation error message in f_layer_SaveEditsFailed event handler.

If you have any idea about the problem, please help me.

Thanks in advance.
Kerem.
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
Does your service contain these editable fields (TypeID, Custom1)? If yes, do they match the data type value (TypeID a number, Custom1 a string)? Kindly inspect the Error in the SaveEditsFailed. Also, you might want to run Fiddler with your app to see how the web request is formed when applying these edits.

Looking at your code, I would not advice adding the graphics in the UpdateCompleted event. This event is also raised the first time feature service is querried for existing features and every time you call Update() on the layer.

Just to clarify, without the attribute change, you are able to see the newly added features in your service? What version of the API are you using? Can you also share code on how FeatureLayer is created? Thanks.
0 Kudos
KeremCelik
New Contributor
Does your service contain these editable fields (TypeID, Custom1)? If yes, do they match the data type value (TypeID a number, Custom1 a string)? Kindly inspect the Error in the SaveEditsFailed. Also, you might want to run Fiddler with your app to see how the web request is formed when applying these edits.

Looking at your code, I would not advice adding the graphics in the UpdateCompleted event. This event is also raised the first time feature service is querried for existing features and every time you call Update() on the layer.

Just to clarify, without the attribute change, you are able to see the newly added features in your service? What version of the API are you using? Can you also share code on how FeatureLayer is created? Thanks.


Thanks a lot for your quick response.

For fields, they are editable, I re-checked and the data type matched with the feature layer.

For UpdateCompleted event, I forgot to add the following line to the f_layer_UpdateCompleted event handler, I usually put (sender as FeatureLayer).UpdateCompleted -= f_layer_UpdateCompleted; in the first line. To prevent feature layer to re-call this event when update function called.

I can see the feature I added right after I add them,

The API version is 2.1

Creation of feature layer is in the server. I have a SDE database and a Line FeatureClass in it. (The table is registered as versioned) I put the featureclass into an mxd file and published in ArcGIS Server Manager. (I have other layers, I can add new features to them, edit existing features, and delete them without any problem)

I add feature layer into my Map with the following xaml code (I set the Url in code behind):
<esri:FeatureLayer ID="Links" Opacity="1" DisableClientCaching="True" Where="TypeID = 3"  Renderer="{StaticResource BlackRenderer}" />


I have another consideration :

When I add feature without Geometry and Symbol attribute set, I can edit the existing feature with the code I posted. I think the problem is in the Geometry setting part. But I could not identified.

Thanks again.
Kerem.
0 Kudos
KeremCelik
New Contributor
Finally I solved my problem, I am not sure what the problem is but what I did is just create the line feature class again with fields and the problem is solved.

Thanks again for your help.

Kerem.
0 Kudos