Created
April 27, 2016 16:01
-
-
Save JamesWP/292493e95dbe503581254012994063f5 to your computer and use it in GitHub Desktop.
GetNearestPoints Enumerate through nearest points in STRTree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace Ex{ | |
| class Example{ | |
| public static IEnumerable<Point> GetNearestPoints(STRtree<Point> tree, Point p) | |
| { | |
| var returnedSet = new HashSet<Point>(); | |
| returnedSet.Add(p); | |
| var dist = new FilteredItemDistance(returnedSet); | |
| while (true) | |
| { | |
| var nearest = tree.NearestNeighbour(p.Boundary.EnvelopeInternal, p, dist); | |
| if (returnedSet.Contains(nearest)) break; | |
| yield return nearest; | |
| returnedSet.Add(nearest); | |
| } | |
| } | |
| } | |
| public class FilteredItemDistance : IItemDistance<Envelope, Point> | |
| { | |
| private ISet<Point> ignorePoints; | |
| private IItemDistance<Envelope, IGeometry> D = new GeometryItemDistance(); | |
| public FilteredItemDistance(ISet<Point> ignorePoints) | |
| { | |
| this.ignorePoints = ignorePoints; | |
| } | |
| public double Distance(IBoundable<Envelope, Point> item1, IBoundable<Envelope, Point> item2) | |
| { | |
| if (ignorePoints.Contains(item1.Item)) return double.MaxValue; | |
| return D.Distance(item1, item2); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment