[mapserver-users] LABEL - POSITION and FONT Calculations

Donald Kerr donald.kerr at dkerr.co.uk
Mon Dec 29 16:51:34 EST 2008


Jose,

All understood. I'll try your suggestions tomorrow.

Many thanks.

Regards,

Donald


-----Original Message-----
From: José María Michia [mailto:jose.maria.michia at gmail.com] 
Sent: 29 December 2008 15:33
To: Donald Kerr
Cc: mapserver-users at lists.osgeo.org
Subject: Re: [mapserver-users] LABEL - POSITION and FONT Calculations


2008/12/29 Donald Kerr <donald.kerr at dkerr.co.uk>:
> I have a problem that has me stumped.
>
> I am trying to place text on a map as a LABEL which I can successfully do
> with the following code:
>
> LAYER CONNECTIONTYPE postgis
>        NAME "CartographicText"
>        CONNECTION "user=postgres dbname=MasterMap host=localhost"
>        DATA "geom FROM (SELECT toid, featurecode, textstring,
> orientation/10 AS orientation, fontnumber, anchorposition, textstyle, geom
> FROM cartographictext) AS foo USING UNIQUE toid"
>
>        METADATA
>                "IMAGEFORMAT" "AGGA"
>        END
>
>        STATUS DEFAULT
>
>        MINSCALEDENOM 1
>        MAXSCALEDENOM 1300
>        SYMBOLSCALEDENOM 1250
>
>        TYPE ANNOTATION
>
>        LABELITEM textstring
>
>        CLASS
>                # Road Name Or Classification
>                EXPRESSION ([featurecode] = 10169)
>                LABEL
>                        TYPE truetype
>                        FONT arial
>                        SIZE 10
>                        MAXSIZE 30
>                        MINSIZE 0
>                        COLOR  0 0 0
>                        ANTIALIAS TRUE
>                        ANGLE [orientation]
>                END # LABEL
>        END # CLASS
>
>        CLASS
>                # Building or Structure Text
>                EXPRESSION ([featurecode] = 10026)
>                LABEL
>                        TYPE truetype
>                        FONT arial
>                        SIZE 7
>                        MAXSIZE 21
>                        MINSIZE 0
>                        COLOR  0 0 0
>                        ANTIALIAS TRUE
>                        ANGLE [orientation]
>                END # LABEL
>        END # CLASS
>
> END # LAYER
>
> I want to add POSITION based on [anchorposition] from the database.
>
> The database grid for anchorposition is as follows:
>
> 2  5  8
> 1  4  7
> 0  3  6
>
> Whereas MapServer is as follows
>
> ul uc ur
> cl cc cr
> ll lc lr
>
> Which is probably:
>
> 0  1  2
> 3  4  5
> 6  7  8
>
> The question is: Is it possible to take the values from the database and
> convert them for use within the LABEL e.g. 2 = ul = "POSITION ul" or 5 =
uc
> = "POSITION uc"?

I think that, yes! The numeric values for these constants are defined
in mapserv.h:

enum MS_POSITIONS_ENUM {MS_UL=101, MS_LR, MS_UR, MS_LL, MS_CR, MS_CL,
MS_UC, MS_LC, MS_CC, MS_AUTO, MS_XY , MS_FOLLOW};

The positions following to the MS_UL, adopt their values automaticly
(MS_LR=102, and so on).

> I would also like to be able to change the Font based on [fontnumber] from
> the database e.g. 0 = Arial = "FONT arial" or 1 = Times = "FONT times"
>
> Are these things possible?

Yes again. You must define your fonts in a FONTSET file. These file
have entries like this one:

"times   /archivos/mapping/fonts/times.ttf
arial   /archivos/mapping/fonts/arial.ttf
..."

The first column, is the name of the font, and the second column is
the full path to the font. You can choose the name, so you can choose
a number as font name:

0   /archivos/mapping/fonts/times.ttf
1   /archivos/mapping/fonts/arial.ttf
...

I'm not sure if numbers are allowed in font names. Anyway, you can do
some string manipulation to get the desired result.

> Many thanks.
>
> Regards,
>
> Donald Kerr
>

I hope I have understood. And I hope that you understand myself.

Saludos
José María



More information about the mapserver-users mailing list