Aggregate query

Stephen Woodbridge woodbri at SWOODBRIDGE.COM
Thu Jan 27 10:12:18 EST 2005


Benjamin Lloyd-Hughes wrote:
> Hi
>
> I'm using the cgi mapserver in NQUERY mode to extract values within a user
> defined extent from a point shape file.  The query works fine in so much
> that it returns the desired data and dumps this into the specifed template.
> So far so good... But what I really want to obtain is the average of these
> values.  I've been scratching my head and thought I might be able to do
> something using the EVAL() javascript function but I've not had any joy.  I
> would be very grateful I someone could point me in the direction of a
> solution.

Since you are use a HTML template, I think you are on the right track to
do this in Javascript. I would not use an eval though, I would create
and array initializer and just populate the values directly into the
array. So do something like the following (I will leave the exact syntax
up to you to figure out):

I think you need to break this into three separate files, ie; header,
template and footer so if the file names are header.html, template.heml
and footer.html, you would break up the code like this:

========header.html==============
...
var num_rows = [nr];
var data = new Array(
========template.html============
[DBASE column_name],
========footer.html==============
0);  // probably need the trailing "0" beacue of the comma above
...

// now loop through your array using num_rows to compute whatever

==================================

I'm a little rusty with my javascript and use of query templates, but
this should give you the idea. I am assuming that the mapserver
templating will repeat the [DBASE column_name], line once for every row.
if this is not right maybe some else will post the correct syntax.

-Steve W.



More information about the mapserver-users mailing list