[mapserver-users] GetFeatures - get the ID value of clicked shape

Medve Zsolt medvezs84 at gmail.com
Thu Apr 1 10:43:42 EDT 2010


Hy all

Can someone help me with this?

$layer = $map->getLayerByName('sde1','sde2','sde3','sde4');

// xy pix -> geo pt

$xPixel = $_REQUEST['x'];
$yPixel = $_REQUEST['y'];

$xGeo = $_SESSION['GEOEXT']['minx'] + (($xPixel/$_SESSION['mapwidth']) * 
($_SESSION['GEOEXT']['minx']-$_SESSION['GEOEXT']['maxx']));
$yGeo = $_SESSION['GEOEXT']['maxy'] - (($yPixel/$_SESSION['mapheight']) 
* ($_SESSION['GEOEXT']['maxy']-$_SESSION['GEOEXT']['miny']));

$pt = ms_newPointObj();
$pt->setXY($xGeo, $yGeo);

// proj
$mapProjStr = $map->getProjection();
$layerProjStr = $layer->getProjection();
if ($mapProjStr && $layerProjStr && $mapProjStr != $layerProjStr) {
     $mapProjObj = ms_newprojectionobj($mapProjStr);
     $layerProjObj = ms_newprojectionobj($layerProjStr);
     $pt->project($mapProjObj, $layerProjObj);
}

// set map extent and size:
$map->setExtent($_SESSION['GEOEXT']['minx'], 
$_SESSION['GEOEXT']['miny'], $_SESSION['GEOEXT']['maxx'], 
$_SESSION['GEOEXT']['maxy']);
$map->setSize($_SESSION['mapwidth'], $_SESSION['mapheight']);

$map->preparequery();

// Use '@' to avoid warning if query found nothing
@$layer->queryByPoint($pt, MS_SINGLE, -1);
$pt->free();

if ($layer->getNumResults() == 1) {
     $res = $layer->getResult(0);
     $layer->open();
     $shape = $layer->getFeature($res->shapeindex, $res->tileindex);
*    $id = $shape->ID;*

     $layer->close();
}

This code gets the x and y coordinates of the clicking ($xPixel = 
$_REQUEST['x']) I have transformed it to Geo coords, and so on, and in 
the end i want to search for my clicked shape's ID

Am i right that the $id variable is contaning the ID value of the 
clicked shape? i have bolded the line i talking about..  (The shape file 
have an attribute table and mine have a ID column)

Please if someone can help , do it:P

thanks,
Zsolt



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20100401/7c81469c/attachment.html


More information about the mapserver-users mailing list