views:

177

answers:

3

Hello. 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

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!

+1  A: 

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

amercader
A: 

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.

sirius
You should probably mark amercader's answer as correct and give them an upvote..
geographika
I don't think you need to do a subquery in the connection parameter if the `name` column is in the `province` table. Leave it as just `"the_geom from province using unique gid using srid=4326"` and see if labels show up (they should). Subqueries are expensive and have only meaning in some cases, like when you have to perform a join with a table that contains extra attributes. Maybe I didn't get it right from your examples, but this doesn't seem to be your case.Here are some examples:http://postgis.refractions.net/docs/ch05.html#id2801160
amercader
You're right, amercader, thank you very much! I read the documentation about the postGIS ( http://mapserver.org/input/vector/postgis.html ), and assumed so. I'm wrong.
sirius
A: 

hey guys am having the same problem only that mine wont go away, the LABELITEM still not displaying code is given below

LAYER NAME 'shops' TYPE POLYGON CONNECTIONTYPE postgis CONNECTION "dbname='db' host=localhost port=5432 user='postgres' password='pass'" DATA "the_geom FROM shops USING UNIQUE gid USING SRID=-1" METADATA 'wms_title' 'shops' END STATUS DEFAULT TRANSPARENCY 100 PROJECTION 'proj=longlat' 'ellps=WGS84' 'datum=WGS84' 'no_defs' '' END LABELITEM 'id_number' STATUS ON

CLASS
   NAME 'shops' 
   STYLE
     SYMBOL 0 
     SIZE 2 
     OUTLINECOLOR 0 0 0
     COLOR 97 136 146
   END
END

END

thanks for any help

geekmate
Sorry, I've no idea. I'm also a beginner...In my opinion, you don't need so many attribute or options. first, showing a simple one may be better. http://mapserver.org is a good choice. good luck!
sirius
Please create a new question if you are not providing an answer to the current one (You can link to this question if you want). Otherwise your question won't be noticed and answers won't be reviewed.You must place a LABEL ... END section inside the CLASS ... END section to have the labels displayed. Check http://mapserver.org/mapfile/label.html
amercader