Identify feature is taking 2 values at a time.

Oct 25, 2009 at 6:11 PM

Hi All,

I am trying to make an identify tool which shall return the feature name of the one which is selected. For point features it is working fine.But for polygon features it is returning more than one feature when I click.My polygon layer is state.When I am clicking on a state it is returning the name of the neighboring state also along with the one I clicked.And at times more than even 2.

Please help.Below is my code.


if (rblMapTools.SelectedValue == "4") //Identify
            SharpMap.Geometries.Point p = myMap.ImageToWorld(new System.Drawing.Point(e.X, e.Y));

            FeatureDataSet fs = new FeatureDataSet();
            SharpMap.Layers.VectorLayer laystate = new SharpMap.Layers.VectorLayer("laystate");

            laystate.DataSource = new SharpMap.Data.Providers.PostGIS("Server=localhost;Port=5432;User Id=postgres;Password=yam@123;Database=postgis", "state__boundary", "gid");
            int screenToleranceX = 1, screenToleranceY = 1;

            System.Drawing.Point screenLowerLeft = new System.Drawing.Point(e.X - screenToleranceX, e.Y - screenToleranceY);
            System.Drawing.Point screenTopRight = new System.Drawing.Point(e.X + screenToleranceX, e.Y + screenToleranceY);

            SharpMap.Geometries.Point worldBottomLeft = myMap.ImageToWorld(screenLowerLeft);
            SharpMap.Geometries.Point worldTopRight = myMap.ImageToWorld(screenTopRight);

            SharpMap.Geometries.BoundingBox worldQueryBox = new SharpMap.Geometries.BoundingBox(worldBottomLeft, worldTopRight);

            laystate.DataSource.ExecuteIntersectionQuery(worldQueryBox, fs);            
            DropDownList1.DataSource = fs.Tables[0];            
            DropDownList1.DataTextField = "NAME";


Thanks in Advance




Oct 25, 2009 at 9:55 PM

Hello Sayan,

SharpMap v0.9 is only doing an intersection test for the bounding box of the states. Therefore you may be getting more than one result.

You need to look at this to do true intersection testing .

Hth FObermaier



Oct 26, 2009 at 5:18 AM

Hi fobermaier,

Wanted to know can the problem be because of screenTolerance.Can I reduce the screen tolerance less than 1 and solve the problem.

If so then how to give decimal value to the screen tolerance because System.Drawing only accept two int parameters.

Thanks in advance,



Oct 26, 2009 at 12:15 PM

Hi Sayan,

I doubt that it has much to do with screen tolerance.

Suppose you have a countries of the world layer in EPSG:4326 and you click almost anywhere on the northern hemisphere
you'll get almost certainly russia in your result set, since its boundingbox covers most of it.

If you try to get Luxemburg you are likely to get Belgium, France and Germany, (Russia) as well, since the bounding boxes
of these countries overlap that the area of Luxemburg.