Find nearest geometry

566
1
02-25-2019 02:05 PM
MarkHolm
New Contributor II

I am trying to add or change a feature geometry to have some sort of "snap to" functionality. Where if you click and drag an existing feature point, or add a point, you can have it snap to another point if you click and drag closest to another feature. Features will be across multiple different layers as well.

The only way I can imagine this type of functionality is to use identifyLayersWithMaxResults and find the nearest geometry point of the results to set to. Let me know if there is a better way as I think identifyLayersWithMaxResults will not have the performance I require.

0 Kudos
1 Reply
LucasDanzinger
Esri Frequent Contributor

You'll probably end up needing to use the GeometryEngine::nearestVertex function - GeometryEngine Class | ArcGIS for Developers 

How you get there will be the question, because this function takes in a geometry and a point, and finds the nearest vertex of the input geometry to the input point. Since you are working across multiple layers, you might need to get creative about how you find the top candidates to run this geometry operation against. For example, perhaps at certain intervals (or on map extent changed) you queryFeatures against the feature table to get the current features that are in the current map extent, then store those geometries in some data structure, and run through the nearestVertex method on all the geometries. Tough to say what the best way to optimize this would be. We hit performance issues while trying to create a high performance geofencing feature in our DSA app, so we built a quad tree to act as a spatial index of sorts dynamic-situational-awareness-qt/GeometryQuadtree.cpp at 27f95374c2caa96e6574e6952b55c07bf1f3d012 · ... . Not sure how far you will need to take this all to get the performance to what you need it to be.

0 Kudos