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

Worth Lutz wal3 at mindspring.com
Sun Apr 4 20:29:24 EDT 2010


Off the top of my head:

 

    $id = $shape->values['ID'];



 

  _____  

From: mapserver-users-bounces at lists.osgeo.org
[mailto:mapserver-users-bounces at lists.osgeo.org] On Behalf Of Medve Zsolt
Sent: Thursday, April 01, 2010 10:44 AM
To: mapserver-users at lists.osgeo.org
Subject: [mapserver-users] GetFeatures - get the ID value of clicked shape

 

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/20100404/b4737d87/attachment.html


More information about the mapserver-users mailing list