Lower level editing API

688
9
09-13-2011 12:18 PM
NANA
by
New Contributor
Hello,

From what I saw in the examples, editing is only supported on a feature layer that is currently visible on a map control (I guess opacity 0 would work, but would hurt performance). Because our geographical tables that we want to edit only contain the shapes of our entities, we don't want to display them as they are (we have database views that we display instead, with symbology based on certain attributes). We want to just send the features that we want to add/move/delete to the rest endpoint, we will handle the drawing on the map.

The question is: Are there any APIs that would make it easier for us to communicate with the server (ArcGIS server 10 SP2), for example something like the internal EditTask class that is referred here? Or do we have to roll our own code that would construct http requests?

We would even prefer doing the requests from our server side, so the question also applies to WPF API, or any other libraries that you could offer (:

Thanks,
Evgeny
0 Kudos
9 Replies
JenniferNery
Esri Regular Contributor
You can still perform add/delete/update to FeatureLayer.Graphics even if the layer is not visible. It won't be interactive as in the Editing examples in the SDK but in code behind you can do. If FeatureLayer.AutoSave=False, you need to call FeatureLayer.SaveEdits() to submit the changes to the server.

//add
var graphic = new Graphic() {Geometry = new MapPoint(x,y)}
graphic.Attributes["fieldName"] = fieldValue;
featureLayer.Graphics.Add(graphic);

//remove
graphic = featureLayer.Graphics.FirstOrDefault(g => (int)g.Attributes[layer.LayerInfo.ObjectIdField] == idToDelete);
if (graphic != null) featureLayer.Graphics.Remove(graphic);

//edit
graphic = featureLayer.Graphics.FirstOrDefault(g => (int)g.Attributes[layer.LayerInfo.ObjectIdField] == idToEdit);
graphic.Geometry = new MapPoint(x,y);
graphic.Attributes["fieldName"] = newFieldValue;
0 Kudos
NANA
by
New Contributor
Thanks for the answer Jennifer.

I will try to use it but it still seems that I'm forced to put the feature layer into a map control to initialize it properly (I tried to do it without and I couldn't make it), and even if it's possible to work with it outside of a map, it seems that we have to do multiple calls to the gis server for a single operation, first initialize the layer, then add or edit features (this without the server obviously), and then save the edits.

Is there anything that would allow us to simply send the features that we want to add/edit to the server?

Regards,
Evgeny

Edit: I played with the System.Net.WebClient class a little bit today, and quite easily I was able to make a request to the rest api that worked. So even without any helpers it's ok.
0 Kudos
JenniferNery
Esri Regular Contributor
You don't need to add FeatureLayer to your map control to perform edit, you just need to make sure it is initialized and updated. Try the following code snippet:
   FeatureLayer l = new FeatureLayer() 
   {
    Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/FeatureServer/0"     ,
    ObjectIDs = new int[]{11688}
   };
   l.OutFields.Add("*");
   l.Initialized += (s, e) =>
    {
     if (l.InitializationFailure == null)     
      l.Update();
    };
   l.UpdateCompleted += (s, e) =>
    {
     var graphic = l.Graphics.FirstOrDefault(g => (int)g.Attributes[l.LayerInfo.ObjectIdField] == 11688);
     if (graphic != null)
      graphic.Attributes["description"] = string.Format("Updated this field on {0}", DateTime.UtcNow);
    };
   l.EndSaveEdits += (s, e) =>
    {
     if(e.Results!= null || e.Results.UpdateResults!=null)
     {
      foreach (var r in e.Results.UpdateResults)
       MessageBox.Show(string.Format("Updated id ({0})", r.ObjectID));
     }
    };
   l.Initialize();


Visit this page to see that the Date is changed: http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/FeatureServer/0/11688
0 Kudos
NANA
by
New Contributor
Thanks again Jennifer, really useful example, but like I said in my previous post, it does few server calls for one operation so it may not be ideal for us.
0 Kudos
JohnnyPenet
New Contributor
Hi Evgeny

I'm doing low level API's for doing updates on feature layers. If you do not use the feature layers displayed on the map, you will still have the problem of refreshing the map, because the map does not know when you add or modify features of a feature class on the map. Doing a refresh will be a very costly operation and not user friendly.
To handle symbology you can use field types defined in the mxd behind the mapservice. The API allow you to extract the symbology from the mapservice. But for the symbology you are limited to simple symbols and picture symbols.
But there are limitations on the the rendering of a feature layer. You do not have standard support for the use of labeling, you has to program it.

Johnny
0 Kudos
LucasCulbertson
New Contributor
Jennifer,

I'm able to add a graphic to my featurelayer's graphic collection and post the edits back up to the server.  However, I'm having a tough time wrapping my head around how to delete features through the feature service. According to your snippet below you can remove the graphic from the graphics collection:
//remove
graphic = featureLayer.Graphics.FirstOrDefault(g => (int)g.Attributes[layer.LayerInfo.ObjectIdField] == idToDelete);
if (graphic != null) featureLayer.Graphics.Remove(graphic);


When my featurelayer is successfully initialized, there are no graphics in the collection, hence I can not remove a particular record since it is not there.  Is it an expected behavior for a featurelayer to not have any graphics associated with it? Or is there a method I need to call in order to populate my graphics collection after it initializes?  Any  help would be much appreciated.
0 Kudos
JenniferNery
Esri Regular Contributor
You need to call FeatureLayer.Update() to query the service for features. When FeatureLayer.UpdateCompleted is fired, FeatureLayer.Graphics should contain the features.
0 Kudos
LucasCulbertson
New Contributor
Thank you Jennifer.  That did the trick.
0 Kudos
ForamParikh
Occasional Contributor
I am having trouble in delete the feature

I am using this code,
featurelayer.Graphics.Remove(graphicalLayer.Graphics[0]);
but it is not working please help me.I will appreciate if you can explain me in details.

also let me know how to select the graphic,

and also any one know about if i draw overlapped polygon it should propmt me that this is overlapped polygon user can't draw any overlapped polygon.

Please advise,
Thanks
Foram
0 Kudos