This project has moved and is read-only. For the latest updates, please go here.

ExecuteIntersectionQuery does not work in POINT Shapefile

Apr 29, 2008 at 5:39 AM
i am working on sharp map v 0.9 .
Now i am in great trouble. when i try to get features data of a point by mouse clicking on it, sharpmap does not return any result. Mouse point geometry does not intersect with shape point geometry . I use ExecuteIntersectionQuery following way,

SharpMap.Geometries.Point ClickPnt = myMap.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();

if (ds.Tables.Count > 0)
myGRD.Visible = true;
myGRD.DataSource = ds.Tables0;
lblMsg.Text = "No Record Found";

But this code work fine for both line and polygon shape files. I have tried by changing the data provider to nts. But problem still remains. I have working experience on UMN Mapserver where there is a property name "tolerance" for searching. Exploring the Sharpmap API i can not find such property . i have searched in the sharpmap forum , but can not get any post on ExecuteIntersectionQuery of point shape file. sharp map have used one of my professional project. But this problem bring me serous trouble.
please help me to overcome from this terrible trouble.
Apr 29, 2008 at 8:47 AM
Edited Apr 29, 2008 at 8:47 AM
Hi akhayer, create a bounding box centered around the target point and with a non zero area. tweak the size of the box to recreate the 'tolerance' and pass this box instead of the point. e.g

int screenToleranceX = 2, screenToleranceY = 2;

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);

SharpMap.Data.FeatureDataSet fds = new SharpMap.Data.FeatureDataSet();

myLayer.DataSource.ExecuteIntersectionQuery(worldQueryBox, fds);

HTH jd
Apr 30, 2008 at 5:15 AM
thanks JohnDiss.
It's now working fine.
it's really save me from terrible situation.
thanks again..

Sep 7, 2009 at 10:43 AM


  Is there any way to filter the feature dataset dynamically? I want to color some shapes dynamically. Any help in this is really appreciated. Thanks in advance.

Sep 8, 2009 at 6:49 PM
Edited Sep 8, 2009 at 7:13 PM

While it isnt a filter as such, check out the different ITheme implementors particularly CustomTheme they allow you to create / select styles depending on attributes of the feature (or geometry) hth jd

Sep 29, 2009 at 4:55 PM

Hi Johndiss, 

I am new to Sharpmap.

I am not able to find the ExecuteIntersectionQuery.

I tried the following 

SharpMap.Map myMap = new SharpMap.Map();


myMap is showing the datasource property ... what/where is the mistake ?



Vadivelan. P


Sep 29, 2009 at 5:02 PM

Hi Vadivelan, myMap should not have a datasource property..

Maps have layers and layers have datasources.. hth jd

Jan 13, 2010 at 12:25 PM


the code:

myLayer.DataSource.ExecuteIntersectionQuery(worldQueryBox, fds);


cause an error: NullReferenceException.

Can I help me????

Jan 13, 2010 at 2:24 PM

Domenico something hasnt been initialised properly.. use a breakpoint to find out what is null..