Thematic map with external data

Topics: Data Access, General Topics, Web Controls
Oct 14, 2009 at 12:28 PM


I am trying to use sharpmap for the following requirement.

I want to create a web application which has a world map that gets dynamically rendered (gradient) based on values from external database of countries. I could able to use Gradient them of sharpmap successfully to generate the map, this gets generated based on feature data column of shape file.  How can I link external database (MySQL / MS SQL Server) to this shape file and generated thematic maps dynamically.

Please help...

Thanks and Regards


Oct 14, 2009 at 2:29 PM

Hi Rajesh, one option would be to call out from within a CustomTheme to the database - watch the performance though, so don't call row by row if you can help it.. hth jd

Oct 15, 2009 at 4:26 AM

Hi John,

Thanks for the reply.. Can u pls help me with a sample code...


Oct 15, 2009 at 3:00 PM

Hi Rajesh, I have made a slight modification to the GradientTheme code - there is now a GradientThemeBase class which you can subclass.

So you can do something like:


using System;
using System.Collections.Generic;
using System.Text;
using SharpMap.Rendering.Thematics;
using SharpMap.Data;
using SharpMap.Styles;

namespace ExampleCodeSnippets
    public class ExtendedGradientTheme : GradientThemeBase
        public ExtendedGradientTheme(double min, double max, IStyle minStyle, IStyle maxStyle)
            : base(min, max, minStyle, maxStyle)
        { }

        protected override double GetAttributeValue(FeatureDataRow row)
            //do something to lookup an appropriate value from a database or alternate store based on your row
            //for now we will just return a random number between min and max
            return new Random((int)DateTime.Now.Ticks).NextDouble() * (Max - Min) + Min;

hth jd
Oct 19, 2009 at 2:33 PM

Hi John,

Thanks for your reply.  I did not find GetAttributeValue method in updated GradientTheme class... Pls help us with a sample application which suits my requirement.  As I mentioned, my requirement is to match records of shapefile and external database (based on country name/id) and render image (gradient) based on values of external database.



Oct 19, 2009 at 2:43 PM
Edited Oct 19, 2009 at 2:46 PM

Hi Rajesh, you need to get the latest sharpmap code from the source code tab and build that (from the trunk directory)  then you can subclass GradientThemeBase as above...

Oct 20, 2009 at 4:33 AM

Hi John,

I have downloaded latest sharpmap (sharpmap-60134) and tried to build sharpmap under trunk directory.  But, i was unable to build the same as I am gettting number of build errors viz., Type expected, Syntax error, Invalid expression term etc., (more than 200)... what could be the problem?  I am using .Net Framework 2.0 & VS 2005.  Can u place updated dll anywhere for download?  Also pls help me with sample application for my requirement, if u can! Thanks in advance.


Oct 20, 2009 at 9:00 AM

Hi Rajesh, use Vs2008 if you cant use that try using MonoDevelop.. jd

Oct 22, 2009 at 10:19 AM

Please see updated binaries on downloads page hth jd