This project is read-only.

GridColorBreak?

Jul 23, 2012 at 1:10 PM

Hello,

I'm buiding a GIS sofware and I have a problem with a fonction : GridColorBreak. I think I understand well the fonction of this class but it doesn't run in my program : I'm trying to apply a specific color for each value of a grid (it's a a land use). Those colors are placed in a vector called Color_Order( , ) and the corresponding categories in the second colum of this vector (I hope i'm clear...). The GridColorScheme is well affected by each categorie but in my map i have only the last categorie in color (the other categorie, even the "nodata" categorie" are in black). Do you have an idea to resolve this problem?

I placed my code just below:

            Dim Color_specific As MapWinGIS.GridColorBreak
            Dim Landuse As New MapWinGIS.Grid
            Dim COLOR_Landuse_Grid As New MapWinGIS.GridColorScheme
            Dim Show_Landuse As New MapWinGIS.Image
            Dim ConvertImage As New MapWinGIS.Utils
            Dim GridPath As String
            Dim GridPath As String
            Dim i As Integer

            'Path of the output file
            GridPath = Main.PathTEMP & "OUTPUT\luse.asc"
            'Clearing the breaks
            COLOR_Landuse_Grid.Clear()

            succes = Landuse.Open(GridPath)
            'We fill the grid color break with the color and the label than the user chose before
            For i = 0 To (Cell_Size.NLandUse - 1)
                Color_specific = New MapWinGIS.GridColorBreak
                Color_specific.LowValue = Cell_Size.Color_Order(Cell_Size.NLandUse - 1, 1)
                Color_specific.LowColor = Convert.ToUInt32(Cell_Size.Color_Order(Cell_Size.NLandUse - 1, 0))
                Color_specific.HighValue = Cell_Size.Color_Order(Cell_Size.NLandUse - 1, 1)
                Color_specific.HighColor = Convert.ToUInt32(Cell_Size.Color_Order(Cell_Size.NLandUse - 1, 0))
                Color_specific.Caption = Cell_Size.Label_Order(Cell_Size.NLandUse - 1, 0)
                COLOR_Landuse_Grid.InsertAt(i, Color_specific)
            Next

            'For the data "other" (not in the landuse)
            Color_specific = New MapWinGIS.GridColorBreak
            Color_specific.LowValue = (Cell_Size.Cat_Order.Max + 1)
            Color_specific.LowColor = Convert.ToUInt32(RGB(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B))
            Color_specific.HighValue = (Cell_Size.Cat_Order.Max + 1)
            Color_specific.HighColor = Convert.ToUInt32(RGB(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B))
            Color_specific.Caption = "Other"
            COLOR_Landuse_Grid.InsertAt(i, Color_specific)

            'Showing the grid file (which has to be convert into image before)
            Show_Landuse = ConvertImage.GridToImage(Landuse, COLOR_Landuse_Grid)
            Landusenum = Main.MapMain.AddLayer(Show_Landuse, True)
            Show_Landuse.UpsamplingMode = tkInterpolationMode.imNone
            LANDUSE_Level = Main.MapMain.get_LayerPosition(Landusenum)
Thank you

Jul 25, 2012 at 9:35 AM

I'm not sure what your problem is, but did you already have a look at the documentation?
http://www.mapwindow.org/documentation/mapwingis4.8/class_grid_color_scheme.html

Unfortunately I don't see some sample code in the documentation about the Grid Color Scheme.

 

--
Paul

Jul 25, 2012 at 10:19 AM

I already have a look to the documentation...

To be more clear, the user selected a color for each category of land use. I recorded those colors inside a vector and after the calculation of lot of things, I show a raster map with the reslut using those colors.

But I have something new, I got only 2 colors instead of 7 (not only one as before)....

Maybe I do something wrong with the affectation of the "GridColorScheme". Do I have to save it somewhere?

 

Thanks

 

Julien

Jul 26, 2012 at 6:28 PM
Edited Jul 26, 2012 at 6:32 PM

Here is how I add my grid and color it

            'Add Grid to Map
            Dim grid As New MapWinGIS.Grid
            'Open a grid. sometimes if file doesnt exist there will be a hard crash when grid.open is executed so we check for it.
            Dim grdName As String = My.Computer.FileSystem.CombinePath(My.Application.Info.DirectoryPath(), "Rasters\terrain\sta.adf")
            If My.Computer.FileSystem.FileExists(grdName) = True Then
                If grid.Open(grdName, MapWinGIS.GridDataType.LongDataType, True, MapWinGIS.GridFileType.UseExtension) = True Then
                    'create the grid coloring scheme
                    Dim scheme As New MapWinGIS.GridColorScheme
                    scheme = TerrainColorScheme(grid)

                    'convert the grid to an image
                    Dim img As MapWinGIS.Image
                    Dim util As New MapWinGIS.Utils()
                    img = util.GridToImage(grid, scheme)
                    'add the image to the map
                    hndTerr = leg.Layers.Add(img, True)
                    leg.Map.LayerName(hndTerr) = "Terrain"
                    leg.Layers.ItemByHandle(hndTerr).Type = MapWindow.Interfaces.eLayerType.Grid
                    grid.Close()
                    map.SetImageLayerColorScheme(hndTerr, scheme)
                    'display the categories in the legend
                    leg.Layers.ItemByHandle(hndTerr).Expanded = True
                    leg.Layers.ItemByHandle(hndTerr).Refresh()
                Else
                    MsgBox("Could not open the terrain grid [Error in open].", MsgBoxStyle.Critical)
                End If
            Else
                MsgBox("Could not open the terrain grid [File does not exist].", MsgBoxStyle.Critical)
            End If

And my scheme function looks like

        Dim scheme As New MapWinGIS.GridColorScheme()
        Dim fmt As String = "F0" 'F0 will give us a whole number with no decimals

        'the color that will be displayed when there is no data
        scheme.NoDataColor = System.Convert.ToUInt32(RGB(0, 0, 0)) 'black

            Dim brk As MapWinGIS.GridColorBreak 'declare it once and then every time we use it instantiate a new object
            brk = New MapWinGIS.GridColorBreak
            brk.GradientModel = MapWinGIS.GradientModel.Linear
            brk.ColoringType = MapWinGIS.ColoringType.Gradient
            brk.LowValue = -500
            brk.HighValue = -100
            brk.LowColor = ColorToUInteger(Color.Aqua)
            brk.HighColor = ColorToUInteger(Color.Aqua)
            brk.Caption = brk.LowValue.ToString(fmt) & " - " & brk.HighValue.ToString(fmt)
            scheme.InsertBreak(brk)

            'from 100 to 3000
            brk = New MapWinGIS.GridColorBreak
            brk.GradientModel = MapWinGIS.GradientModel.Linear
            brk.ColoringType = MapWinGIS.ColoringType.Gradient
            brk.LowValue = 100
            brk.HighValue = 3000
            brk.LowColor = ColorToUInteger(Color.Khaki)
            brk.HighColor = ColorToUInteger(Color.Khaki)
            brk.Caption = brk.LowValue.ToString(fmt) & " - " & brk.HighValue.ToString(fmt)
            scheme.InsertBreak(brk)

        'return the scheme that was prepared
        Return scheme

Jul 27, 2012 at 1:06 PM

Thanks for you're code!

It helps me a lot but I was wrong before the use of the girdbreakcolor... I found my mistake, I did not filled well my vector of color when the user clicked, and I kept only the last color ... Thats' why!

Thanks for all,

 

Julien