[mapserver-users] query results lost

Worth Lutz wal3 at mindspring.com
Sun Jun 12 08:43:40 EDT 2011


This is probably related to the different ways results are accessed in PHP
MapScript.  This changed between version 5.4 and 5.6 and again between 5.6
and 6.0.  See the two functions below.  The first shows the differences
between the versions.  The second function is trying to get an object with
numResults and bounds of the results in it.  This is easy in version 6.0 but
requires a loop to get the bounds in earlier versions.  This loop will show
you the differences in version 5.4 and 5.6.  Note the layer->open and close
used only in version 5.4.

 

I hope this helps.

 

 

  static function layerGetShape($layer, $result) {

    if (MAPSERVER_VERSION < 50600) {

      $shape = $layer->getFeature($result->shapeindex);

    } else if (MAPSERVER_VERSION < 60000) {

      $shape =
$layer->resultsGetShape($result->shapeindex,$result->tileindex);

    } else {

      $shape = $layer->getShape( $result );

    }

    return $shape;

  }

 

  static function layerGetResultsObj($layer, $getBounds = FALSE) {

    $debug = Debug::getInstance();

    $debug->log(__FUNCTION__." - MAPSERVER_VERSION = ".MAPSERVER_VERSION);

  

    $results->numresults = $layer->getNumResults();

    $debug->log(__FUNCTION__." - results->numresults =
".$results->numresults);

    

    if (MAPSERVER_VERSION >= 60000) {

      $results->bounds = $layer->getResultsBounds();

    } else {

      $results->bounds = NULL;

      if ($getBounds && $results->numresults > 0) {

        $debug->log(__FUNCTION__." - in get bounds if");

        $result = $layer->getResult(0);

        $debug->log(__FUNCTION__." - shapeindex=".$result->shapeindex);

    

        if (MAPSERVER_VERSION < 50600) {

          $layer->open();

          $shape = $layer->getFeature($result->shapeindex);

        } else {

          $shape =
$layer->resultsGetShape($result->shapeindex,$result->tileindex);

        }

    

        $results->bounds->minx = $shape->bounds->minx; 

        $results->bounds->maxx = $shape->bounds->maxx; 

        $results->bounds->miny = $shape->bounds->miny; 

        $results->bounds->maxy = $shape->bounds->maxy; 

    

        $debug->log(__FUNCTION__." - before loop");

        $debug->startTimer('calc_bounds');

        for ($i = 1; $i < $results->numresults; $i++) {

          $result = $layer->getResult($i);

          if (MAPSERVER_VERSION < 50600) {

            $shape = $layer->getFeature($result->shapeindex);

          } else {

            $shape = $layer->getShape( $result );

          }

          

          if ($shape->bounds->minx < $results->bounds->minx) {

            $results->bounds->minx = $shape->bounds->minx;

          } 

          if ($shape->bounds->miny < $results->bounds->miny) {

            $results->bounds->miny = $shape->bounds->miny;

          } 

          if ($shape->bounds->maxx > $results->bounds->maxx) {

            $results->bounds->maxx = $shape->bounds->maxx;

          } 

          if ($shape->bounds->maxy > $results->bounds->maxy) {

            $results->bounds->maxy = $shape->bounds->maxy;

          } 

        }

        $debug->stopTimer('calc_bounds');

        $debug->log(__FUNCTION__." - results->bounds-> ".
$results->bounds->minx.", ".$results->bounds->miny.",
".$results->bounds->maxx.", ".$results->bounds->maxy );

    

        if (MAPSERVER_VERSION < 50600) {

          $layer->close();

        }

      }

    }

    $debug->log(__FUNCTION__." - at end"." - results->numresults =
".$results->numresults);

    return $results;

  }

 

 

 

 

  _____  

From: mapserver-users-bounces at lists.osgeo.org
[mailto:mapserver-users-bounces at lists.osgeo.org] On Behalf Of Ben Thompson
Sent: Friday, June 10, 2011 11:06 AM
To: mapserver-users at lists.osgeo.org
Subject: [mapserver-users] query results lost

 

Hello...we upgraded to the latest ms4w version 3.0.1 (MapServer and
MapScript to 5.6.6 )

and some things went bad. after doing a $oLayer->queryByPoint which yields
results (layer->numresults>0), a call to $map_object->saveQuery yields a
file showing *no results*:

 

MapServer Query - Generated by msSaveQuery()
1 1 33 -1
10718763.8336106 3518854.14068547 -1 0
-1 -1 -1 -1
-1 -1 1
NULL
NULL
-1
0

so I rewrote our code to avoid using that...a php is loaded into an iframe
(frame.src=blablabla.php?xxx),  in which the query results are accesed via
$map_object->$oMapSession->oMap...all layers have ->numresults=0

 

anyone have a clue as to what went bad? the code worked fine in an older
mapserver/mapscript...

 

thanks,

Ben


 

  _____  

No virus found in this message.
Checked by AVG - www.avg.com
Version: 10.0.1382 / Virus Database: 1513/3692 - Release Date: 06/10/11

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20110612/b8bae481/attachment-0001.html


More information about the mapserver-users mailing list