This project has moved and is read-only. For the latest updates, please go here.

I'm just not understanding how to create a label layer

Topics: SharpMap v0.9 / v1.x
Jul 27, 2012 at 4:04 PM

Sorry, I've read and read and just can't quite figure this out.

I'm building my map from data in an SQL database.  For each record I build a layer and add it to the map.  I need to add labels to this.  One post I read said that I should use a GeometryFeatureProvider in this instance.  I see that I can instantiate one of these using a FeatureDataTable (subclassed DataTable I assume).  I read another post about this that said I just need an X coordinate column, a Y coordinate column, and a Label name column.  I see when creating the Label Layer that there's a property for mapping the Label Name column but I don't see a property or way to map the X and Y coordinate columns.  What specific name do I need to use for these columns or is there something I'm not understanding/doing wrong here?

Thanks for any help!

Oh yeah, I'm using SharpMap v0.9

Jul 27, 2012 at 8:55 PM

Here is how I have done it. First we set up the database and then query it for the records we want.

   ' Add PostGIS site layer:
        Dim provider As SharpMap.Data.Providers.PostGIS
        SiteLayer = New SharpMap.Layers.VectorLayer("Site Layer")
        provider = New SharpMap.Data.Providers.PostGIS(tseConnection, "sites", "lonlat_nad83", "pk_sites")
        provider.DefinitionQuery = "jobnumber = '" & jobnumber & "'"
        SiteLayer.DataSource = provider

        With SiteLayer.Style
            .PointSymbolizer = SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateSquare(New Pen(Drawing.Color.Green, 3.0), Brushes.Coral, 15)
        End With

Now the labels

    'add label layer
        SiteLabels = New LabelLayer("Site Labels")
        SiteLabels.DataSource = provider
        SiteLabels.LabelColumn = "site_name"
        SiteLabels.RotationColumn = "symbol"
        SiteLabels.Style.Font = New Font("Ariel", 10)
        SiteLabels.Style.BackColor = Brushes.White
        SiteLabels.Style.ForeColor = Drawing.Color.MediumBlue
        SiteLabels.Style.Offset = offset
        SiteLabels.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left
        SiteLabels.Style.VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Top
Seems to work fine