[Mapserver-users] A QUERY only mapfile, PHP/Mapscript, get not results

woodbri at swoodbridge.com woodbri at swoodbridge.com
Sat Mar 8 16:14:03 EST 2003


Dylan,

Thank you for taking a look, but no cigar :)

On 8 Mar 2003 at 12:23, Dylan Keon wrote:

> Not sure if this is it, but try setting the last parameter in 
> queryByPoint() to -1 instead of 1.0.  If you want to use the TOLERANCE
> setting in the layer definition, the last parameter in queryByPoint()
> should be <= 0.  By setting it to 1.0, you're saying you want to find
> features within 1.0 ground units of where you clicked.  That may not
> be enough tolerance to find features near your point (?).

I tried that originally, the changed it to 1.0 which for another 
test. In this case the world_countries_shp is a polygon layer and I 
checked it out in ArcExplorer and the point is inside the polygon. So 
that should not be a problem.

I changed the map file so the layer has:
    TOLERANCE 1000000
    TOLERANCEUNITS FEET
and is didn't make a difference.
 
> Also, why do you have your printf statement printing both 
> $layer->tolerance and $layer-toleranceunits to the TOLERANCE line?  I
> thought the TOLERANCE line just accepted the tolerance level, and to
> set toleranceunits you need a separate TOLERANCEUNITS line.

The printf statements were just there to verify the contents of the 
map and layer objects to make sure I was getting reasonable results.

> --Dylan
> 
> 
> woodbri at swoodbridge.com wrote:
> > Hi all,
> > 
> > My brain must have gone on vacation or something, because I have
> > what I thought should be a trivial example to put together and I can
> > not seem to get it to work!
> > 
> > Built a simple php script to do a query of a query only mapfile and
> > print the results. I have included below the results, query.map,
> > t2.php
> > 
> > So, does anyone have any ideas on what stupid thing I have 
> > overlooked. Oh, the world_countries_shp file is good and in units
> > DD. I have tried this with 12 different layers all with the same
> > results. I just stripped that down to this simple example. And I
> > have tried it on php-4.3.1 and MS-3.7_dev with the same results.
> > 
> > -Steve W.
> > 
> > ------------------------------ results
> > 
> > query point = (-71.3940, 42.6140)
> > 
> > LAYER country, 0
> >   STATUS 1
> >   TYPE 5
> >   SHAPEPATH /data/mdata/
> >   TILEINDEX 
> >   DATA world/world_countries_shp
> >   TEMPLATE dummy
> >   TOLERANCE 3.000 6
> > 
> > Warning:  MapServer Error in msQueryByPoint(): No matching record(s)
> > found.
> >  in /home/httpd/html/maptools/rgeo/t2.php on line 29
> > 
> > 
> > ret=1
> > 
> > ---------------------------------- query.map
> > 
> > MAP
> >   NAME "EXAMPLE"
> >   STATUS ON
> >   EXTENT -180.0 -14.8 -51.75 113.4
> >   SHAPEPATH "/data/mdata/"
> >   UNITS DD
> > 
> >   LAYER   # this is a polygon layer
> >     NAME "country"
> >     TYPE QUERY
> >     STATUS ON
> >     DATA "world/world_countries_shp"
> >     TEMPLATE "dummy"
> >     METADATA
> >       "DESCRIPTION"    "World Countries"
> >       "RESULT_FIELDS"  "NAME CAPITAL CONTINENT"
> >     END
> >   END
> > 
> > END
> > 
> > 
> > ---------------------------------- t2.php
> > 
> > <?php
> > 
> > dl("php4.2.2_mapscript-20020904.so"); # mapserver 3.6.2
> > 
> > define(MAPFILE, '/data/mdata/query.map');
> > 
> > $point = ms_newPointObj();
> > $point->setXY(-71.394, 42.614);
> > 
> > print "<pre>\n";
> > printf("query point = (%.4f, %.4f)\n\n", $point->x, $point->y);
> > 
> > $map = ms_newMapObj(MAPFILE) or
> >     die("Can't create mapObj using " . MAPFILE);
> > $map->preparequery();
> > $shapepath = $map->shapepath;
> > 
> > for ($i=0; $i<$map->numlayers; $i++) {
> > 
> >     $layer = $map->getLayer($i);
> >     $layer->set('status', MS_ON);
> >     printf("LAYER %s, %d\n", $layer->name, $layer->index);
> >     printf("  STATUS %d\n  TYPE %d\n", $layer->status,
> >     $layer->type); printf("  SHAPEPATH %s\n", $shapepath); printf(" 
> >     TILEINDEX %s\n", $layer->tileindex); printf("  DATA %s\n",
> >     $layer->data); printf("  TEMPLATE %s\n", $layer->template);
> >     printf("  TOLERANCE %.3f %d\n", $layer->tolerance, $layer-
> > 
> >>toleranceunits);
> > 
> >     $ret = $layer->queryByPoint($point, MS_MULTIPLE, 1.0);
> >     print "ret=$ret\n";
> >     if ($ret == MS_SUCCESS) {
> >         for ($j=0; $j<$layer->getNumResults(); $j++) {
> >             $result = $layer->getResult($j);
> >             printf("lay=%d, res=%d, si=%d, ti=%d, ci=%d\n",
> >                 $i, $j, $result->shapeindex, $result->tileindex,
> >                 $result->classindex);
> >         }
> >     }
> > 
> > }
> > 
> > phpinfo();
> > ?>
> > 
> > _______________________________________________
> > Mapserver-users mailing list
> > Mapserver-users at lists.gis.umn.edu
> > http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> 
> 





More information about the mapserver-users mailing list