Finding distances

Steve Lime steve.lime at DNR.STATE.MN.US
Thu Jan 13 13:27:41 EST 2005


There's probably no need to use the distance methods depending on your
exact requirements. In most cases you want to know the closest feature
(e.g. school) within some maximum distance. You can take advantage of
that maximum to speed things up a great deal.

You can use LAYER tolerance values and the normal queryByPoint methods
to do this pretty efficiently. For example, if the tolerance for a
school is 5 miles then mapserver uses that value to first do a bounding
box filter to find all features that might be within 5 miles (this is
really fast if your data is indexed) and then only computes distances to
candidate features, ultimately returning the closest.

Do the query for each layer you need and your done... ;-)

Steve

>>> Camden Daily <cdaily at GMAIL.COM> 1/13/2005 10:59:54 AM >>>
I'm working on an app in php/mapscript in which I'll need to do some
calculations of the distances between a given point (address) and
various shapefiles, such as parks, or schools.  Basically, I'll be
showing what the nearest school is, or nearest lake.

I know that mapscript has some useful functions, such as
distanceToShape().   I can check a point against every shape in a
shapefile and see which is smallest, but it seems to me that this
might take a very long time, especially if the shapefiles are really
large.

Alternately, it seems I could load the shapefile into a database and
use some 'where' clauses to my SQL statements to reduce the number of
points I need to check.  Does anyone have any examples of how to make
this run efficiently?



More information about the mapserver-users mailing list