WMS/WFS using PHP MapScript

Eric Bridger eric at GOMOOS.ORG
Tue Dec 7 09:52:44 EST 2004


On Mon, 2004-12-06 at 19:28, Hester Jane Viola wrote:
> Hi,
>
> We have developed an internal web mapping tool within the Australian Bureau
> of Meteorology using standard CGI MapServer to view weather data.
> Our newest undertaking though is using PHP Mapscript to provide climate data
> (stored in PostgreSQL/PostGIS) to a Water Portal via a WFS, based on a
> dynamic request sent by that portal.
> The request sent by the portal, is used to generate a layer in a PHP
> mapscript file, by adding the data via an SQL query, (there are no layers
> defined in the map file in use) ie.
>
> section of the php file:
>   ...
> $rain_layer->set("connectiontype",MS_POSTGIS);
> $rain_layer->set("connection","$rain_connection");
> $rain_query="the_geom from (SELECT g_stations.the_geom as the_geom,
>                        onedrain.prcp as prcp,
>                              g_stations.name as name,
>                              g_stations.oid as oid
>                        FROM g_stations, onedrain
>                            $date_part
>                              $loc_part
>                            AND onedrain.stn_num = g_stations.stn_num)
>                            as foo USING UNIQUE oid USING SRID=-1";
>
> $rain_layer->set("data","$rain_query");
>   ...
> where $date_part and $loc_part include the input arguments sent in the
> portal request.
>
> Now that I have explained the set up, I would like to know how to implement
> a WFS to this dynamically created rain_layer. I have experimented with using
> $rain_layer->executeWFSGetfeature() but this only returns an empty string.
> I am also interested in how a WMS is enabled using PHP mapscript, if the
> layers are not defined in the .map file.
>
> I hope that someone can provide some information.

My guess is that executeWFSGetfeature() fails because your layer is not
a WFS layer but a POSTGIS layer. I think it would quite difficult to
duplicate Mapserver's WFS handling utilizing PHP and PHP Mapscript.

I would suggest adding you POSTGIS layer to your map file which would
make it very easy to serve as either a WMS or WFS layer.

The dynamic part of your SQL query could go into a FILTER section. E.g.

FILTER "date_field = %date_part% and location_field = %loc_part and
onedrain.stn_num = g_stations.stn_num"

The WFS requests then just need to add: &date_part=XXXXX&loc_part=NNNNN

See the section on map file variable substitution in
http://mapserver.gis.umn.edu/doc42/mapfile-reference.html

Eric



More information about the mapserver-users mailing list