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

how to get polygon detail when user click it.

Topics: Data Access, SharpMap v0.9 / v1.x, Web Controls
Feb 21, 2008 at 8:11 AM
I am displaying shapes on web through Sql Server2005. how to get ploygon id when user click it. i want to display detail of that polygon.
Feb 22, 2008 at 5:30 AM
I am using this code but gets more than one polygons. how to solve this

SharpMap.Geometries.Point p = new SharpMap.Geometries.Point(e.X, e.Y);
SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
string connstr = ConfigurationManager.ConnectionStrings"GeoDatabase".ConnectionString;
SharpMap.Data.Providers.MsSql data1 = new SharpMap.Data.Providers.MsSql (connstr, "cata", "WKBGeometry", "oid");
SharpMap.Layers.VectorLayer layer = myMap.Layers0 as SharpMap.Layers.VectorLayer;
SharpMap.Geometries.BoundingBox bbox = myMap.ImageToWorld(new System.Drawing.Point(e.X, e.Y)).GetBoundingBox().Grow(myMap.PixelSize * 5);
data1.ExecuteIntersectionQuery(bbox, ds);
dd.DataSource = ds.Tables0;
TextBox1.Text = ds.Tables0.Count.ToString();
Feb 22, 2008 at 6:55 AM
The bounding boxes of the polygons probably overlap, and so more than one polygon satisfies the ExecuteIntersectionQuery.

There isn't much of a way around this in SharpMap v0.9, unless you want to use the NTS provider, which performs correct spatial operations, like the intersection you are trying to perform.

When I was using v0.9, I would just bind to a control which would allow one of them to be chosen. It worked for my needs.
Feb 26, 2008 at 6:19 AM
Another way to get correct result is to use MSSqlSpatial provider. It also returns accurate results in click operations. sqlprovider sometimes returns 2,3 polygons on click on one feature.
Feb 26, 2008 at 7:32 AM
Ah, good call Sumeet...

The provider Sumeet mentions is here: MsSqlSpatial.