Solution -- PHP Highlight list of Parcels Passed In - Solution

Steve Lehr lehrs at ERAU.EDU
Thu Jan 27 06:00:05 PST 2005


Abe:

Thanks again for the help.  I ended up getting the highligting to work --
with your suggestions, though I thought I would be smart and change the
QUERYMAP style to selected - not so smart, after reading the STYLE options
for QUERYMAP it highlighted the found parcels just as it did not found
parcels as defined in the layer definition... so for quite awhile I did not
see that I had found the 2 shapes it has said it found (the selected sytle
option defaults to layer queried definition - and thus it just rendered the
green line as it did for the other parcels not found in the query, but as
found in the layer itself).  Anyway, changed that back to hilight as you
said and it worked fine.

I searched the emails pretty hard to find a way to render the highlighted
shapes a little better, Ken from DNR was the only post I could find.

Then I thought about it some more and derived a much simpiler solution ...
set up a new layer, create a class with an expression, then send in the
expression variable or set the expression in PHP however you choose to
operate (i.e. cgi or scripting).  i.e.

CLASSITEM ID
CLASS
  EXPRESSION /%list%/     #NOTE var set in via CGI would be list -->
....&list=1|2|3&..

or
$new_expression = "/".$list."/";
$class->setexpression($new_expression);

No querymap needed and much better control of layer formatting.
Additionally, I can continue to pass the variable $list around (containing
list of parcels) and then let the user browse my map with the list of
parcels highlighted and peek and poke at other data.  And of course add to
the list or cull from the list.

Thanks again for the help of this tremendous list!

Steven Lehr
Assistant Professor
Freshmen Program
College of Engineering
Embry-Riddle Aeronautical University (LB159)
600 S. Clyde Morris Blvd.
Daytona Beach, FL 32114-3900
386-226-7740
  -----Original Message-----
  From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU]On
Behalf Of Abe Gillespie
  Sent: Sunday, January 23, 2005 2:39 AM
  To: MAPSERVER-USERS at LISTS.UMN.EDU
  Subject: Re: [UMN_MAPSERVER-USERS] PHP Highlight list of Parcels Passed In


  Um ... yeah, it's late and I'm tired. Please replace "ampersand" with "at
symbol" at the appropriate place. :)

  -Abe

  On Jan 23, 2005, at 1:44 AM, Abe Gillespie wrote:


    Ok, since this list has been so helpful and generous to me in the past,
here is an exhaustive example. I hope this will finally get you going.
Disclaimer: I'm doing this all from memory and w/o testing so there may be a
few errors.

    Setup a map file like this:

    MAP
    NAME "Parcel Query"
    STATUS on
    EXTENT xmin ymin xmax ymax
    SIZE 300 300
    SHAPEPATH "/data_path"
    IMAGETYPE png
    IMAGECOLOR 255 255 255


    QUERYMAP
    STYLE hilite
    COLOR 255 0 0
    END


    LAYER
    NAME "Parcels"
    DATA "parcels"
    CLASS
    OUTLINECOLOR 0 255 0
    END
    TEMPLATE "x"
    END
    END

    Setup a web page like this:

    <html>
    <head>
    <?
    $parcel_ids = "1|2|3|4|5";

    if (PHP_OS == "WINNT" || PHP_OS == "WIN32")
    dl("php_mapscript.dll");
    else
    dl("php_mapscript.so");

    $map = ms_newMapObj("parcels.map");
    $layer = $map->getLayerByName("parcels");

    // Query.
    $layer->queryByAttributes("", "/".$parcel_ids."/", MS_MULTIPLE);
    // If you want to avoid errors when no matches are found use the
ampersand
    // in the above statement like this: @$layer->queryByAttributes();

    // Render an image and get its URL.
    $img = $map->drawQuery();
    $url = $img->saveWebImage(MS_PNG, 1, 1, 0);
    $img->free();
    ?>
    </head>
    <body>
    <img src="<? echo $url; ?>" />
    <?
    if ($layer->getNumResults() > 0)
    echo $layer->getNumResults()." parcels found.";
    else
    echo "No parcels found.";
    ?>
    </body>
    </html>

    Now that I look at it, the last thing you may have been missing was the
mapObj::queryMap() method. Anyhow, I hope this helps.

    -Abe

    On Jan 22, 2005, at 10:07 PM, Steve Lehr wrote:


      Abe:

      I appreciate the help, still not getting it though. I'm wondering if I
need
      to draw out the map after rendering? I've sceen other posts but no
real
      solutions...

      I'll start from scratch rather then trying to reuse something I have.
If
      anyone else has a more complete example I'd really appreciate seeing
