Multi-feature query

Mark Westenberger mjw at STORM.CA
Fri Jan 12 10:09:23 EST 2007


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