Displaying variations in data obtained from postGIS database

Topics: SharpMap v0.9 / v1.x
Oct 17, 2009 at 9:13 AM

Hi,

I need to display/render the variation in some data (polygon or line data) obtained from a PostGIS database, based on a certain condition (based on a value in a particular column in the database) using different set of colours.

What is the way to do it? How could I do the filtering operations?

Thanks.

 

Coordinator
Oct 17, 2009 at 12:51 PM

Hi supunmali, see http://sharpmap.codeplex.com/wikipage?title=Styling%20based%20on%20feature%20data&referringTitle=Change%20rendering%20styleshth jd

Oct 17, 2009 at 1:52 PM

Thank you very much, I didnt know its theming..  Is that means, if I am using custom theme, I need to get the dataset (from the database) and convert it into FeatureDataTable and need to go thru each row with a foreach loop?  

Thanks again

Coordinator
Oct 17, 2009 at 2:14 PM

Hi Supunmali, you do not need to loop through the table - you just provide a delegate which selects or creates the correct style based on the record and returns it.. The renderer takes care or looping and apply styles by itself.. hth jd

Oct 17, 2009 at 7:11 PM

Thank u so much Johndiss, it works really fine!!!!.

 

Thought of attaching what I did too.

 

 public void BuildingsBufferLayer()

{
	VectorLayer.DataSource = new SharpMap.Data.Providers.PostGIS(ConnStr, "vw_buffer_result", "the_geom", "id");
        SharpMap.Rendering.Thematics.CustomTheme myTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetBuildingStyle);
VectorLayer.Theme = myTheme; } private SharpMap.Styles.VectorStyle GetBuildingStyle(SharpMap.Data.FeatureDataRow row) { SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); if (row["id"].ToString()== buildingid) { style.Fill = Brushes.RoyalBlue; style.Outline = Pens.DarkBlue; style.EnableOutline = true; } else { style.Fill = Brushes.BurlyWood; style.EnableOutline = false; } return style; }

 

 

  VectorLayer.DataSource = new SharpMap.Data.Providers.PostGIS(ConnStr, "vw_buffer_result", "the_geom", "id");
            SharpMap.Rendering.Thematics.CustomTheme myTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetThreatStyle);
            VectorLayer.Theme = myTheme;