Help with getting attributes of layers

Topics: CompactFramework, Data Access, SharpMap v2.0
Editor
Aug 14, 2014 at 8:30 PM
Edited Aug 14, 2014 at 8:30 PM
I have this so far:
    private void mapImage2_MouseUp(object sender, MouseEventArgs e)
    {
        var p = mapBox1.Map.ImageToWorld(e.Location);
        SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();

        foreach (var layer in mapBox1.Map.Layers)
        {
            MessageBox.Show("I am in layer " + layer.LayerName + " " + e.Location.ToString());


        }
So if I click on the map it shows me the layer.... now within the layer I need to go down to the attributes... So if I click over an area it will read the attributes from the shp file and display some info. Thre are borders stored in the shp file attributes. Any assistance is greatly appreciated.
Coordinator
Aug 14, 2014 at 8:53 PM
Why don't you use MapBox' built in functionality to query the map?

Set MapBox.QueryLayerIndex to the layer you want to query and set MapBox.ActiveTool = MapBox.Tools.Query...
You may want to experiment with MapBox.MapQueryMode.

If that is not what you want, you need to check every layer if it implements ICanQueryLayer interface.
If it does, and ICanQueryLayer.Enabled == true, you can call ICanQueryLayer.ExecuteIntersectionQuery([Envelope|Geometry], fds)
Aug 15, 2014 at 12:23 PM
I was just using the code I could find to read the mouse location. Actually its the attributes of the layer that I am interested in. Imagine you have a sales district area and within the shp file is attributes set that for a particular area it will be the Downtown West district. That is stored as an attribute of the layer. If I go into any GIS program and look at attributes, its their. The eventual goal is that if the user clicks on Downtown West District it will pop up with some information. That information is coming from a database but I need to know where on the map the user clicked and what district that is. Ill look into the mapbox.tools.query... any other assistance is greatly appreciated.

I have many years of .NET but I am really not a GIS guy at all.
Aug 15, 2014 at 12:46 PM
Oh silly me... I just found the DemoProjects... ok that should help tremendously.
Editor
Aug 15, 2014 at 4:06 PM
Apparently what I am looking for is : GetFeatureInfo (please correct me if i'm wrong.
I am trying to make it so if I click on an area specified in a shp file it will allow me to display some data about that region.

Does anyone have any sample code where they implemented GetFeatureInfo from a layer (in my case its a vector layer from a shp file).
Coordinator
Aug 18, 2014 at 7:51 AM
To use GetFeatureInfo, you need to know the ID of the feature.
ExecuteIntersectionQuery does a spatial search on the data, and returns a feature data set based on spatial position.