Dynamic where clause in OGR/ OVF file

Frank Warmerdam fwarmerdam at GMAIL.COM
Thu Dec 30 09:31:10 PST 2004


On Thu, 30 Dec 2004 07:17:09 -0500, Shanton, James A
<James.Shanton2 at nscorp.com> wrote:
> Is it Possible to put asp or other dynamic content in an OGR file ?
>
> (Specifically the where clause of the SQL statement )
>
> In my Sample below I'd like to replace the '%myuid' in the SQL with the
> users id  -- something like <%session("myuid")%>
>
> <OGRVRTDataSource>
>     <OGRVRTLayer name="notesogrl">
>         <SrcDataSource>ODBC:dbuid/mypwd at mydsn</SrcDataSource>
>         <SrcLayer>mynotes</SrcLayer>
>        <SrcSQL>select icon_id,gis_note,latitude as y,longitude as
> x,insert_id from gis_object where insert_id like '%myuid'</SrcSQL>
>         <GeometryType>wkbPoint</GeometryType>
>         <LayerSRS>WGS84</LayerSRS>
>         <GeometryField encoding="PointFromColumns" x="x" y="y"/>
>     </OGRVRTLayer>
> </OGRVRTDataSource>

James,

If you have the OGR VRT datasource definition in it's own file,
then there is no practical way to have substitutions occur.
However, if you have it "in line" in the CONNECTION
value of the layer in your .map file you could in theory use normal
MapServer variable substitution to replace key values.  Note
that this can be tricky due to the multiple levels of escaping that
apply (the SQL style escaping in the where clause itself, the
XML escaping for the VRT fragment, and the .map file
escaping required in string constants.

I don't know exactly how .map file substitutation works unfortunately,
so you will need to look that up in the reference documents ... or
perhaps someone else will explain it.

However, my advise would be to consider moving to MapScript
before letting stuff get to complex in a static .map file approach.
With MapScript you can apply arbitrary logic to form the
OGR connection string (aka VRT data) without being restricted
to simple substiution.

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the MapServer-users mailing list