Select to view content in your preferred language

Polygon Editing Capabilities in Silverlight API

1819
8
03-29-2011 11:32 AM
MichaelAnderson
Emerging Contributor
Hello,

I have a project that will use ArcGIS Server 9.3.1 as the data source. It requires fairly complex polygon editing in the client and I am planning on using OpenLayers because it can do what I need.

The client has asked that I consider using the Silverlight API instead. My questions are only related to what kind of editing can be done in the client, I already know how I will get the geometries to the client and back to the server.

Does anyone know if the Silverlight API can do the following:
- snap vertices to adjacent polygons while creating or editing vertices
- create and edit multi-part polygons
- create holes in polygons
- delete holes from polygons

I've found plenty of editing examples, but none that demonstrate any of these capabilities.

Thanks.

Mike
0 Kudos
8 Replies
JenniferNery
Esri Regular Contributor
You can look at this Editing sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsExplicitSave

- snap vertices to adjacent polygons while creating or editing vertices

Click on Edit Vertices button.
Click on polygon you want to edit
Press on CTRL-key while dragging vertex and try to snap to other polygon's vertex


- create and edit multi-part polygons

Click on Add Vertices button to add polygons.
Click on Add to Selection button.
Click on polygons you want to comprise a single polygon.
Click on Union button.

To demonstrate that this is in-fact multi-part.
Click on Edit Vertices button.
Drag one of the polygons. Notice that the other polygons are moved with it.

- create holes in polygons

Click on New Selection button.
Click on polygon you want to edit.
Click on Cut button.
Draw a hole inside the polygon.

- delete holes from polygons

Delete hole to make one polygon?
[INDENT]Click on New Selection button.
Click on the two polygons created from above.
Click on Union button. (this creates a single polygon without the hole)[/INDENT]
or delete hole to get rid of the center?
[INDENT]Click on New Selection button.
Click on the inner polygon.
Click on Delete Selected button. (this removes the center).[/INDENT]
0 Kudos
MichaelAnderson
Emerging Contributor
Thanks Jennifer.

The multi-part polygon works great. The snapping looks like it snaps to vertices in adjacent polygons, but not edges. Can it be configured to snap to edges? I like how it shows the snap tolerance. I'm guessing the tolerance can be modified.

At first I couldn't get the holes to work because it only let's you draw a line. Then I tried a line that crosses over itself and that did it. Is there a way to draw a polygon to cut it with? A line crossing itself works, but isn't as intuitive as a polygon.

Looks like I can potentially use the SilverLight API instead of OpenLayers. Could you point me to documentation, tutorials, screen casts, etc. about editing and how to configure it? I'm particularly interested in how many vertices a polygon can have and assigning attributes to the polygon.

Thanks.

Mike
0 Kudos
JenniferNery
Esri Regular Contributor
The snap to vertices have configurable properties: SnapKey and SnapDistance

<esri:Map x:Name="MyMap" Extent="-13054165,3850112,-13027133,3863559" esri:Editor.SnapDistance="20" esri:Editor.SnapKey="S">


Re: snap to edges, this is a related thread: http://forums.arcgis.com/threads/26296-Snap-to-edges.

Kindly see attached for drawing a hole. You draw a closed polyline to create a polygon (hole). This is by design. Cutting with polygon is not supported by Editor out-of-the-box but you can customize your app to use CutAsync instead of going through the Editor. What you can do is allow user to draw cutter with polygon and in code convert it to a polyline to pass as parameter to http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Tasks.Geom...

You can read up on the following:
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Editor.htm...

You can also take a look at the SDK samples. Particularly, Editing, Utilities, Graphics, and Toolkit.
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm

For editing attributes, you can use FeatureDataForm or FeatureDataGrid or EditorWidget.
0 Kudos
MichaelAnderson
Emerging Contributor
Your description of how to use a polygon to cut made me realize some of this editing is using calls to the server. I assumed it was all going on the the client. I turned on Firebug to confirm that.

My client will be upgrading to 10 in the future, but not until after my current project is finished. So I can't do this editing, at least the hole cutting part, with 9.3.1 on the back end, correct?

Mike
0 Kudos
JenniferNery
Esri Regular Contributor
You're right Editing is new to ArcGIS REST API v10 http://help.arcgis.com/en/arcgisserver/10.0/apis/rest/index.html.

You can still perform geometry edits on the graphic from the client-side by using Draw (http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#DrawGraphics).

You can update the DrawComplete event handler to something like this. For simplicity, I am using polyline to cut but you can also use polygon and iterate through its rings.
Polyline polyline = args.Geometry as Polyline;
if (polyline != null && graphicsLayer.Graphics.Count>0 && graphicsLayer.Graphics[0].Geometry is Polygon)
{
 Polygon polygon = graphicsLayer.Graphics[0].Geometry as Polygon;
 foreach (var path in polyline.Paths)
 {
  polygon.Rings.Add(path);
 }
}
else
 graphicsLayer.Graphics.Add(graphic);
0 Kudos
MichaelAnderson
Emerging Contributor
I was just logging on to ask if you could do something like that. In OpenLayers the way I have done it is to represent the geometries in WKT and then insert the holes in the WKT and recreate the geometry. Deleting a hole is just removing the hole from the WKT and recreating the geometry. This looks basically the same.

Can I do something similar to create a multi-part polygons since I can't do the union like the other example?

I assume the snapping works the same and isn't dependent on anything server side. And I don't see any REST request when I delete a polygon, so that will work too, correct?

And thank you very much for all your help.

Mike
0 Kudos
JenniferNery
Esri Regular Contributor
Yes, for union, you want to add the rings from one polygon to rings of another polygon to make a single multi-part polygon.

Snapping requires more code, you need to find the closest vertex by comparing the distance of the moving vertex against vertices of other feature geometries.

Delete is removing the graphic from your layer. You don't see a webrequest for this operation if FeatureLayer.AutoSave=False until SaveEdits is called. The feature is marked for deletion and a request is made to the service for this object id to be deleted. You can try this sample and watch the webrequests on Fiddler: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsAutoSave.
0 Kudos
PavelVranka
Emerging Contributor
I have inverse problem. I need some of the functionality in OpenLayers, particularly to create and edit multi-part polygon. Can you help me?

Pavel Vranka (vranka@seznam.cz)
0 Kudos