[Mapserver-users] confused about QueryByPoint

Michael McGrath mmcgrath at umd.edu
Wed Aug 4 14:31:55 EDT 2004


Hi,

I'm new to Mapserver and PHP/Mapscript, and I'm currently in the process of figuring out how to perform queries. I have a simple map file with 3 layers and a small php script for zooming/panning and performing queries. Zooming and panning works fine, but when I perform queries I get strange results. If I set the query mode to MS_MULTIPLE, the function always returns every feature in the layer. If I change it to MS_SINGLE, I always get a feature that is nowhere near the feature I clicked on. Changing the UNITS attribute for the MAP results in no features being returned at all, and changing the TOLERANCEUNITS to anything besides miles also results in no features being returned. Here is my mapfile:

MAP
STATUS ON
IMAGETYPE PNG
EXTENT -79.487152 37.911423 -75.045898 39.724014
SIZE 800 600
SHAPEPATH "maps"
IMAGECOLOR 255 255 255
SYMBOLSET '/var/www/htmldocs/mapfiles/etc/symbols/symbols.sym'
#UNITS meters
WEB
IMAGEPATH "/var/www/htmldocs/mapfiles/tmp/"
IMAGEURL "/mapfiles/tmp/"
END

#PROJECTION
# "proj=utm"
# "ellps=GRS80"
# "zone=18x"
# "north"
# "no defs"
#END

LAYER
NAME "counties"
METADATA
"DESCRIPTION" "CNAME"
"RESULT_FIELDS" "COUNTY"
END
DATA "counties"
STATUS ON
TYPE POLYGON
CLASS
COLOR 168 214 138
OUTLINECOLOR 56 32 11
TEMPLATE 'dummy'
END
TOLERANCE 3
TOLERANCEUNITS miles
#PROJECTION
# "proj=utm"
# "ellps=GRS80"
# "zone=15"
# "north"
# "no defs"
#END
END

LAYER
NAME "interstate"
DATA "interstate"
STATUS ON
TYPE LINE
CLASS
COLOR 0 0 0
SIZE 2
END
TOLERANCE 10
END

LAYER
NAME "detectors"
METADATA
"DESCRIPTION" "Lat"
"RESULT_FIELDS" 'Latitude'
END
DATA "detectors"
STATUS ON
TYPE POINT
CLASS
COLOR 255 0 0
SYMBOL 'circle'
SYMBOL 'circle'
SIZE 3
TEMPLATE "dummy"
END
TOLERANCE 3
TOLERANCEUNITS miles
END

OUTPUTFORMAT
NAME png
DRIVER "GD/png"
MIMETYPE "image/png"
IMAGEMODE PC256
EXTENSION "png"
END
END


And here is the php code responsible for performing the query:

$detLayer = $map->getLayerByName("counties");
$detLayer->queryByPoint($my_point, MS_SINGLE, -1);
$count_results = $detLayer->getNumResults();
echo $count_results . '<br>';
if ($count_results > 0) {
$detLayer->open();
$selFields = explode(" ", $detLayer->getMetaData("CNAME"));

$oRes = $detLayer->getResult(0);
$oShape = $detLayer->getShape($oRes->tileindex,$oRes->shapeindex);

$aResBoundBox = array($oShape->bounds->minx, $oShape->bounds->miny,
$oShape->bounds->maxx, $oShape->bounds->maxy);

$ID = $oShape->values['COUNTY'];
echo $ID;
$oShape->free();
}
else
{
echo "nothing found<br>";
}

The version of mapserver we are using here was compiled without proj4 support, which is why all the projection sections in the mapfile are commented out. Could that be my problem?

Any light you could shed on this problem would be greatly appreciated

Thanks,
Mike McGrath
mmcgrath AT umd DOT edu
 






More information about the mapserver-users mailing list