[mapserver-users] Hacking Mappostgis.c to allow Views as Mapserver Data Source

Sean Gillies sgillies at i3.com
Mon Mar 18 16:47:53 PST 2002


Greetings,

A while ago Dave Blasby announced that one can use sub-selects in
PostGIS layer DATA parameters like "the_geom from (select oid,the_geom 
from ftab) as foo".

I desire to be able to use Postgresql views in the DATA parameter
(so that I can have OpenGIS-compliant views of non-compliant tables)
and have hacked mappostgis.c to do so.  My changes are:

1. Querying a unique row ID called "URID" instead of the Postgres
    OID.

    Mapserver requires an OID for every feature in order to query
    attributes and one cannot have an "OID" column in a view.  So
    I edited the mappostgis.c code to query "URID" instead of OID
    and create views like:

    create view fview as select oid as urid,the_geom from ftab

    (Code in mappostgis.c presumes the geometry to be the last field
    in the record, so you have to explicitly list columns in your
    view definition in order to get the proper order.)

2. The code in mappostgis.c which parses the message from EXPLAIN to
    get the query fields returns some bogus fields named "<>" from
    a view.  So, I made a small change to throw out these bogus
    fields.

So now, I just create a view and then add a new row in the 
geometry_columns table for the view.  So far it seems to work
fine.

If anyone is interested, I can email a file containing the diff between
my mappostgis.c and the latest source.  I'd also appreciate comments on
whether I'm going against the future direction of Mapserver-PostGIS
developement.

cheers,
Sean




More information about the MapServer-users mailing list