Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am new to Sharpmap and GIS. Going through the sample code and building simple programs for better understanding. I have a water bodies layer. I want to display only a particular river. I used CustomTheme. How to show label for only this river.

To display a river (named Ganga), I have written following code.

SharpMap.Data.Providers.ShapeFile shapeFileProvider = new SharpMap.Data.Providers.ShapeFile(@"C:\water.shp", false);
SharpMap.Layers.VectorLayer waterLayer = new SharpMap.Layers.VectorLayer("Water", shapeFileProvider);

SharpMap.Rendering.Thematics.CustomTheme waterTheme = new  SharpMap.Rendering.Thematics.CustomTheme(GetWaterStyle);
waterLayer.Theme = waterTheme;

The GetWaterStyle method:

private SharpMap.Styles.VectorStyle GetWaterStyle(SharpMap.Data.FeatureDataRow row)
    SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();
    if (row["NAME"].ToString().Equals("Ganga"))
        style.Fill = Brushes.Aqua;
        return style;
        return null;

Now I want to show a label "Ganga" (the river name) as well. How to approach?

Please help.

Thanks and regards, Abhi

share|improve this question

You can do something like this:

    //Proivder for labels only fetching one river
    SharpMap.Data.Providers.ShapeFile shapeFileProviderLabels = new SharpMap.Data.Providers.ShapeFile(@"rivers.shp", false);
    shapeFileProviderLabels.FilterDelegate += new SharpMap.Data.Providers.FilterProvider.FilterMethod(delegate(FeatureDataRow row) { return row["NAME"] as string == "Ganga"; });
    int cnt = shapeFileProviderLabels.GetFeatureCount();

    SharpMap.Layers.VectorLayer waterLayer = new SharpMap.Layers.VectorLayer("Water", shapeFileProvider);

    //Layer for labels
    SharpMap.Layers.LabelLayer waterLabels = new SharpMap.Layers.LabelLayer("Water_Labels");
    waterLabels.LabelColumn = "NAME";
    waterLabels.DataSource = shapeFileProviderLabels;


There has been an bug/issue with the FilterDelegate of ShapeFile provider in SharpMap, this is fixed and included in SharpMap 1.0 RC1 that is newly released

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.