1

I am creating a WMS service made up of linestrings pulled from a POSTGIS database

I want to label the start of each line with a sequence number. At present I can label the centre of each with:-

 PROCESSING 'LABEL_NO_CLIP=1'  (to prevent repetition across tiles)
 ....
 LABEL
      COLOR 132 31 31
      TYPE TRUETYPE
      FONT "arialbd"
      SIZE 12
      POSITION AUTO
 END

This places the label in the middle of the line string. Any idea how to place it at the start?

Note that GEOMTRANSFORM "start" does not work with labels

  • sorry for saying this but I'd like to ask you a bit more of clarification to see if I can be of help here, do you need only the label at the end of each linestring? no matter what if it's the upper or lower end? – Gery Oct 1 '13 at 11:22
  • I need a single label at the start of the linestring – user1331131 Oct 1 '13 at 20:32
2

To my knowledge, there is no way to do that directly with mapserver. I have not tested this, but given you are using postgis you can probably get something close to what you want by creating a POINT layer and a specially crafted postgis query to extract the first point of each linestring. This would be something like:

layer
 type point
 name "line_start_labels"
 connectiontype postgis
 connection "blabla"
 data "start_point from (select ST_StartPoint(the_geom) as start_point, id, label_column from mytable) as foo using unique id using srid=XXXX"
 labelitem "label_column"
 class
  label
   #color, font, size, etc...
  end
 end
end

Note that in this case your label will not be oriented along the linestring, and that you will have to render the actual linestrings in a separate layer. You might be able to compute the angle to orient your label inside the postgis query, and bind that for mapserver:

data "start_point from ( select ...,
        -- some postgis/sql code to compute an angle in [0..360] from the first and second point -- as            orientation,
        ) as foo ...."
....
class
 label
  ...
  angle [orientation]
 end
end
0

try this:

LAYER
    LABELMAXSCALEDENOM      433344
    TOLERANCE               10
    TOLERANCEUNITS          pixels

            LABEL
                    BUFFER          10
                    SIZE            15
                    ANGLE           FOLLOW
                    POSITION        AUTO
                    MINFEATURESIZE  10
                    PRIORITY        10
                    PARTIALS        FALSE
                    FORCE           TRUE
                    ANTIALIAS       TRUE
            END

END

This has two properties:

  1. it allows me to have the label on the line (it fits to the feature, ie. line or point).
  2. it depends on a maximum scale, so labels don't get agglomerated after some specific zoom in/out.

At the end, with this I can move freely in my map and labels move at my pace, ie., if I follow one linestring the label will keep appearing once I move through the map. If you just need all labels no matter what scale you use, just get rid off of the LABELMAXSCALEDENOM property.

Hope this helps,

  • I am not sure that will achieve what I am after. For me it is important that the start of the linestring is labelled. I don't care about any other portion of the line. – user1331131 Oct 2 '13 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.