Quantcast
Channel: MapWinGIS ActiveX Map and GIS Component
Viewing all articles
Browse latest Browse all 2341

New Post: [How-to] Colorize individual shapes

$
0
0
A lot of questions on the MapWindow/MapWinGIS forums are about the new categories. They are very powerful but for some simple tasks it was not so easy.

A few days ago Sergei introduced a few new methods to make it easier to assign a custom category to a shape.
These new methods made it in the Stable Release which I published just a minute ago. Go to the download section of this site.

We've created a C# example and a VB.NET example.
The C# version can be downloaded here: http://svn.mapwindow.org/svnroot/TestingScripts/TestColorUniqueShapes.cs
The VB.NET code is:
    Dim sf As Shapefile = New Shapefile()

    If sf.Open("C:\Users\Meems\Desktop\United States\Shapefiles\lakes.shp") Then
      Dim utls As Utils = New Utils()

      Dim ctOrange As ShapefileCategory = sf.Categories.Add("Orange")
      ctOrange.DrawingOptions.FillColor = utls.ColorByName(tkMapColor.Orange)

      Dim ctBlue As ShapefileCategory = sf.Categories.Add("Blue")
      ctBlue.DrawingOptions.FillColor = utls.ColorByName(tkMapColor.Blue)

      For i As Integer = 0 To sf.NumShapes - 1
        If i Mod 2 = 0 Then
          sf.ShapeCategory2(i) = "Orange"
        Else
          sf.ShapeCategory3(i) = ctBlue
        End If
      Next i

      For i As Integer = 0 To sf.NumShapes - 1
        System.Diagnostics.Debug.Print("Shape category: {0}, {1}", i, sf.ShapeCategory2(i))
      Next i

      For i As Integer = 0 To sf.NumShapes - 1
        System.Diagnostics.Debug.Print("Shape category: {0}, {1}", i, sf.ShapeCategory3(i).Name)
      Next i

      ' Add the data to the map:
      AxMap1.AddLayer(sf, True)
    End If
Please download the latest installer and update your project.
If you have questions, please post them here and we'll try to answer them.

Viewing all articles
Browse latest Browse all 2341

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>