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

How to highlight countries on a world map based on data from SQL server database

Topics: Data Access, General Topics, SharpMap v0.9 / v1.x, Web Controls, WinForms Controls
Nov 4, 2008 at 5:20 PM
Edited Nov 4, 2008 at 5:24 PM

I am working on a project where I attributed a number to a country in my database (SQL Server 2005) showing distribution of my target in each country and I did the same for each province/state in each country. Now, I need to program a user interface that can show this distributions by highlighting the countries on the world map in different colors base on the categories of my numbers and also can do the same for provinces/states of each countries when we click on that country on the world map. I am programming in VB.Net.

I don't know if it is possible in SharpMap but I would appreciate for any help.

Nov 5, 2008 at 11:39 AM
Hi nemesis52, it is definately possible. You can use custom themes to alter the rendering based on attributes in the datasource. hth jd
Nov 5, 2008 at 10:19 PM
Dear JohnDiss,
Thanks for your guidance. I would be grateful if you can explain me in more details or to show me a simple example in VB.Net as I am a newbie in GIS and mapping systems.

Thanks again
Nov 5, 2008 at 11:11 PM
There are a couple of demos in vb which can be downloaded from (page 2 by joane3005) then there is some useful information on the 'How To' wiki page but they are in C#. Personally I work mostly in C# so I don't really have any complete vb examples to share maybe somebody else will step in to help? Cheers jd
Nov 6, 2008 at 4:26 AM
Edited Nov 6, 2008 at 4:29 AM
I'm a newbie in GIS and i have the same problem.
have U any complete code in c# that show me how to highlight countries using sql server data
thank U.
Nov 6, 2008 at 11:33 AM
Hi mrharry, how is your data stored?  MsSqlSpatial or Sql2008? there isn't a sql2008 provider for SharpMap 0.9/1.x.
I don't have an example I can share but: 
Use as a starting point  and swap the reference 'SharpMap.Providers.PostGIS' to 'SharpMap.Providers.MsSqlSpatial' (or any of the other providers) hth jd
Nov 6, 2008 at 6:14 PM
thanks 4 ur quick reply :*
i use sql2000 and oracle 10g
but i need a sample code 4 sql2000
ur link seems useful & try that ASAP
thanks again
Nov 6, 2008 at 6:27 PM
Sql 2000 doesn't have any spatial support and will not work with the MsSqlSpatial provider (it requires sql 2005 or later and extra CLR components to be installed on the server ), so it will not be very useful (apart from maybe with points) hth jd
Nov 12, 2008 at 6:45 AM
Edited Nov 12, 2008 at 6:48 AM
Hi JohnDiss,
I have a problem:
when i click on the map. I get feature on this area. Example that area is USA. I use method ExecuteIntersectionQuery . But result is a table include 2 row, it is not exactly.
So, can you tell me 1 solution
here is code:

if (Request.QueryString["pntx"] != null && Request.QueryString["pnty"] != null)

                SharpMap.Geometries.Point ClickPnt = new SharpMap.Geometries.Point(Convert.ToDouble(Request.QueryString["pntx"].ToString()), Convert.ToDouble(Request.QueryString["pnty"].ToString()));
                SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
                SharpMap.Geometries.BoundingBox bx = ClickPnt.GetBoundingBox();
                (ajaxMap.Map.Layers[0] as SharpMap.Layers.VectorLayer).DataSource.ExecuteIntersectionQuery(bx, ds);
                GridView1.DataSource = ds.Tables[0];
Nov 12, 2008 at 10:55 AM
Hi sdd, without knowing the data it is a hard call, can you check the data in a different viewer? cheers jd