distinct colour for sublayer in a layer

Topics: SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0
Dec 21, 2011 at 7:23 AM

i want to display different static colour for sub layer in a layer.using postgis database.. can't create feature data row and can;t pass

that parameter in function... help me out to create function with featuredatarow ..

Thanks in advance

Developer
Dec 21, 2011 at 7:58 AM

Hi j_nip,

May be, you should use CustomTheme class. Search how to use customtheme in this. There are a lot of discussions about that.

TrieuVy

Dec 21, 2011 at 9:06 AM

hi developer.. how to use that class... i went through that also but i couldn't get result... jst say i have layer( table on postgis) called "SSRN" and in that table

column called typestatus so what i want is when case is select for typestatus say case row("typestatus")

case "PL"

style.line=Pens.Green

but it changes whole layer line colour...into green.... can u pass how i can use customtheme class...

Developer
Dec 22, 2011 at 3:05 AM
Edited Dec 22, 2011 at 3:07 AM

 

// Create custom style foreach data rows

private SharpMap.Styles.VectorStyle GetCustomStyle(SharpMap.Data.FeatureDataRow row)
        {
                SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();
                if (row["typestatus"].ToString().Equals("PL"))
                {
                    style.Line = new Pen(Color.Green, 1);
                    style.Outline = new Pen(Color.Gray, 2);
                }              
                return style;
        }

// Set Custom theme for layer

_layer.Theme = new SharpMap.Rendering.Thematics.CustomTheme(GetCustomStyle);

 

TrieuVy

Dec 22, 2011 at 6:18 AM

how to pass value on featuredatarow. there is error on passing getcustomstyle...how to create featuredatarow..

Dec 22, 2011 at 6:29 AM

my function code is

Private Function GetCustomeStyle(ByVal row As FeatureDataRow)
        Dim tab As String = """SSRN"""
        Dim sqls As String = "SELECT * from  " & tab & ""
        Dim cmds As New NpgsqlDataAdapter(sqls, npgconnection)
        Dim tbl As New DataTable
        Dim redd As SharpMap.Data.FeatureDataRow
        cmds.Fill(tbl)
        For i = 0 To tbl.Rows.Count - 1
            redd = tbl.Rows(i)
            For Each rowss As DataRow In tbl.Rows
                Dim style As SharpMap.Styles.VectorStyle = New SharpMap.Styles.VectorStyle
                If row("typestatus").ToString().Equals("PL") Then
                    style.Line = New Pen(Color.Green, 1)
                    'style.Outline = New Pen(Color.Gray, 2)
                End If
                Return style

            Next
        Next
        Dim laystyle As SharpMap.Layers.VectorLayer = New SharpMap.Layers.VectorLayer("SSRN")
        laystyle.Theme = New SharpMap.Rendering.Thematics.CustomTheme(GetCustomStyle)
        Return Nothing

    End Function

there is error on passing getcustomstyle

and when try to call function .. featuredatarow is needed to pass which i can't get it ...

Developer
Dec 22, 2011 at 6:46 AM

GetCustomeStyle is a function 

laystyle.Theme = New SharpMap.Rendering.Thematics.CustomTheme(GetCustomStyle) wrirte out of GetCustomeStyle function.

EX: when you create new layer to add to map

   Dim laystyle As SharpMap.Layers.VectorLayer = New SharpMap.Layers.VectorLayer("SSRN")
   laystyle.Theme = New SharpMap.Rendering.Thematics.CustomTheme(this.GetCustomStyle) // if GetCustomStyle and create layer function  in the same class.

Dec 22, 2011 at 7:20 AM
Edited Dec 22, 2011 at 8:23 AM

error while calling function..

Unable to cast object of type 'SharpMap.Styles.VectorStyle' to type 'GetStyleMethod'.

return style .. use

Developer
Dec 22, 2011 at 8:17 AM

Please use like this, GetCustomStyle function have to return SharpMap.Styles.VectorStyle. In this function, you don't need access database.
Only follow my example.


// Create custom style foreach data rows private SharpMap.Styles.VectorStyle GetCustomStyle(SharpMap.Data.FeatureDataRow row) { SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); if (row["typestatus"].ToString().Equals("PL")) { style.Line = new Pen(Color.Green, 1); style.Outline = new Pen(Color.Gray, 2); } return style; } // Set Custom theme for layer _layer.Theme = new SharpMap.Rendering.Thematics.CustomTheme(GetCustomStyle);

Dec 22, 2011 at 9:06 AM

while debug there is error Object reference not set to an instance of an object.

on row("typestatus") where row is featuredatarow so how to get featuredata row if there is no need to connect database...

Developer
Dec 22, 2011 at 9:17 AM
Edited Dec 22, 2011 at 9:19 AM

You have to sure: layer.Datasource  is mapping to table that have "typestatus" colunm name,

after that you set layer.Theme =new SharpMap.Rendering.Thematics.CustomTheme(GetCustomStyle);

GetCustomStyle is a delegate method and it will access database when render layer

Dec 22, 2011 at 10:04 AM

layRoads.DataSource = New SharpMap.Data.Providers.PostGIS(connStr, lay("tablename").ToString, idColumn)

where lay("tablename")=SSRN where ssrn is line polygon

in ssrn there is typestatus column with

error occur says.."value of type sharpmap.style.vectorstyle cannot be converted to sharpmap.rendering.themetics.custometheme.GetStyleMethod"

layer displayed but no customstyle.. gradient theme works fine. could you provide me any project related to this of line polygon with custome style ... my all effort going in vain...

can mail me j_shrestha@live.com

Thank s

Dec 28, 2011 at 5:35 AM

Private Function GetCustomeStyle(ByVal row As FeatureDataRow) As SharpMap.Styles.VectorStyle
     
        Dim style As SharpMap.Styles.VectorStyle = New SharpMap.Styles.VectorStyle
              Select Case row("typestatus")
            Case "PL"
                style.Line = New Pen(Color.Green, 5)
                Return style
            Case "UC"
                style.Line = New Pen(Color.Blue, 10)
                Return style
        End Select

return nothing

end function

** where to put this function and how to get featurerow as paramenter..

Developer
Dec 28, 2011 at 6:21 AM

HI J_nip,

- can not return nothing in GetCustomStyle  method. You should use default value

   Dim style As SharpMap.Styles.VectorStyle = New SharpMap.Styles.VectorStyle
              Select Case row("typestatus")
            Case "PL"
                style.Line = New Pen(Color.Green, 5)
                Return style
            Case "UC"
                style.Line = New Pen(Color.Blue, 10)
                Return style
             Default
                style.Line= New Pen(Color.Black, 10)
                return style
        End Select