Multi-feature query

Steve Lime Steve.Lime at DNR.STATE.MN.US
Wed Jan 17 16:26:43 EST 2007


Hi Mark: Typically when I've run into something like this I stick with
the standard
templates but have them produce javascript code instead. Something
like:

in species_header.html:

<html>
  <head>
  <script language="JavaScript">
    var url = "http://mymachine/crunch_stuff.cgi?";
    var keys = new Array();

in species.html

    keys.push('[SYMBOL_KEY');

in species_footer.html

    url = url + keys.join('+');
    window.location.href = url;
 </script>
  </head>
</html>

Seems to work ok. I don't know if it's more elegent, but it might be a
bit easier to
understand? Same technique can be used to build, for example, JSON
objects...

Steve

>>> Mark Westenberger <mjw at STORM.CA> 1/12/2007 9:09:23 AM >>>
Hello all.  Brand new shiny user here and just got Mapserver running on

Fedora and have a query, er, query.

I have several shapefile layers, each of which may have multiple 
features at the identical lat/lon.  Each feature only has
an ID (or Key) as an attribute within the dbf while the remaining 
attributes are maintained in other files. Upon a query,
all the features from a unique layer need to contribute their
attributes 
to a collective computation with the result of
that being presented to the browser.  In essence, a "Venn diagram" of 
their attributes.

So I've digested the Template issue in the Layer's Class, conceptually

seeking a capability to do something like:
TEMPLATE "http://mymachine/crunch_stuff.cgi?<key=[id1]>...<key=[idn]> 
but see that the template doesn't
behave like that.  After a bit of experimentation, I invented my own an

HTML tag and have things structured as per
the following extracts, which essentially is a Mapserver wrapper to do

that cgi above.  The invented tag is only seen
momentarily by the wrapper.  Each time the wrapper has collected a 
command in SHELL_ESCAPE, it runs it, whose
purpose is to chew through the feature keys, collect attributes, crunch

them, and send HTML chatter back to the browser.
When complete, the command looks like: "./species.cgi key1 key2 key3 
key4 key5 [etc]"

What I don't yet know is whether there exists a more elegant, 
"Mapserver-ish" solution to this and seek suggestions.

Here are the extracts:

============my.map==============
<...snip>
  LAYER
    NAME Species
    TYPE POINT
    DATA species
    STATUS ON
    TOLERANCE 5 # 5 pixels
    CLASS
      <...snip...>
      TEMPLATE "templates/species.html"
    END

    HEADER "templates/species_header.html"
    FOOTER "templates/species_footer.html"

    METADATA
      <...snip...>
    END
  END
<...snip>

=====species_header.html with the invented "<?sh" tag ==========
<?sh species.cgi

============species.html===============
[SYMBOL_KEY]

============species_footer.html==========
?>

=============mapserv.cgi===========
#!/bin/sh
./mapserv | while read INPUT; do
# set a latch when we see the <?sh opening tag
  if `echo "$INPUT" | grep -q "<?sh"`; then
    BUILDING_SHELLCMD=y
  fi
# collect feature "keys" one by one since they are NL delimited by
Mapserver
  if [ "$BUILDING_SHELLCMD" = "y" ]; then
    SHELL_CMD="$SHELL_CMD $INPUT"
    if `echo "$INPUT" | grep -q "?>"`; then
# we found the closing tag
      BUILDING_SHELLCMD=n
# Now strip the command of those tags
      SHELL_ESCAPE=`echo $SHELL_CMD | sed 's/<?sh \(.*\)?>/\1/'`
# and run ./$SHELL_ESCAPE"
      ./$SHELL_ESCAPE
# and reinit
      SHELL_CMD=
    fi
  else
# Otherwise just dump output through to browser
    echo $INPUT
  fi
done



More information about the mapserver-users mailing list