Converting lat/long distance to miles.

Lowell Filak lfilak at MEDINACO.ORG
Wed Jan 26 16:45:12 EST 2005


The following message was sent by Camden Daily <cdaily at GMAIL.COM> on
Wed, 26 Jan 2005 15:34:45 -0600.

> Ok, I need some help with this one.  I have a map where all the layers
> are in lat/long coordinates, so I don't do any projections.
>
> I use queryByPoint and distanceToShape to find the closest item in a
> shapefile to a given point (nearest subway stop, for example).  I have
> all this working just fine, but the distance I receive from
> distanceToShape is in decimal degrees.  I'd like to convert this to
> miles.
>
> Anyone have a good solution?  The result doesn't need to be too
> precise, but the more precise the better.  The issues I see as causing
> problems are:
>
> 1) Degrees of longitude vary in length the further north you are.  My
> map only covers a limited area (northern Illinois) so I wouldn't be
> adverse to using a 'fixed' value for that conversion, but if I could
> be more exact I'd like to be.
>
> 2) The distance I have doesn't tell me anything about the direction;
> if two points are of equal distance in latlong, one to the east or
> west would actually be 'closer' than one to the north or south,
> correct (unless you're at the equator);
>
> I'm guessing I'll have to calculate the difference in latitude,
> convert it to miles, then calculate the difference in longitude,
> convert it to miles, and then use the pythagorean theorem to calculate
> the distance.  Is this sounding correct?  Or for distances under 2
> miles will this even make a noticeable difference?

Camden,

Is the projection of your map set to DD? If you temporarily changed the
projection of your map to stateplane for northern Illinois wouldn't the
result be in feet, letting proj.4 do the math.?

Lowell



More information about the mapserver-users mailing list