0

Is there any way to move the center (centroid) of a circle/polygon to a new X/Y on the map, such as the current mouse location in C# using the ArcGIS Pro SDK?

I have a solution that I found that builds a buffer polygon using GeometryEngine.Instance.GeodesicBuffer. It takes a point, a radius, and linear units and outputs a polygon. The results are exactly what I need, but unfortunately I have to call it on every mouse move. This causes too much overhead, because the method is very slow and the polygon drags behind the mouse. I should be able to create the geodesic buffer (polygon) once on an initial button click and then just move that buffer (polygon) at its centroid to a new location on the mouse move. However, I still cannot do this.

The following is some code that I am using to create the buffer. I just need to plug in a moue point on the buffer to center it.

System.Drawing.Point currentLoc = System.Windows.Forms.Control.MousePosition;
MapPoint mapPt = MapView.Active.ScreenToMap(new Point(currentLoc.X, currentLoc.Y));
ArcGIS.Core.Geometry.Geometry buffer = GeometryEngine.Instance.GeodesicBuffer(mapPt, _graphics[i].Radius, GetLinearUnits(_graphics[i].Units));
if (_graphics[i].Graphic == null)
{
    _graphics[i].Graphic = MapView.Active.AddOverlay(buffer, _graphics[i].Symbol);
}
else
{
    MapView.Active.UpdateOverlay(_graphics[i].Graphic, buffer, _graphics[i].Symbol);
}
0

1 Answer 1

1

I have devised a solution for this problem with the assistance of the Esri ArcGIS Pro SDK team. I am utilizing the GeometryEngine.Instance.Move method on the polygon along with a delta X and delta Y coordinate. The previous mouse point X/Y is subtracted from the current mouse point X/Y. This creates the delta that is needed to move the centroid of the polygon to the correct location. The following is the necessary code:

MapPoint screenMapPt = MapView.Active.ScreenToMap(new Point(e.X, e.Y));
MapPoint prevPt = MapView.Active.ScreenToMap(new Point(_prevX, _prevY));

ArcGIS.Core.Geometry.Geometry buffer = GeometryEngine.Instance.Move(_graphics[i].Polygon, (screenMapPt.X - prevPt.X), (screenMapPt.Y - prevPt.Y));
_graphics[i].Polygon = (Polygon)buffer;

The code is still a little bit laggy, since it all happens on the mouse move event, but it is faster than the previous option of creating a GeodesicBuffer.

Thanks again to the Esri ArcGIS Pro SDK team.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.