Select to view content in your preferred language

Editor - how to add a geometry to an existing row

1118
2
12-09-2011 07:05 AM
markcheyne
Deactivated User
Hi, I'm hoping for some pointers on a scenario I haven't found in the API docs.

I have an Oracle ArcSDE feature class that was created from a preexisting Oracle table. So the feature class has many rows, but no row has a geometry.

The intent of our Silverlight editing application is to allow the user to select a row, draw a shape on the map, and save that shape to the selected row. Think of this as an UPDATE of an existing row, where the column being changed is the geometry, not the attributes.

As I understand the Editor and EditorWidget classes, I only see methods for adding new rows - if you draw a shape on the map and save your edits, new rows are INSERTed. That's not what I want.

Thank you for any suggestions you can share.

Mark
0 Kudos
2 Replies
ChristopherHill
Deactivated User
Hello Mark,

I have a solution for you provided you are using couple of things in your application.
1. FeatureDataGrid
2. FeatureLayer
3. EditorWidget

What I would suggest is you set turn AutoSave=false on your feature layer, when AutoSave=true(which is the default) all newly created Graphics/Geometry will get pushed to the server as a new item. Having AutoSave=False will allow you to create the geometry then associate with the record/row you want then use a button click to Update the record with the geometry.

A Graphic object contains geometry and fields/attributes. Your feature layer should have graphics with attributes but the geometry is null.

Graphic.Attributes <-- Your fields/columns in you database. Graphic.Attributes["OBJECTID"] is the primaryKey
Graphic.Geometry <-- Polyline, Polygon, MapPoint

1 : Draw your new graphic using the editor control.
2 : Select the new graphic and get the geometry (newGraphic.Geometry)
3 : Set the geometry of the new graphic to the existing graphic. (existingGraphic.Geometry = newGraphic.Geometry)
4 : Delete the newGraphic you created because it is no longer needed. if you don't it will create a new record in your database which you don't want.
5 : Call myFeatureLayer.SaveEdits() <-- this will update the changes you have made back to the server.

Here is a link to our SDK where you can see examples of how to edit graphics attributes and geometry.
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm
0 Kudos
markcheyne
Deactivated User
Thanks very much! It was pretty easy once you pointed me in the right direction.

What I implemented is modified from those ideas:

I set AutoSave=false on my feature layer.

Then, it turns out I don't need the FeatureDataGrid or EditorWidget. I use an Editor with the Add and EditVertices command bound to it and assigned to a "New" and "Edit" Button, respectively, in a StackPanel & Border in my UserControl's Grid.

The host web app determines what the current row is, and I use it's primary key ID value to set, in code, a Where on my FeatureLayer, then call Update() on the layer to refresh it. Then once the FeatureLayer's UpdateCompleted event fires, the FeatureLayer has a single row in it (in other words, the FeatureLayer.Graphics.Count == 1). If that row already has a geometry, it'll be drawn. Either way I squirrel away the Graphic in a member variable: _editParcel = _editLayer.Graphics[0];

I can then use my "New" button to draw a new graphic, or if the row already has a geometry, I can use my "Edit" button, click on the graphic, which gives me handles to move or add vertices. In either case, when I complete the edit the Editor's EditCompleted event fires, which includes the new or edited Graphic in its eventargs, and, in the new case, the FeatureLayer.Graphics.Count now == 2. I get the Geometry off the new Graphic and assign it as the Geometry of my existing Graphic that I squirreled away earlier. Then I delete the new graphic from the layer's Graphics collection: _editLayer.Graphics.RemoveAt(_editLayer.Graphics.Count() - 1);, so that a new row doesn't get added when I save the edits.

Finally, I also have a "Save" button on that StackPanel - clicking it calls _editLayer.SaveEdits();

Voila!
0 Kudos