A simple... sample !
Marco Marsella
m.marsella at ITWORKS.IT
Thu Feb 10 10:14:09 PST 2005
Hi list,
I just wanted to contribute to the list the little experience with
MapServer/PHP I have put together during the last couple of weeks. I
hope it will be useful to somebody and I will be more than happy to get
feedback for improvements!
The request was to provide a simple thematic mapping of data stored in
postgres tables on a single layer of a few south-east asian countries
at provincial level. No zoomig/panning and other map interactions were
required, so I opted for a simple PHP/Javascript approach.
Data is about socio-economic indicators such as literacy rate,
male/female population percentage and so on. The tables are:
- shapes: contains the vector layer with regid as the region ID used to
join with the data table
- data: contains provID as the key to join with shapes and dyear, indid
and value as, respectively, the year, the indicator and the actual
value
The mapfile and the php page are attached. Below some short description
of the main points:
The mapfile is based on the single layer:
LAYER
NAME "acthem"
TYPE POLYGON
STATUS ON
CONNECTIONTYPE POSTGIS
CONNECTION "user=xxx password=xxx dbname=xxx host=xxx port=xxx"
DATA "the_geom from
( select map.oid, map.the_geom, data.value
from asiacover.shapes as map left join (
select provid, value from asiacover.data
where dyear = %dyear% and indid = %indid%) as data
on (data.provid = map.regid)) as foo using srid=4326"
CLASS
EXPRESSION ([value] < 10)
NAME "First"
OUTLINECOLOR 0 0 0
COLOR 202 255 133
END
CLASS
EXPRESSION ([value] < 20)
NAME "Second"
OUTLINECOLOR 0 0 0
COLOR 255 255 133
END
CLASS
EXPRESSION ([value] < 30)
NAME "Third"
OUTLINECOLOR 0 0 0
COLOR 133 255 239
END
CLASS
EXPRESSION ([value] < 40)
NAME "Fourth"
OUTLINECOLOR 0 0 0
COLOR 251 60 235
END
CLASS
EXPRESSION ([value] >= 40)
NAME "Fifth"
OUTLINECOLOR 0 0 0
COLOR 255 0 0
END
CLASS
OUTLINECOLOR 0 0 0
NAME "No data"
COLOR 200 200 200
END
PROJECTION "init=epsg:4326" END
EXTENT 90 0 120 30
END
The points to note are:
- I use an outer join because not all year/province/indicator are
available but I still need to show all the provinces, although as "no
data". This is also why there is a "default" class
- %dyear% and %indid% come from the request URL and are substituted by
MapServer on the fly, very neat feature!
- the CLASS names and expressions are dummies as they will be provided
through the URL as explained before (other very nice feature!)
The php page is attached. At this time I have made no attempt to group
statements together as functions, so it is a bit verbose... The first
issue was to have dynamic queries to the DB to present the user only
the combinations in indicator category/indicator/year that actually
exist in the DB. This explains the PHP segments that make queries and
the cookie setting/clearing. The basic functionality is there although
there is considerable room for improvements.
I hope this could be of use to somebody because, frankly, the
documentation on MapServer is sketchy (to say it politely) and I had to
browse through a lot of messages in this list (which is a godsend, but
would be less critically useful if proper documentation existed) and do
a lot of tests myself.
Cheers
Marco
-------------- next part --------------
A non-text attachment was scrubbed...
Name: asiacover.php
Type: application/text
Size: 17410 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20050210/469d83ef/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: geonetwork.map
Type: application/text
Size: 2513 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20050210/469d83ef/attachment-0001.bin>
More information about the MapServer-users
mailing list