ThinkGeo.com    |     Documentation    |     Premium Support

Finding nearest feature

I need some help.


I am looking to allow users to add roads to my map.  I want to store the user defined roads in an sqlserver2008 database.  That is working fine, but I also want to use a snapto feature that will snap these roads to the nearest "local roads (40)" layer.  I am wondering how do I get the nearest feature to a point using WorldMapKitRenderLayer.cs from the demo project?  Is that possible?  I see the layer in the collection of static layers, but they are only retrievable by index and not name.  



Jake,


Thanks for your post and question.


I think the problem is very similar with some how do I samples, the only difference is that the HowDoI sample shows how to find a layer within a Map Control using an existing API. While the WorldMapKit layers are stored in the DynamciLayers in the WOrldMapKitRenderLayer instance.



private void btnGetCount_Click(object sender, EventArgs e)
{
    FeatureLayer worldLayer = winformsMap1.FindFeatureLayer("WorldLayer");
    worldLayer.Open();
    txtCount.Text = worldLayer.QueryTools.GetCount().ToString(CultureInfo.InvariantCulture);
    worldLayer.Close();
}

1. Find the target layer(“Local roads(40))”). One easiest way is to loop through each layer in the DynamicLayers and to find out the layer with name "Local Roads (40)".

public Collection<WorldMapKitShapeFileFeatureLayer> DynamicLayers

Layer.Name = "Local Roads (40)";


2.Do the Query based on the target layer.


Any more questions just feel free to let me know.


Thanks.


Yale