it.

      Thanks

      Steven Lehr
      Assistant Professor
      Freshmen Program
      College of Engineering
      Embry-Riddle Aeronautical University (LB159)
      600 S. Clyde Morris Blvd.
      Daytona Beach, FL 32114-3900
      386-226-7740

      -----Original Message-----
      From: UMN MapServer Users List
[mailto:MAPSERVER-USERS at LISTS.UMN.EDU]On
      Behalf Of Abe Gillespie
      Sent: Saturday, January 22, 2005 8:22 PM
      To: MAPSERVER-USERS at LISTS.UMN.EDU
      Subject: Re: [UMN_MAPSERVER-USERS] PHP Highlight list of Parcels
Passed
      In


      Something else I noticed. You shouldn't even have to setup a separate
      layer to show queried parcels (though there are ways to do this). I
      suggest starting out with one layer that renders queried and
      non-queried parcels at the same time. Once you get the hang of that
      then you can do two different layers (if you still even want to). Make
      the layer like this:

      LAYER
      NAME "parcels"
      DATA "parcels"
      STATUS on
      TYPE polygon
      CLASS
      OUTLINECOLOR 0 255 0
      END
      TEMPLATE "x" # Must be present to query on (though "x" means
      absolutely nothing).
      END

      The above layer will render all your parcels green outline with hollow
      fill. Then when you use the PHP code to query it will render your
      queried parcels red. This assumes you have QUERYMAP setup correctly.

      -Abe

      On Jan 22, 2005, at 7:12 PM, Steve Lehr wrote:


        Abe I've never used the QUERY MAP before, I tried putting it in the
        layer
        and it did not like that?

        My initial layer looks like:

        I changed my code to pass Pipe delimited.

        But I'm not quite certian I'm still getting what I need to do to my
        .map.

        Thanks for the help..below is the layer repeated my EXPRESSION is
        trashed I
        realize.


          LAYER
          NAME "selected_parcels"
          DATA parcels
          STATUS DEFAULT
          TYPE POLYGON
          CLASSITEM QPID
          CLASS
          EXPRESSION "/%parcels%/"
          COLOR 255 0 0
          END
          END



        Steven Lehr
        Assistant Professor
        Freshmen Program
        College of Engineering
        Embry-Riddle Aeronautical University (LB159)
        600 S. Clyde Morris Blvd.
        Daytona Beach, FL 32114-3900
        386-226-7740

        -----Original Message-----
        From: UMN MapServer Users List
[mailto:MAPSERVER-USERS at LISTS.UMN.EDU]On
        Behalf Of Abe Gillespie
        Sent: Saturday, January 22, 2005 7:05 PM
        To: MAPSERVER-USERS at LISTS.UMN.EDU
        Subject: Re: [UMN_MAPSERVER-USERS] PHP Highlight list of Parcels
Passed
        In


        For the red you need to setup the QUERYMAP. For the PHP it will be
        something like this:

        $target =
use_appropriate_string_func_to_conver_semi_to_pipe($parcels);
        // $target should look like "1|2|3|4" ... where the numbers are the
        IDs.
        $layer = $map->getLayerByName("parcels");
        $layer->queryByAttributes("parcel_id_field", "/".$target."/",
        MS_MULTIPLE);

        Also, don't forget to add the TEMPLATE "x" tag in your LAYER
        definition.

        I'm not a RegEx expert, so someone please put me in check if I'm
        leading Steven astray.

        -Abe

        On Jan 22, 2005, at 6:37 PM, Steve Lehr wrote:


          I'm trying to write some PHP that I can send extents and list of
          parcels to
          get it to highlight the parcels.

          I'd like to highlight all the found parcels in RED.

          My php gets a variable by post called parcels and contains at this
          time a
          semi colon delimited list of ids in the attribute column QPID of
the
          parcels.dbf.

          LAYER
          NAME "selected_parcels"
          DATA parcels
          STATUS DEFAULT
          TYPE POLYGON
          CLASSITEM QPID
          CLASS
          EXPRESSION "/%parcels%/"
          COLOR 255 0 0
          END
          END


          I've got my extents. I've got the list of parcels. Now I want to
          highlight
          the list of parcels with something like the below. But I have to
do
          something in php to take that ; delimited list and the turn on all
the
          matching attributes. (I belive its a QUERYMAP with
MULTIPLE_SELECT)
          but I'm
          having trouble getting my brain around what I need to code - might
          someone
          have a sample.

          Thanks

          Steven Lehr
          Assistant Professor
          Freshmen Program
          College of Engineering
          Embry-Riddle Aeronautical University (LB159)
          600 S. Clyde Morris Blvd.
          Daytona Beach, FL 32114-3900
          386-226-7740





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20050127/aefd74d4/attachment.htm>


More information about the MapServer-users mailing list