Ricky
You can implement it using the spatial query of a layer. For example, if you want to find a nearest city of “myPoint”, you can write code like
PointShape myPoint = new PointShape(100, 100);
Collection<Feature> features = citiesLayer.QueryTools.GetFeaturesNearestTo(myPoint, GeographyUnit.DecimalDegree, 1, new string[] { "CityName" });
That returns the closest feature within citiesLayer. Also that feature includes the column info of “CityName”. If you want to get the closest let’s say 3 cities to “myPoint”, just change the variable from 1 to 3.
If you want to find which state the point is in, the code will be like:
Collection<Feature> features = statesLayer.QueryTools.GetFeaturesContaining(myPoint, ReturningColumnsType.AllColumns);
That returns a feature within statesLayer contains “myPoint”, with all the columns data it has.
It’s similar if you want to find the nearest street to a point. We need to confirm how many streets we want to return as if the point gets the same distance to a couple streets, we might want to return all those streets instead of one. Also if the point is just on an intersection, we properly want to return all the streets which made that intersection. To do this, we can get the closest couple streets first, and check each closest streets to see if the distance to the point is equal. If yes, return all the streets that get the same distance to the point and if no, return only the nearest road. The code will like
// return the nearest 4 streets
Collection<Feature> closestStreets = streetsLayer.QueryTools.GetFeaturesNearestTo(myPoint, GeographyUnit.DecimalDegree, 4, new string[] { "StreetName" });
// Loop though to get the closest ones.
foreach (Feature street in closestStreets)
{
double distance = street.GetShape().GetDistanceTo(myPoint, GeographyUnit.DecimalDegree, DistanceUnit.Meter);
// Do what you need with the distance
}
Ben.