Select to view content in your preferred language

Select features and change selected features info

1058
7
03-07-2022 07:57 AM
MehdiHakimi
Emerging Contributor

Hi, I am beginner and need your help. I need c# code to select features (polygons or polylines)  by dragging a window in map view and change/update their geometric data (start or end points or radius ,...). Thank you

0 Kudos
7 Replies
TonyWakim
Esri Contributor

@MehdiHakimi ,

Here is a helper method that you can use as a reference to help select features from a feature layer.  It uses the SketchEditor to draw a rectangle and use that in the selection of the features.  Once you have the selected features you can edit them or update their geometries as needed.

 

            public static async Task<List<Feature>> SelectFeaturesAsync(MapView mapView, FeatureLayer featureLayer, SelectionMode selectionMode = SelectionMode.New)
            {
                List<Feature> features = new List<Feature>();

                var se = new SketchEditor();
                mapView.SketchEditor = se;
                Geometry envlope = await se.StartAsync(SketchCreationMode.Rectangle, false);

                var query = new QueryParameters();
                query.Geometry = envlope;
                query.SpatialRelationship = SpatialRelationship.Intersects;

                if (selectionMode == SelectionMode.New)
                    featureLayer.ClearSelection();

                var results = await featureLayer.SelectFeaturesAsync(query, selectionMode);

                foreach (var result in results)
                    features.Add(result);

                return features;
            }

 

0 Kudos
MehdiHakimi
Emerging Contributor

Thank you So much,

MehdiHakimi_0-1646672507314.png

Need load something to fix this errors?

0 Kudos
TonyWakim
Esri Contributor

You will just need add the proper "using" statements, for example the SketchEditor would need "using Esri.ArcGISRuntime.UI;", QueryParameters would need "using Esri.ArcGISRuntime.Data" and so on.

You should be able to find this info from the Doc references at: ArcGIS Runtime Library Reference

0 Kudos
MehdiHakimi
Emerging Contributor

Thank you. I added them but i have still this error.

MehdiHakimi_0-1646697554696.png

 

0 Kudos
TonyWakim
Esri Contributor

@MehdiHakimi , it looks like you are using the ArcGIS Desktop API (mapping) instead of runtime

TonyWakim_0-1646759672541.png

Are you using a blend of desktop and runtime api in your application?  If not you can simply comment out the first using line.  If you are for some reason, you can try qualifying your class names by their full namespace name.

0 Kudos
MehdiHakimi
Emerging Contributor

would you please tell me which 'usings' exactly needed for your code?

0 Kudos
TonyWakim
Esri Contributor

@MehdiHakimi The ones needed would be:

using Esri.ArcGISRuntime.UI;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Geometry;

 

In your code just make sure that the mapView is an instance of"Esri.ArcGISRuntime.UI.Controls.MapView"

0 Kudos