Create Buffer around whole layer and to the selected feature in the layer

598
1
Jump to solution
01-03-2022 03:49 AM
RomanBoros
New Contributor III

Hi


We need to apply the buffer around layers i.e (polygon, line or point) which could be feature, MapTile or vector layer, and also if we select some feature in the layer then only to the selected feature.

We know GeometryEngine.Buffer() method creates buffers that accept Geometry and buffer distance as parameters.


So our question is how to get all the geometries in the layer and the geometry of the selected features in the layer.

Also, how we can delete the buffer from the layer too.

Any tips would be helpful.

0 Kudos
1 Solution

Accepted Solutions
TonyWakim
Esri Contributor

To select features in a layer, you could use: SelectFeaturesAsync() method (Method SelectFeaturesAsync (arcgis.com)).  To get selected features from a layer, you could use GetSelectedFeaturesAsync() (Method GetSelectedFeaturesAsync (arcgis.com)).

The SelectFeaturesAsync() takes a QueryParameters; passing a WhereClause with "1=1" will select all the features in a layer.

After calling the GetSelectedFeaturesAsync(), you could iterate through all the selected features and buffer (Method Buffer (arcgis.com)) their geometries one by one.  The buffer geometry could be added to a FeatureLayer FeatureTable(Class FeatureTable (arcgis.com)) (by creating new features using the geometry from each buffer) , or you could create graphics from them and add that to a GraphicsOverlay (Class GraphicsOverlay (arcgis.com)).

If you choose to add the buffer feature to the layer/table, it will be like any other feature, and if you want to remove it you will have to query it to find it and delete it (would usually help if there is a unique attribute value you can query for to identify which features are buffers and which are not).

If you choose to add to a GraphicsOverlay, then at runtime you can call GraphicsOverlay.Graphics.Clear() to clear all the graphics. 

 

View solution in original post

1 Reply
TonyWakim
Esri Contributor

To select features in a layer, you could use: SelectFeaturesAsync() method (Method SelectFeaturesAsync (arcgis.com)).  To get selected features from a layer, you could use GetSelectedFeaturesAsync() (Method GetSelectedFeaturesAsync (arcgis.com)).

The SelectFeaturesAsync() takes a QueryParameters; passing a WhereClause with "1=1" will select all the features in a layer.

After calling the GetSelectedFeaturesAsync(), you could iterate through all the selected features and buffer (Method Buffer (arcgis.com)) their geometries one by one.  The buffer geometry could be added to a FeatureLayer FeatureTable(Class FeatureTable (arcgis.com)) (by creating new features using the geometry from each buffer) , or you could create graphics from them and add that to a GraphicsOverlay (Class GraphicsOverlay (arcgis.com)).

If you choose to add the buffer feature to the layer/table, it will be like any other feature, and if you want to remove it you will have to query it to find it and delete it (would usually help if there is a unique attribute value you can query for to identify which features are buffers and which are not).

If you choose to add to a GraphicsOverlay, then at runtime you can call GraphicsOverlay.Graphics.Clear() to clear all the graphics.