[Mapserver-users] QuerybyPoint no result (Help) PHP/Mapscript
jose.quintal at cfe.gob.mx
jose.quintal at cfe.gob.mx
Thu Apr 24 16:34:56 PDT 2003
I have a data base in Mysql in which it contains ID, cor_x, cor_y and other
4 fields. The points in the map already visualize, but when wanting to do
query does not bring any result to me.
Here this part of the code where I select the registries of the data base
and I visualize them in the map .
mysql_select_db("mapas") or die("No selecciono la Base de Datos");
$sql="SELECT * from postes_Mer WHERE circuito = '$buscar' ";
$p=mysql_query($sql) or die("Error al Ejecutar la Consulta");
//Arma la consulta
// get a layer object representing your pointlayer
$layerObj = undef;
$layerObj = $map->getLayerByName("postes");
// get a class object representing the first class in the layer
$classObj = $layerObj->getClass(0);
// create a new point object to hold the X Y data
$pointObj = ms_newPointObj();
$i=0;
while($reg=mysql_fetch_array($p))
{
$a=$reg['id'];
$b=$reg['cor_x'];
$c=$reg['cor_y'];
//set the X Y values of the point object
$pointObj->setXY($b,$c);
$line = ms_newLineObj();
$line ->add($pointObj);
$shp = ms_newShapeObj(MS_SHAPE_POINT);
$shp->add($line);
//$shp->setBounds();
$shp->{text} = $a;
$shp->{index} = $i;
if($layerObj->addFeature($shp) == -1){
echo "addFeature failed";
}
$point_lookup[$i] = $a;
$i++;
$pointObj->draw($map, $layerObj, $image, 0, $a);
}
Here it is the part where I make the QuerybyPoint
if ( isset($HTTP_POST_VARS["mapa_x"]) && isset($HTTP_POST_VARS["mapa_y"]) )
{
$nClickGeoX = GMapPix2Geo($mapa_x, 0, $dfWidthPix,
$dfMinX, $dfMaxX, 0);
$nClickGeoY = GMapPix2Geo($$mapa_y, 0, $dfHeightPix,
$dfMinY, $dfMaxY, 1);
$ptClicked = ms_newPointObj();
$ptClicked->setXY($nClickGeoX, $nClickGeoY);
if ($info_pt == 1 )
{
$record = -1;
$layerObj = $map->getLayerByName('postes');
$layerObj = @$map->queryByPoint ($ptClicked,MS_SINGLE,-1);
if($layerObj == MS_SUCCESS)
{
$results = $layerObj->{resultcache};
$num_results = $results->{numresults};
// we only expect one result.
$rslt = $layerObj->getResult(0);
// this is an index into the point lookup table.
$record = $rslt->{shapeindex};
$point_name = $point_lookup[$record];
echo "Encontrado " . $point_name;
}
}
}
Here he is .map
MAP
NAME "MER"
STATUS ON
EXTENT 217014 2.30865e+006 242281 2.33284e+006
SIZE 800 600
SHAPEPATH "c:/Php4/mapserver/webmap/shp/"
SYMBOLSET "c:/Php4/mapserver/webmap/etc/symbols.sym"
FONTSET "c:/Php4/mapserver/webmap/etc/fonts.txt"
IMAGECOLOR 213 255 255
TRANSPARENT OFF
UNITS METERS
INTERLACE ON
IMAGETYPE PNG
IMAGEQUALITY 150
WEB
IMAGEPATH "C:/tmp/ms_tmp/"
IMAGEURL "/ms_tmp/"
END
QUERYMAP
COLOR 255 255 0
STYLE HILITE
END
LEGEND
STATUS ON
IMAGECOLOR 199 226 243
TRANSPARENT TRUE
INTERLACE TRUE
POSITION LL
KEYSIZE 18 2
KEYSPACING 5 5
LABEL
TYPE BITMAP
SIZE MEDIUM
OFFSET 0 0
BUFFER 0
MINDISTANCE -1
MINFEATURESIZE -1
COLOR 0 0 89
PARTIALS TRUE
FORCE FALSE
END
END
SCALEBAR
STATUS ON
COLOR 255 255 255
OUTLINECOLOR 0 0 0
BACKGROUNDCOLOR 0 0 0
IMAGECOLOR 255 255 255
TRANSPARENT FALSE
UNITS KILOMETERS
INTERVALS 5
SIZE 300 5
STYLE 0
POSITION UC
INTERLACE TRUE
LABEL
TYPE BITMAP
SIZE SMALL
OFFSET 0 0
BUFFER 0
MINDISTANCE -1
MINFEATURESIZE -1
COLOR 0 0 0
PARTIALS TRUE
FORCE FALSE
END
END
LAYER
NAME "MERTP"
STATUS ON
DATA "Merida"
TYPE LINE
UNITS METERS
SIZEUNITS PIXELS
TOLERANCE 3
TOLERANCEUNITS PIXELS
CLASS
NAME "Cd de Merida"
SYMBOL 0
COLOR 102 153 204
# COLOR 255 255 223
OUTLINECOLOR 51 153 204
SIZE 1
MINSIZE 1
MAXSIZE 100
END
END
LAYER
NAME "MerText"
STATUS ON
DATA "Mertext"
TYPE POINT
UNITS METERS
SIZEUNITS PIXELS
LABELITEM "NAME"
LABELMINSCALE 5
LABELMAXSCALE 30000
TOLERANCE 3
TOLERANCEUNITS PIXELS
CLASS
NAME "Nombre de Calles"
SYMBOL 0
COLOR 51 153 204
SIZE 2
MINSIZE 1
MAXSIZE 100
LABEL
TYPE BITMAP
SIZE SMALL
POSITION CC
OFFSET 0 0
BUFFER 2
MINDISTANCE -1
MINFEATURESIZE -1
COLOR 0 0 0
PARTIALS TRUE
FORCE FALSE
END
END
END
LAYER
NAME "postes"
TYPE POINT
STATUS ON
TOLERANCE 10
LABELMINSCALE 10
LABELMAXSCALE 60000
TEMPLATE "postes.html"
CLASS
SYMBOL 'circle'
COLOR 255 89 89
SIZE 10
MINSIZE 5
MAXSIZE 2
LABEL
ANTIALIAS TRUE
TYPE TRUETYPE
FONT Arialn
SIZE 8
POSITION CL
BUFFER 2
MINDISTANCE -3
MINFEATURESIZE -1
COLOR 252 152 54
PARTIALS TRUE
FORCE FALSE
END
END
END
END
Thanks
Jose Antonio Quintal Castillo
PHP/Mapscript 4.2
MapServer version 3.6.3
Windows 2000 Server IIS
More information about the MapServer-users
mailing list