Save areas of Map where user has clicked

Topics: Data Access, SharpMap v0.9 / v1.x, Web Controls, WinForms Controls
Jun 20, 2011 at 7:29 AM

I am using Sharpmap v 0.9 & ASPX.NET

My shapefile has several polygons in it. Each time a user clicks inside a polygon, the polygon should be added to a selected set. All the polygons in the selected set should have a fill color of Red.

If the user selects an already selected polygon, the polygon should be removed from the selected set and the color should be rest back to the original color

I have the code to select a polygon working. Currently, when I click on the next poylgon, the 1st polygon is deselected & the the new polygon is selected. i.e I have not saved the set.

Does SharpMap have any built-in functions/samples to achieve this?

What will be a good approach to achieve this functionality?

Jun 20, 2011 at 11:14 AM

Hello tarana,

I'd use a GeometryFeatureProvider along with a VectorLayer. Create yourself a FeatureDataTable with an FeatureId column that matches the feature id of the selected polygon.

Every time a polygon is clicked, you need to check if it is already included in the GeometryFeatureProvider and thus needs to be removed, otherwise you need to add it and invalidate the map.

Hth FObermaier


Jun 20, 2011 at 8:59 PM
Edited Jun 21, 2011 at 7:02 AM

1. Feature ID of the selected polygon - Presume it is a field in the Shapefile.DBF or does ShapeMap create an internal ID?

2. Can I save the FeatureDataTable to a Database?

3. When I open the application next time, can I read the database to load into the VectorLayer?

4. I was thinking of using Microsoft Access for the initial cut and once I have the code working use SQL database. Is there any eaxmple code for this?


Jun 21, 2011 at 12:25 PM

If you derive yourself a Provider from GeometryFeatureProvider, you can do -almost- all you like to do with it, especially all of the above.

Hth FObermaier

Jun 22, 2011 at 1:13 AM
Edited Jun 22, 2011 at 2:01 AM


Is there an example on how to save the FeatureDataTable to a database?

Does SharpMap assign each polygon on the map a unique object ID? If so, how can I retrieve it?