Select to view content in your preferred language

How to edit a polygon shape

662
1
08-02-2017 08:22 AM
ManelKEDDAR
Deactivated User

Hello,

I have a feature Layer represented with a featureClass that contains a 2D Geometry field (polygon type)

i stored on the feature class some polygons i need to edit the shape of the polygon(the geometry) but i didn't know how to do it , i didn't find any method on Polygon class that helps me to extract any point of the polygon and try to move it for example here what i have tried but didn't work 

private async void update2D()
{
var featureTableUri = new System.Uri("https://frpargeosidport.corp.capgemini.com/arcgis/rest/services/POCSynopsis/FeatureServer/0");
var table = new ServiceFeatureTable(featureTableUri);
await table.LoadAsync();
MyMapView.Map = new Map();
var layer = new FeatureLayer(table);
MyMapView.Map.OperationalLayers.Add(layer);

var queryPoint = new MapPoint(0, 1670.82);
var buffer = GeometryEngine.Buffer(queryPoint, 5000);
//Use the buffer to define the geometry for a query
var query = new QueryParameters();
query.Geometry = buffer;
query.SpatialRelationship = SpatialRelationship.Contains;
//select features in a feature layer using the query
await layer.SelectFeaturesAsync(query, Esri.ArcGISRuntime.Mapping.SelectionMode.New);
var couche = MyMapView.Map.OperationalLayers[0] as FeatureLayer;
var coucheSelectionne = await couche.GetSelectedFeaturesAsync();

//Boucler sur tous les features dans la selection
foreach (ArcGISFeature f in coucheSelectionne)
{
//Load the feautre
await f.LoadAsync();

var location = (Esri.ArcGISRuntime.Geometry.Multipoint)f.Geometry ;
var pointsX = location.Points[0].X;
var pointY = location.Points[0].Y + 5000;
var newLocation = new MapPoint(pointsX, pointY);
//set the feature's new location
// f.Geometry = newLocation;
//update the feature in the local cache with the edits
await table.UpdateFeatureAsync(f);

}

//Apply all the edits back to the service feature table
var editResults = await table.ApplyEditsAsync();

}

Any help would be appreciated 

Thanks

Cheers

0 Kudos
1 Reply
JenniferNery
Esri Regular Contributor

If you wish to interactively update the geometry, you can use SketchEditor. If you wish to update programmatically, you can use PolygonBuilder and/or GeometryEngine methods.

To use SketchEditor, you will have something like this:

        xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid>
        <esri:MapView x:Name="MyMapView" />
        <StackPanel VerticalAlignment="Top"
                    HorizontalAlignment="Right">
            <Button Content="Edit"
                    Click="OnEdit" />
            <Button Content="Complete"
                    Command="{Binding ElementName=MyMapView, Path=SketchEditor.CompleteCommand}" />
        </StackPanel>
    </Grid>

In code-behind, identify the feature to edit, grab its geometry to use SketchEditor, hide the feature while its geometry is being modified, update the feature with geometry from SketchEditor, and make feature visible again. In this sample, Edit will start the geometry edit and Complete will complete the geometry edit.

        public MainWindow()
        {
            InitializeComponent();

            MyMapView.Map = new Map(Basemap.CreateTopographic());
            MyMapView.Map.OperationalLayers.Add(new FeatureLayer(new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire/FeatureServer/2")));
        }

        private async void OnEdit(object sender, RoutedEventArgs e)
        {
            ArcGISFeature feature = null;
            try
            {
                var mp = await MyMapView.SketchEditor.StartAsync(SketchCreationMode.Point, false) as MapPoint;
                var sp = MyMapView.LocationToScreen(mp);
                var result = await MyMapView.IdentifyLayersAsync(sp, 2, false);
                feature = result.FirstOrDefault(i => i.GeoElements.Any(g => g is ArcGISFeature))?.GeoElements?.FirstOrDefault() as ArcGISFeature;
                if (feature?.FeatureTable?.FeatureLayer == null)
                    return;
                feature.FeatureTable.FeatureLayer.SetFeatureVisible(feature, false);
                var geometry = await MyMapView.SketchEditor.StartAsync(feature.Geometry);
                feature.Geometry = geometry;
                await feature.FeatureTable.UpdateFeatureAsync(feature);
                feature.FeatureTable.FeatureLayer.SetFeatureVisible(feature, true);
            }
            catch (TaskCanceledException) { }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().Name);
            }
            finally
            {
                if (feature?.FeatureTable?.FeatureLayer != null)
                    feature.FeatureTable.FeatureLayer.SetFeatureVisible(feature, true);
            }
        }
0 Kudos