Hi everyone! I am super new to SDK, so there may be an obvious answer. Is there a way for a user to select a point on a map and then that point is buffered a set distance? I'm using Visual Studio 2022, and the ArcGIS Pro Module Add-in (C#).
I've looked at the pro snippets to buffer a MapPoint on the GitHub, but I'm just not connecting the dots on it. I've been able to set it so a user can select a point on the map and it shows the coordinates in a message box, and have an initial message box pop up prompting the user to select a point, I've just been running into issues getting a buffer to work. I've included my code down below, thanks for any advice!
namespace Tester
{
internal class MapTool1 : MapTool
{
public MapTool1()
{
IsSketchTool = true;
SketchType = SketchGeometryType.Point;
SketchOutputMode = SketchOutputMode.Map;
}
// This happens before the tool is run //
protected override Task OnToolActivateAsync(bool active)
{
MessageBox.Show(
"Please Select a Point on the Map!"
);
MapPoint pt = MapPointBuilderEx.CreateMapPoint(1.0, 1.0, SpatialReferences.WGS84);
Geometry ptBuffer = GeometryEngine.Instance.Buffer(pt, 5.0);
Polygon buffer = ptBuffer as Polygon;
return base.OnToolActivateAsync(active);
}
//This happens when the user clicks and begins to use the tool
protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
MessageBox.Show(
"North: " + geometry.Extent.YMax.ToString() + "\n" +
"South: " + geometry.Extent.YMin.ToString() + "\n" +
"East: " + geometry.Extent.XMax.ToString() + "\n" +
"West: " + geometry.Extent.XMin.ToString()
);
MapPoint pt = MapPointBuilderEx.CreateMapPoint(1.0, 1.0, SpatialReference.WGS84);
Geometry ptBuffer = GeometryEngine.Instance.Buffer(pt, 5.0);
Polygon buffer = ptBuffer as Polygon;
return base.OnSketchCompleteAsync(geometry);
}
}
}
Solved! Go to Solution.
As an update - I managed to get this working this morning. I found the code snippet here - https://github.com/Esri/arcgis-pro-sdk-community-samples/blob/master/Geoprocessing/GeoprocessingExec...
I updated the script and it looks like this now and seems to be working like I need it to!
namespace Tester
{
internal class MapTool1 : MapTool
{
public MapTool1()
{
IsSketchTool = true;
SketchType = SketchGeometryType.Point;
SketchOutputMode = SketchOutputMode.Map;
}
// This happens before the tool is run //
protected override Task OnToolActivateAsync(bool active)
{
MessageBox.Show(
"Please Select a Point on the Map!"
);
return base.OnToolActivateAsync(active);
}
//This happens when the user clicks and begins to use the tool
protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
var valueArray = await QueuedTask.Run(() =>
{
var g = new List<object>() { geometry, };
// Creates a 2 mile buffer around the geometry object
// null indicates a default output name is used
return Geoprocessing.MakeValueArray(g, null, @"2 Miles");
});
await Geoprocessing.ExecuteToolAsync("analysis.Buffer", valueArray);
return true;
}
}
}
As an update - I managed to get this working this morning. I found the code snippet here - https://github.com/Esri/arcgis-pro-sdk-community-samples/blob/master/Geoprocessing/GeoprocessingExec...
I updated the script and it looks like this now and seems to be working like I need it to!
namespace Tester
{
internal class MapTool1 : MapTool
{
public MapTool1()
{
IsSketchTool = true;
SketchType = SketchGeometryType.Point;
SketchOutputMode = SketchOutputMode.Map;
}
// This happens before the tool is run //
protected override Task OnToolActivateAsync(bool active)
{
MessageBox.Show(
"Please Select a Point on the Map!"
);
return base.OnToolActivateAsync(active);
}
//This happens when the user clicks and begins to use the tool
protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
var valueArray = await QueuedTask.Run(() =>
{
var g = new List<object>() { geometry, };
// Creates a 2 mile buffer around the geometry object
// null indicates a default output name is used
return Geoprocessing.MakeValueArray(g, null, @"2 Miles");
});
await Geoprocessing.ExecuteToolAsync("analysis.Buffer", valueArray);
return true;
}
}
}