Dynamic where clause in OGR/ OVF file

Blaine Hackett blaine_hack1 at YAHOO.COM
Thu Dec 30 13:10:15 EST 2004


James

You do have to put the OGR Connection in the .map
file. You can't dynamically change it if you use an
.ovf file.

Here is how I do it.

LAYER
    NAME "layername"
    TYPE annotation
CONNECTIONTYPE OGR
CONNECTION "<OGRVRTDataSource><OGRVRTLayer
name=whatevernameyouwant>
<SrcDataSource>ODBC:user/pass at nameofODBCyoucreated</SrcDataSource>
<SrcSQL>SELECT * FROM subset WHERE tim_time BETWEEN
(#%time1%#) AND (#%time2%#) </SrcSQL>
        <GeometryType>wkbPoint</GeometryType>
        <LayerSRS>WGS84</LayerSRS>
        <GeometryField encoding=PointFromColumns x=LONG
y=LAT/>
    </OGRVRTLayer>
</OGRVRTDataSource>"
(REST OF LAYER SYNTAX DELETED)

Then I send default values from the initialize page
for the variables or it will cack on you.

I have an input form on the MapServer webpage which
sends the typed in variables to the OGR connection,
sending back the data that meets the criteria.

I had some problems with syntaxthe variables when
trying to query a date or time field because depending
on the database you are using, they might use
different syntax.

Hope this helps!
Blaine

--- Frank Warmerdam <fwarmerdam at GMAIL.COM> wrote:

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




__________________________________
Do you Yahoo!?
The all-new My Yahoo! - What will yours do?
http://my.yahoo.com



More information about the mapserver-users mailing list