Custom Rendering Styles with external variable

Topics: SharpMap v0.9 / v1.x, Web Controls
Jul 15, 2008 at 7:59 AM
Hi all,

I have been looking through the source code about how to define custom rendering styles based on an external variable. When using shapefiles to define the map, like I do, the information seems to be retrieved from the DBF file. Is it possible to hand some other variable to be measured? Like an array of some sort of structs?

Thanks in advance

Jul 15, 2008 at 9:16 AM
Hi Chris, you can either copy the relevant data into a FeatureDataTable and use a FeatureGeometryProvider instead of the shapefile (example of building such a provider:
 or you could call _out_ of your styling method to retrieve data from an accessible place, in the case of an array, it may be difficult to know which index relates to a given dbf record (unless they are already ordered of course). Ideally you could use some attribute in the dbf table to look up a value elsewhere... hth jd
Jul 15, 2008 at 9:27 AM
Hi John,

That code you linked to looks like it might be promising, I'll knock together some test code later today, see what I can work with. On another note, I'm developing with v0.9 at the moment as I need a stable platform but how much of a rewrite is it going to be moving to v2.0 when it's stable?


Jul 15, 2008 at 10:09 AM
Edited Jul 15, 2008 at 12:07 PM
Hi Chris, v2 is a different beast but shares many similarities; in terms of how much of a rewrite, a lot depends on how much code duplication your app has. The more code re-use your app enjoys the less pain you will suffer.. For a simple app I dont think it will be too bad once you have got your head around the basics. hth jd
Jul 17, 2008 at 11:56 AM


I have thought about this and I have decided to go down the route of a custom FeatureDataTable but, probably because of my unfamiliarity with the framework, I seem to be going round in circles.

But, as they say, the first stage in obtaining a solution is defining the problem so this is what I'm trying to do.

I have a shapefile which contains a polyline of many points. I also have a database, of some form, containing points on the line and a variable value, e.g. altitude for arguments sake. What is the best way to overlay this information as false color with interpolation between data points?

My instinct, based on what I know so far, is to load the shapefile into a FeatureDataTable myself. Then insert the data as extra points on the line containing the variable and then use some sort of custom RenderStyle. Am I on the right track?



Jul 17, 2008 at 2:10 PM
Hi Chris, It would definately work, my tactic would be: 
first create a FeatureDataSet
Pass it into your shapefile providers ExecuteIntersectionQuery method,
dig your table back out of the dataset
add your new columns to it
loop through adding your derived data
hth jd
Jul 18, 2008 at 9:26 AM
Hi John,

I have created this, as you suggested, but am stuck at how to add this to a layer. I.e. How do I convert a SharpMap.Data.FeatureDataSet into something I can pass to SharpMap.Layers.VactorLayer.DataSource?


Jul 18, 2008 at 9:41 AM
Ok, I think I have it, I need to convert the FeatureData*Table* not FeatureData*Set*. :).
Jul 18, 2008 at 10:22 AM
Thats right, you initially populate the dataset, from which you retrieve the datatable to use in your GeometryFeatureProvider. Good luck jd 
Jul 18, 2008 at 2:01 PM
Hi John,

I have come up against an interesting problem. SharpMap.Data.Providers.GeometryProvider does not support feature information and as far as I can see the class GeometryFeatureProvider does not exist

What should I do?

Jul 18, 2008 at 2:42 PM
Turns our you need the latest v1.1 to get GeometryFeatureProvider so that's now sorted.

Next problem is that the theme throws an exception because some of the line points do not have data associated with them. Does this mean I need to interpolate the value across all the line points before it will work?


Jul 21, 2008 at 2:06 PM
Hi Chris, there is a GeometryFeatureProvider in the trunk as well (Data/Providers). As far as interpolation goes, It probably is easiest to do it up front. hth jd
Jul 22, 2008 at 12:39 PM
Hi John,

I have implemented things like you said but I have come up against a problem. My map (well the part of the map thet I'm trying to colour at the moment) is made up of a set of 24 line segments. There are however some sections of the map where there are multiple data points for a single line segment. How can I render this data? Do I need to break the line up into multiple line segments for this to work?


Jul 22, 2008 at 12:48 PM
Edited Jul 22, 2008 at 12:55 PM
Hi Chris, from what you describe I think you would need to break up the lines as otherwise you can only have one attribute per linestring. Alternatively you could customise the rendering routine - in 0.9 that is a part of the layer in 1.1 it is extracted out to a different class. Thinking about it, splitting the lines is probably easiest..  hth jd 
Jul 22, 2008 at 12:58 PM
Could you recommend a good tool (preferably free) for editing the shapefile?


Jul 22, 2008 at 1:45 PM
Hi Chris, I dont use shapefiles very often and do most of my editing with NTS/MsSqlSpatial etc, but you could approach the problem a slightly different way:
load your shapefile into a FeatureDataSet,
Get your table out of it,
Create a new table with the same schema as the one above
then for each record in the first table get the linestring geometry
enumerate through the pairs of vertices in the original geometry,creating a new row with a new 2 point linestring and the attributes from the original row
insert your new row into the new table.

Then you can loop through the new table assigning your interpolated values and use the table for your GeometryFeatureProvider.
In v2 you would  then be able to save the data to a new shapefile. hth jd