Searching for closest object in mapserver

Abe Gillespie abe.gillespie at GMAIL.COM
Mon Jul 3 10:15:20 EDT 2006


I'm not sure if you're using CGI (in which case I'm not sure) or not
... but if you are from the docs for layerObj:

   int queryByPoint(pointObj point, int mode, double buffer)
        Query layer at point location specified in georeferenced map
        coordinates (i.e. not pixels).
        The query is performed on all the shapes that are part of a CLASS
        that contains a TEMPLATE value or that match any class in a
        layer that contains a LAYER TEMPLATE value.
        Mode is MS_SINGLE or MS_MULTIPLE depending on number of results
        you want.
        Passing buffer <=0 defaults to tolerances set in the map file
        (in pixels) but you can use a constant buffer (specified in
        ground units) instead.
        Returns MS_SUCCESS if shapes were found or MS_FAILURE if nothing
        was found or if some other error happened (note that the error
        message in case nothing was found can be avoided in PHP using
        the '@' control operator).

The docs are somewhat confusing here but if you use MS_SINGLE for
"mode" then you'll get exactly what you're asking for.  Like this:

$layer->queryByPoint($myPoint, MS_SINGLE, $myBufferRadius);

Hope this helps!
-Abe

On 7/3/06, Jelmer Baas <baas at speerit.nl> wrote:
> Hi all,
>
> Is there any way to let mapserver determine what object is closest to a
> point I specify?
>
> I basicly have a set of coordinates and what to know which (part of an)
> object is closest to that point, meaning I also need to test lines.
>
> In my desktop app this is handled by Oracle spatial, but I don't have
> that here and don't want to use it as well.
>
> Any suggestions would be more than welcome.
>
>
>
> --
> With kind Regards
> Jelmer Baas
>



More information about the mapserver-users mailing list