3
votes

I'm trying to show a map using postGIS+Mapserver. And I've displayed a PNG picture in my WEB. However, I want to show some charactors in the map, just like this: mapserv demo http://demo.mapserver.org/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/example1-4.map&layer=states_poly&layer=states_line&mode=map

this is the example from Mapserver

Now I'm using database(postgreSQL), but not a shape file. How can I add the charactors then?

Here is a part of my mapfile:

LAYER
  CONNECTIONTYPE postgis
  NAME "state"
  //Connect to a remote spatial database
  CONNECTION "user=postgres dbname=*** host=*** password=***"
  PROCESSING "CLOSE_CONNECTION=DEFER"
  DATA "the_geom from province"
  STATUS ON
  TYPE POLYGON
  CLASS
    STYLE
      COLOR 122 122 122
      OUTLINECOLOR 0 0 0
    END
    LABEL
      COLOR 132 31 31
      SHADOWCOLOR 218 218 218
      SHADOWSIZE 2 2
      TYPE TURETYPE
      FONT arial-bold
      SIZE 12
      ANTIALIAS TRUE
      POSITION CL
      PARTIALS FALSE
      MINDISTANCE 300
      BUFFER 4
    END
  END
END

Some said adding a "TEXT ([*])" in "LABEL", but I don't know howto?

Thanks for your help!

2

2 Answers

1
votes

You should use the LABELITEM directive with the name of the table's field containing the text you want to render:

...
DATA "the_geom from province"
LABELITEM "<field_name>"
STATUS ON
...

Check the map file documentation for further details

http://mapserver.org/mapfile/layer.html

0
votes

The amercader's answer above is quite correct. However, I solved it from amercader's help, but a bit differences, just using subquery.


Here is a sectional code:

LAYER
  CONNECTIONTYPE postgis
  NAME "state"
  //# Connect to a remote spatial database
  CONNECTION "user=postgres dbname=*** host=*** password=***"
  PROCESSING "CLOSE_CONNECTION=DEFER"
  DATA "the_geom from (select gid, the_geom, name from province) as subquery using unique gid using srid=4326"
  STATUS ON
  TYPE POLYGON
  LABELITEM "name"
  CLASS
    STYLE
      ...
    END
    LABEL
      ...
    END
  END
END

The key point is "data" attribute, adding a subquery; as well as the "labelitem"'s parameter must be the same as selecting in subquery.

amercader told me that the subquery is unnecessary (see comments). It's cool!

I hope these words can give a helping hand to other programmers using the mapserver. And thanks amercader.