Moving and Rotating Multiple Polygons

3415
3
12-06-2011 09:43 AM
JeremyBanner
New Contributor
I'm working with a layer of building sketches (polygons) that are composed of several different polygons each.  I want the user to be able to select all the polygons for a building at once and then rotate and move all the parts together.  It appears that the built in tools will only move and rotate one polygon at a time.  I have been working with the editgeometry and editor classes and I can select several polygons together and move them by iterating through all the points in all the rings and moving them with mouse move events.  My problem is that I can't get the edits to save either by calling SaveEdits on the editgeometry or editor.Save.Execute on the editor.  Any ideas?
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
If you are using Editor.EditVertices, I don't see a reason why edits are not saved since geometries are first simplified before it overwrites your geometry. If you are using EditGeometry, you may need to simplify the geometry first: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Simplify. Kindly check Fiddler when saving this edit, SpatialReference on Geometry might be missing. If so, we have logged this bug in EditGeometry.
0 Kudos
JeremyBanner
New Contributor
If you are using Editor.EditVertices, I don't see a reason why edits are not saved since geometries are first simplified before it overwrites your geometry. If you are using EditGeometry, you may need to simplify the geometry first: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Simplify. Kindly check Fiddler when saving this edit, SpatialReference on Geometry might be missing. If so, we have logged this bug in EditGeometry.


Jennifer,
Thank you for your reply.  I was trying to edit each selected Graphic.Geometry object directly and change it's vertices.  But when I tried to save the changes were lost.  What did work was making a clone of the geometry, editing the vertices, and then assigning the clone back to the Graphic.Geometry object.  Now I can move and rotate groups of polygons together.  Here's the code I used to move polygons. 

          
 
            foreach (var graphic in flayer.SelectedGraphics)
            {
                _edit_Geometry.StartEdit(graphic);
                ESRI.ArcGIS.Client.Geometry.Geometry geom = 
                    ESRI.ArcGIS.Client.Geometry.Geometry.Clone(graphic.Geometry);
                ESRI.ArcGIS.Client.Geometry.Polygon polygon = geom as ESRI.ArcGIS.Client.Geometry.Polygon;
                if (polygon != null)
                {
                    foreach (var ring in polygon.Rings)
                    {
                        IEnumerator<MapPoint> points = ring.GetEnumerator();
                        while (points.MoveNext())
                        {
                            points.Current.X = points.Current.X + changeinX;
                            points.Current.Y = points.Current.Y + changeinY;
                        }
                    }
                }
                graphic.Geometry = geom;
                _edit_Geometry.StopEdit();
                
            }
0 Kudos
BrettBattles1
New Contributor
This thread is pretty old... 🙂

I could not figure out how to get the geometry edits to persist until i tried the method described below with the Geometry.Clone method. (In my case, I did not have to use the edit geometry StartEdit/StopEdit methods.)

Thank you!!

Jennifer,
Thank you for your reply.  I was trying to edit each selected Graphic.Geometry object directly and change it's vertices.  But when I tried to save the changes were lost.  What did work was making a clone of the geometry, editing the vertices, and then assigning the clone back to the Graphic.Geometry object.  Now I can move and rotate groups of polygons together.  Here's the code I used to move polygons. 

          
 
            foreach (var graphic in flayer.SelectedGraphics)
            {
                _edit_Geometry.StartEdit(graphic);
                ESRI.ArcGIS.Client.Geometry.Geometry geom = 
                    ESRI.ArcGIS.Client.Geometry.Geometry.Clone(graphic.Geometry);
                ESRI.ArcGIS.Client.Geometry.Polygon polygon = geom as ESRI.ArcGIS.Client.Geometry.Polygon;
                if (polygon != null)
                {
                    foreach (var ring in polygon.Rings)
                    {
                        IEnumerator<MapPoint> points = ring.GetEnumerator();
                        while (points.MoveNext())
                        {
                            points.Current.X = points.Current.X + changeinX;
                            points.Current.Y = points.Current.Y + changeinY;
                        }
                    }
                }
                graphic.Geometry = geom;
                _edit_Geometry.StopEdit();
                
            }
0 Kudos