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

Why I cannot get selectedfeature using ExecuteIntersectionQuery ()

Topics: Algorithms, General Topics, SharpMap Project, SharpMap v2.0, WinForms Controls
Jul 26, 2009 at 2:40 AM
Edited Jul 26, 2009 at 4:36 AM


                System.Drawing.PointF pt_click = new PointF((float)e.X, (float)e.Y);
                SharpMap.Geometries.Point pt_map = map.ImageToWorld(pt_click);

                SharpMap.Layers.VectorLayer query_lyr = map.GetLayerByName("Bound") as SharpMap.Layers.VectorLayer; ;
                if (query_lyr == null) return;

                SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
                if (!query_lyr.DataSource.IsOpen) query_lyr.DataSource.Open();
                query_lyr.DataSource.ExecuteIntersectionQuery(pt_map.GetBoundingBox(), ds);

                if (ds == null) return;

                GisSharpBlog.NetTopologySuite.IO.WKTReader reader = new GisSharpBlog.NetTopologySuite.IO.WKTReader();
                GeoAPI.Geometries.IGeometry point = reader.Read(pt_map.ToString());

                int rowid = 0;
                SharpMap.Data.FeatureDataTable dt = ds.Tables[0] as SharpMap.Data.FeatureDataTable;
                if (dt == null) return;
                SharpMap.Data.FeatureDataRow dr1 = dt[0] as SharpMap.Data.FeatureDataRow;
                double distance = point.Distance(reader.Read(dr1.Geometry.ToString()));


"Bound" layer is a polygon layer,so there is must a feature is selected.So the function is success. When layer type is point,I found the count of ds is 1,but ds.Tables[0] is null. Does the GetBoundingBox() of a point get a small rect which cannot intersection with feature in layer? Need your help, Thanks a lot!!!

Jul 26, 2009 at 10:29 AM

Hi btdoctor, when querying a point layer you must buffer the query area by a small amount - search the forums - there are many examples hth jd