Extracting nearest point data with queryByPoint

Thomas Shaw thomas at REDMILENIO.COM
Thu Oct 7 20:52:31 PDT 2004


Hello!!, I'm actually building an application with mapserver mapscript
php, what I'm trying to do is to get a point from a database (lat, lon)
and use that point to make a query of data in a layer as follows:

map file code:

#
# Start of map file
#

MAP
NAME mapa_de_mexico
STATUS ON
SIZE 575 468
SYMBOLSET
/usr/local/mapserver_4/www/trackerweb/modules/Localiza/symbols_mapinfo.sym
#EXTENT -1379278.62 1514480.13 1909424.41 3854862.92
EXTENT -117.53926633136 8.7749367751593 -86.256395549464 34.869751589975
FONTSET  "data/fonts/fonts.list" #se definen los nombres cortos de los
tipos de letra
UNITS DD
SHAPEPATH "data/"
IMAGECOLOR 107 181 255
TRANSPARENT off
IMAGETYPE PNG

#
# Start of web interface definition
#

WEB
  IMAGEPATH "/usr/local/mapserver_4/www/trackerweb/modules/Localiza/tmp/"
  IMAGEURL "http://192.168.1.3/trackerweb/modules/Localiza/tmp/"
END

LAYER

  NAME puntosMunicipios
  GROUP "mex"
  TYPE point
  STATUS on
  CONNECTIONTYPE OGR
  CONNECTION "data/mx_pts1.shp"
  MAXSCALE 280000
  LABELITEM    "FULL_NAME"
  SYMBOLSCALE 280000
  CLASS
    COLOR      248 242 135
    OUTLINECOLOR 0 0 0
    LABEL
     COLOR 0 0 0
      TYPE TRUETYPE
      FONT georgia
      ANTIALIAS TRUE
        MINSIZE 8
        MAXSIZE 9
    END
  END # fin de CLASS

 CLASS
     NAME "puntosMunicipios"
     COLOR 255 255 255
     OUTLINECOLOR 0 0 0
  END
END


php mapscript:


dl('php_mapscript.so');

$map = ms_newMapObj("/usr/local/mapserver_4/www/mexmap.map")

$cond = "select * from lat_lon where grupo='$cve_user' and id_loc='$numloc'";

$res = $db->sql_query ($cond);
$row = $db->sql_fetchrow($res2);

$qx = $row[lon];
$qy = $row[lat];
$point = ms_newpointOBj();
$point->setXY($qx, $qy);
$layer = $map->getLayerByName("puntosMunicipios");
$data = $layer->queryByPoint($point, MS_SINGLE, -1);
$result = $layer->getResult(0);
$layer->open();
$items = $layer->getitems();
$shape =$layer->getShape($result->tileindex, $result->shapeindex);
$layer->close();
$data_val = $shape->values;

foreach($data_val as $data){
echo $data;
}



and the thing I get is:  "Warning: MapServer Error in msQueryByPoint(): No
matching record(s) found. " and the $data variable, contains an array with
all the fields of the dbf-shp, but it only presents the first registry of
the dbf table, and the registry I need is the one that is nearest from the
$point (the one I fetched from lat_lon db). I heard somewhere that I need
a Template to query, but I don't really know how to do it, and also I
think that in mapscript is not necessary isn't it? I thought that it is
only for mapsever cgi.  One other thing to consider, is that the "$point",
doesn't exactly matches one coordinate point in the layer
"puntosMunicipios", that's because I used "queryByPoint" to find the
nearest point. Hope that my explanation is enogh clear. I'll appreciate a
lot if anyone can help me with this.

Greetings

Thank you
-----------
Thomas Shaw



More information about the MapServer-users mailing list