ArcGIS.Core.Geometry.MapPoint And SpatialReference - "Snapping" to a valid value during feature creation

192
3
2 weeks ago
ThomasRea
New Contributor II

I've got a custom map tool that allows the user to select a point on the map to be used to create a feature with some domain-specific business logic attached to the creation process. This works excellently; however, we have a need to record these coordinates to be stored in an external system. I'm able to get the map coordinates using the MapView.ClientToMap function, however, after using these coordinates to create a feature, the features output geometry does not match the coordinates that I supply.

My guess is that this has to do with the spatial reference XY Resolution for the layer. I would expect the ClientToMap function to go ahead and "snap" to a valid x/y coordinate based on the maps spatial resolution. I should add that in our use case, the layer's spatial reference may not actually match the map's spatial reference in all cases.

Since it doesn't do this, the only thing I can think to do is to create the feature with the desired geometry, then after the feature is created, query the layer to get the "real" coordinates. This is far less than ideal, since this adds an extra step to our workflow.

 

Ideally, there'd be some SDK function already to allow me to calculate the valid coordinate. As far as I can tell, no such function exists. I tried the GeometryEngine.Project method, but that gave wildly unexpected results.

I also tried to write a simple "snap" function myself, but I couldn't quite get that to work as expected either. I presume that the true value would be the nearest factor of the XY Resolution value, so I would think this would work:

var x = Math.Round(point.X / resolution) * resolution;
var y = Math.Round(point.Y / resolution) * resolution;

0 Kudos
3 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

MapTool has SnappingResults property. More info here.

0 Kudos
ThomasRea
New Contributor II

Thank you for the response! I will test this, but I suspect this won't be sufficient. I need to snap to a spatial reference that is possibly different than the map spatial reference. Also, there are other places in our code where we need to perform a similar operation, outside of the MapTool. Also, there is no scenario where I want to snap to another feature - I'm only interested in snapping to a location on the grid for a specific layer.

0 Kudos
ThomasRea
New Contributor II

I did go ahead and test this, but it doesn't seem to work for my scenario. I get a SnapLocation of 0/0, and a snap type of None. I need to snap to spatial reference grid.

0 Kudos