Select to view content in your preferred language

Edit operation on ArcGIS Pro SDK

1498
3
09-15-2021 05:21 PM
ThiPham12
Emerging Contributor

I am trying to create a simple Add-In tool that will allow users to select features from a feature layer, clip the selected features and merge them together. For example, if there is a shapefile of all the counties in California and the user wants to clip and merge their study area from this county shapefile by selecting two counties as their study area. I am relatively new to ArcGIS Pro SDK and add-in. I am not sure if I am declaring the intermediate, clipped feature layer, clipArea and new, merged feature layer, new_fc correctly. Just curious, when would you use "//await mergeFeatures.ExecuteAsync()"? The indentation is not correctly shown below. Thanks for your help!

 

namespace ArcGISPro_Mapping_Apps
{
internal class SelectFeature : MapTool
{
public SelectFeature()
{
IsSketchTool = true;
SketchType = SketchGeometryType.Polygon;
SketchOutputMode = SketchOutputMode.Screen;

}

protected override Task OnToolActivateAsync(bool active)
{
return base.OnToolActivateAsync(active);
}


protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
QueuedTask.Run(() => {
var selection = MapView.Active.SelectFeatures(geometry);
var editOp = new EditOperation();
var clipArea = MapView.Active.Map.GetLayerAsFlattenedList().First(1 => 1.Name == "Area_clip");
var new_fc = MapView.Active.Map.GetLayerAsFlattenedList().First(1 => 1.Name == "StudyArea_merge");
var oid = -1;

Geometry clippedGeometry = GeometryEngine.Instance.Clip(geometry, clippedDistance);
editOp.Name = "clip and merge features";
editOp.Clip(selection, oid, clipArea, ClipMode.PreserveArea);
editOp.Merge(clipArea, new_fc, new List<long>() { 10, 96, 12 });


// Execute the edit operation
editOp.ExecuteAsync();
//await mergeFeatures.ExecuteAsync();
MessageBox.Show("Study area has been clipped successfully.");
return true;

});
}
}
}

0 Kudos
3 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Can you clarify your workflow?  In your pseudo code you take the digitized geometry and select all features intersected by that polygon, then you clip using the the same digitized geometry.

So you start with this (i am using US Counties here):

Wolf_0-1632248247534.png

then you end up with this study area:

Wolf_1-1632248306931.png

Is this your intended workflow?

0 Kudos
ThiPham12
Emerging Contributor

Hi Wolf, 

The user will be selecting the counties, which are part of their study area or importing their study area boundary (shp) onto the map. I would like to clip and merge the selected counties or clip the boundary area as you have shown, if they decide to import their boundary area instead. 

0 Kudos
ThiPham12
Emerging Contributor

Hi Wolf, I figured out how to select the area that overlap using two overlapping shapefiles and selecting the overlapping areas on one of the shapefile. I am figuring out how to do the same process, but using the ICommand select tool (reusing ArcGIS Pro's select tool) and clipping the shapefile I selected. Here is my ICommand script: 

public ICommand CmdSelect =>
FrameworkApplication.GetPlugInWrapper("esri_mapping_selectByRectangleTool") as ICommand;

Here is the tool that I created previously applied to a Pro button, which I would like to recreate the functionality using the ICommand select tool: 

await QueuedTask.Run(() =>
{
var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(fl => fl.Name.Contains("MUPOLYGON")).FirstOrDefault();

QueryFilter queryFilter = new QueryFilter
{
WhereClause = "AREASYMBOL = 'CA011' OR AREASYMBOL = 'CA101'",
SubFields = "MUKEY"
};

featureLayer.Select(queryFilter);

if (featureLayer == null)
{
MessageBox.Show("Failed to select.");
return;
}

});

await MapView.Active.ZoomToSelectedAsync(new TimeSpan(0, 0, 3), true);

 

Thanks Wolf for your help!

0 Kudos