You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Barry Volpe <bv...@childrencare.com> on 2003/05/24 01:10:21 UTC
[OT] Calculating distance using Longitude/Latitude
Hi,
I don't know if there is anything particular to struts on this subject....
What I want to do:
I have a geo database with city,state and corresponding longitude,lattitude.
I want to allow a specific city/state location to be specified and a distance to
be selected. Then all locations (in my database) within that distance (square miles I guess)
can be displayed.
For example I provide a service from my home and service businesses
within 20 square miles from my house and the following cities
are located within that area:
city1 (lattitude = xx.xxx, longitude = xxx.xxx)
city2 (lattitude = xx.xxx, longitude = -xxx.xxx)
city.... (lattitude = xx.xxx, longitude = xxx.xxx)
I have tracked down some of the required equations which would allow one to
calculate distance. Does anything exist in Java? Am I reinventing the wheel
or do I need to code this myself?
Thanks,
Barry
Re: [OT] Calculating distance using Longitude/Latitude
Posted by Micael <ca...@harbornet.com>.
Just so I understand the problem, why would a city not want to have a
service? That makes no sense to me.
At 01:46 PM 5/27/03 -0700, you wrote:
>Micael,
>
>Thanks for your input. My problem is limited to how far one is willing
>to travel to provide a service. The way I have it setup now is
>one can specify up to five locations (cities). But if someone wants to
>provide service to more than five cities they have no way of specifiying
>this. It is a bit more cumbersome to specify individual cities. On the
>other hand specifying a distance would require immediate feedback
>to the person providing the service so they can realize what cities
>they have specified (through distance). Another problem is
>a city that is included in the distance may want to be excluded.
>A solution that comes to mind is to allow the user to enter
>the number of cities they want to provide service in. But what is
>reasonable. 5, 10,100. That would be a pain in the neck to
>enter and may utilize an unnecessary amount of the database
>(would allow random cities not located adjacent to each other).
>
>
>Barry
>
>
>----- Original Message -----
>From: "Micael" <ca...@harbornet.com>
>To: "Struts Users Mailing List" <st...@jakarta.apache.org>
>Sent: Friday, May 23, 2003 5:20 PM
>Subject: Re: [OT] Calculating distance using Longitude/Latitude
>
>
> > Part of the answer is inevitably tied to your problem. If it is one kind
> > of a problem, then distance is crucial. If it is another, then popluation
> > is critical. Ten miles to a hotel in N.Y. is not ten miles to a hotel in
> > the Mojave Desert. Know what I mean? Usually people approach these
> > problems as distance problems when the actual area in which such solutions
> > will usually be employed make them into topographical problems. I am not
> > sure if that is relevant to you. If not, sorry for bothering you. Micael
> >
> > At 05:11 PM 5/23/03 -0700, you wrote:
> > >At 16:10 -0700 5/23/03, Barry Volpe spoke thusly:
> > >
> > >>Hi,
> > >>
> > >>I don't know if there is anything particular to struts on this
>subject....
> > >>
> > >>What I want to do:
> > >>
> > >>I have a geo database with city,state and corresponding
>longitude,lattitude.
> > >>I want to allow a specific city/state location to be specified and a
> > >>distance to
> > >>be selected. Then all locations (in my database) within that distance
> > >>(square miles I guess)
> > >>can be displayed.
> > >The equations, for the simple assumptions (see below) do not require more
> > >then 10 lines of Java. You'd spend more time finding an implementation
> > >than just coding you equations.
> > >
> > >The simple assumption is to compute a box around the source location with
> > >sides equal to half the allowed distance. This will give you a min and
>max
> > >long and latitude that you could query against. Theoretically you should
> > >check against a circle around your source point, so this will include too
> > >many results in the query output. If you really need precision, you could
> > >also computed the square inscribed within the circle and if query results
> > >are inside the outer box, but outside the inner box, you could run
> > >additional filtering in Java do to the precise calculation.
> > >Off course the earth is not flat and the larger the distance, the more
> > >error is introduced. Also, the circle above, is not really a circle for
> > >the same reason. A possible modification is to compute the width of the
> > >box (longitude) based on the latitude closest to the equator. This would
> > >compensate for locations further away from the equator, but is still not
> > >100% precise.
> > >The trick, in the absence of even smarter approaches, is to do the quick
> > >math such that it includes at least all known good answers, so you can do
> > >some more filtering in code if necessary.
> > >
> > >--dolf
> > >
> > >---------------------------------------------------------------------
> > >To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > >For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > >
> >
> >
> >
> > LEGAL NOTICE
> >
> > This electronic mail transmission and any accompanying documents contain
> > information belonging to the sender which may be confidential and legally
> > privileged. This information is intended only for the use of the
> > individual or entity to whom this electronic mail transmission was sent as
> > indicated above. If you are not the intended recipient, any disclosure,
> > copying, distribution, or action taken in reliance on the contents of the
> > information contained in this transmission is strictly prohibited. If you
> > have received this transmission in error, please delete the message.
>Thank
> > you
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
> >
> >
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
LEGAL NOTICE
This electronic mail transmission and any accompanying documents contain
information belonging to the sender which may be confidential and legally
privileged. This information is intended only for the use of the
individual or entity to whom this electronic mail transmission was sent as
indicated above. If you are not the intended recipient, any disclosure,
copying, distribution, or action taken in reliance on the contents of the
information contained in this transmission is strictly prohibited. If you
have received this transmission in error, please delete the message. Thank
you
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: [OT] Calculating distance using Longitude/Latitude
Posted by Barry Volpe <bv...@childrencare.com>.
To all interested here are suggested calculations
( I was planning on using this as a baseline):
http://www.meridianworlddata.com/HTML2/distance-formula-2.asp
Thanks,
Barry
----- Original Message -----
From: "Barry Volpe" <bv...@childrencare.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Tuesday, May 27, 2003 1:46 PM
Subject: Re: [OT] Calculating distance using Longitude/Latitude
> Micael,
>
> Thanks for your input. My problem is limited to how far one is willing
> to travel to provide a service. The way I have it setup now is
> one can specify up to five locations (cities). But if someone wants to
> provide service to more than five cities they have no way of specifiying
> this. It is a bit more cumbersome to specify individual cities. On the
> other hand specifying a distance would require immediate feedback
> to the person providing the service so they can realize what cities
> they have specified (through distance). Another problem is
> a city that is included in the distance may want to be excluded.
> A solution that comes to mind is to allow the user to enter
> the number of cities they want to provide service in. But what is
> reasonable. 5, 10,100. That would be a pain in the neck to
> enter and may utilize an unnecessary amount of the database
> (would allow random cities not located adjacent to each other).
>
>
> Barry
>
>
> ----- Original Message -----
> From: "Micael" <ca...@harbornet.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Friday, May 23, 2003 5:20 PM
> Subject: Re: [OT] Calculating distance using Longitude/Latitude
>
>
> > Part of the answer is inevitably tied to your problem. If it is one
kind
> > of a problem, then distance is crucial. If it is another, then
popluation
> > is critical. Ten miles to a hotel in N.Y. is not ten miles to a hotel
in
> > the Mojave Desert. Know what I mean? Usually people approach these
> > problems as distance problems when the actual area in which such
solutions
> > will usually be employed make them into topographical problems. I am
not
> > sure if that is relevant to you. If not, sorry for bothering you.
Micael
> >
> > At 05:11 PM 5/23/03 -0700, you wrote:
> > >At 16:10 -0700 5/23/03, Barry Volpe spoke thusly:
> > >
> > >>Hi,
> > >>
> > >>I don't know if there is anything particular to struts on this
> subject....
> > >>
> > >>What I want to do:
> > >>
> > >>I have a geo database with city,state and corresponding
> longitude,lattitude.
> > >>I want to allow a specific city/state location to be specified and a
> > >>distance to
> > >>be selected. Then all locations (in my database) within that distance
> > >>(square miles I guess)
> > >>can be displayed.
> > >The equations, for the simple assumptions (see below) do not require
more
> > >then 10 lines of Java. You'd spend more time finding an implementation
> > >than just coding you equations.
> > >
> > >The simple assumption is to compute a box around the source location
with
> > >sides equal to half the allowed distance. This will give you a min and
> max
> > >long and latitude that you could query against. Theoretically you
should
> > >check against a circle around your source point, so this will include
too
> > >many results in the query output. If you really need precision, you
could
> > >also computed the square inscribed within the circle and if query
results
> > >are inside the outer box, but outside the inner box, you could run
> > >additional filtering in Java do to the precise calculation.
> > >Off course the earth is not flat and the larger the distance, the more
> > >error is introduced. Also, the circle above, is not really a circle for
> > >the same reason. A possible modification is to compute the width of the
> > >box (longitude) based on the latitude closest to the equator. This
would
> > >compensate for locations further away from the equator, but is still
not
> > >100% precise.
> > >The trick, in the absence of even smarter approaches, is to do the
quick
> > >math such that it includes at least all known good answers, so you can
do
> > >some more filtering in code if necessary.
> > >
> > >--dolf
> > >
> > >---------------------------------------------------------------------
> > >To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > >For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > >
> >
> >
> >
> > LEGAL NOTICE
> >
> > This electronic mail transmission and any accompanying documents
contain
> > information belonging to the sender which may be confidential and
legally
> > privileged. This information is intended only for the use of the
> > individual or entity to whom this electronic mail transmission was sent
as
> > indicated above. If you are not the intended recipient, any disclosure,
> > copying, distribution, or action taken in reliance on the contents of
the
> > information contained in this transmission is strictly prohibited. If
you
> > have received this transmission in error, please delete the message.
> Thank
> > you
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: [OT] Calculating distance using Longitude/Latitude
Posted by Barry Volpe <bv...@childrencare.com>.
Micael,
Thanks for your input. My problem is limited to how far one is willing
to travel to provide a service. The way I have it setup now is
one can specify up to five locations (cities). But if someone wants to
provide service to more than five cities they have no way of specifiying
this. It is a bit more cumbersome to specify individual cities. On the
other hand specifying a distance would require immediate feedback
to the person providing the service so they can realize what cities
they have specified (through distance). Another problem is
a city that is included in the distance may want to be excluded.
A solution that comes to mind is to allow the user to enter
the number of cities they want to provide service in. But what is
reasonable. 5, 10,100. That would be a pain in the neck to
enter and may utilize an unnecessary amount of the database
(would allow random cities not located adjacent to each other).
Barry
----- Original Message -----
From: "Micael" <ca...@harbornet.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Friday, May 23, 2003 5:20 PM
Subject: Re: [OT] Calculating distance using Longitude/Latitude
> Part of the answer is inevitably tied to your problem. If it is one kind
> of a problem, then distance is crucial. If it is another, then popluation
> is critical. Ten miles to a hotel in N.Y. is not ten miles to a hotel in
> the Mojave Desert. Know what I mean? Usually people approach these
> problems as distance problems when the actual area in which such solutions
> will usually be employed make them into topographical problems. I am not
> sure if that is relevant to you. If not, sorry for bothering you. Micael
>
> At 05:11 PM 5/23/03 -0700, you wrote:
> >At 16:10 -0700 5/23/03, Barry Volpe spoke thusly:
> >
> >>Hi,
> >>
> >>I don't know if there is anything particular to struts on this
subject....
> >>
> >>What I want to do:
> >>
> >>I have a geo database with city,state and corresponding
longitude,lattitude.
> >>I want to allow a specific city/state location to be specified and a
> >>distance to
> >>be selected. Then all locations (in my database) within that distance
> >>(square miles I guess)
> >>can be displayed.
> >The equations, for the simple assumptions (see below) do not require more
> >then 10 lines of Java. You'd spend more time finding an implementation
> >than just coding you equations.
> >
> >The simple assumption is to compute a box around the source location with
> >sides equal to half the allowed distance. This will give you a min and
max
> >long and latitude that you could query against. Theoretically you should
> >check against a circle around your source point, so this will include too
> >many results in the query output. If you really need precision, you could
> >also computed the square inscribed within the circle and if query results
> >are inside the outer box, but outside the inner box, you could run
> >additional filtering in Java do to the precise calculation.
> >Off course the earth is not flat and the larger the distance, the more
> >error is introduced. Also, the circle above, is not really a circle for
> >the same reason. A possible modification is to compute the width of the
> >box (longitude) based on the latitude closest to the equator. This would
> >compensate for locations further away from the equator, but is still not
> >100% precise.
> >The trick, in the absence of even smarter approaches, is to do the quick
> >math such that it includes at least all known good answers, so you can do
> >some more filtering in code if necessary.
> >
> >--dolf
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
>
>
>
> LEGAL NOTICE
>
> This electronic mail transmission and any accompanying documents contain
> information belonging to the sender which may be confidential and legally
> privileged. This information is intended only for the use of the
> individual or entity to whom this electronic mail transmission was sent as
> indicated above. If you are not the intended recipient, any disclosure,
> copying, distribution, or action taken in reliance on the contents of the
> information contained in this transmission is strictly prohibited. If you
> have received this transmission in error, please delete the message.
Thank
> you
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: [OT] Calculating distance using Longitude/Latitude
Posted by Micael <ca...@harbornet.com>.
Part of the answer is inevitably tied to your problem. If it is one kind
of a problem, then distance is crucial. If it is another, then popluation
is critical. Ten miles to a hotel in N.Y. is not ten miles to a hotel in
the Mojave Desert. Know what I mean? Usually people approach these
problems as distance problems when the actual area in which such solutions
will usually be employed make them into topographical problems. I am not
sure if that is relevant to you. If not, sorry for bothering you. Micael
At 05:11 PM 5/23/03 -0700, you wrote:
>At 16:10 -0700 5/23/03, Barry Volpe spoke thusly:
>
>>Hi,
>>
>>I don't know if there is anything particular to struts on this subject....
>>
>>What I want to do:
>>
>>I have a geo database with city,state and corresponding longitude,lattitude.
>>I want to allow a specific city/state location to be specified and a
>>distance to
>>be selected. Then all locations (in my database) within that distance
>>(square miles I guess)
>>can be displayed.
>The equations, for the simple assumptions (see below) do not require more
>then 10 lines of Java. You'd spend more time finding an implementation
>than just coding you equations.
>
>The simple assumption is to compute a box around the source location with
>sides equal to half the allowed distance. This will give you a min and max
>long and latitude that you could query against. Theoretically you should
>check against a circle around your source point, so this will include too
>many results in the query output. If you really need precision, you could
>also computed the square inscribed within the circle and if query results
>are inside the outer box, but outside the inner box, you could run
>additional filtering in Java do to the precise calculation.
>Off course the earth is not flat and the larger the distance, the more
>error is introduced. Also, the circle above, is not really a circle for
>the same reason. A possible modification is to compute the width of the
>box (longitude) based on the latitude closest to the equator. This would
>compensate for locations further away from the equator, but is still not
>100% precise.
>The trick, in the absence of even smarter approaches, is to do the quick
>math such that it includes at least all known good answers, so you can do
>some more filtering in code if necessary.
>
>--dolf
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
LEGAL NOTICE
This electronic mail transmission and any accompanying documents contain
information belonging to the sender which may be confidential and legally
privileged. This information is intended only for the use of the
individual or entity to whom this electronic mail transmission was sent as
indicated above. If you are not the intended recipient, any disclosure,
copying, distribution, or action taken in reliance on the contents of the
information contained in this transmission is strictly prohibited. If you
have received this transmission in error, please delete the message. Thank
you
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: [OT] Calculating distance using Longitude/Latitude
Posted by Dolf Starreveld <do...@starreveld.com>.
At 16:10 -0700 5/23/03, Barry Volpe spoke thusly:
>Hi,
>
>I don't know if there is anything particular to struts on this subject....
>
>What I want to do:
>
>I have a geo database with city,state and corresponding longitude,lattitude.
>I want to allow a specific city/state location to be specified and a
>distance to
>be selected. Then all locations (in my database) within that
>distance (square miles I guess)
>can be displayed.
>
The equations, for the simple assumptions (see below) do not require
more then 10 lines of Java. You'd spend more time finding an
implementation than just coding you equations.
The simple assumption is to compute a box around the source location
with sides equal to half the allowed distance. This will give you a
min and max long and latitude that you could query against.
Theoretically you should check against a circle around your source
point, so this will include too many results in the query output. If
you really need precision, you could also computed the square
inscribed within the circle and if query results are inside the outer
box, but outside the inner box, you could run additional filtering in
Java do to the precise calculation.
Off course the earth is not flat and the larger the distance, the
more error is introduced. Also, the circle above, is not really a
circle for the same reason. A possible modification is to compute the
width of the box (longitude) based on the latitude closest to the
equator. This would compensate for locations further away from the
equator, but is still not 100% precise.
The trick, in the absence of even smarter approaches, is to do the
quick math such that it includes at least all known good answers, so
you can do some more filtering in code if necessary.
--dolf
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: [OT] Calculating distance using Longitude/Latitude
Posted by Micael <ca...@harbornet.com>.
This sort of solution does not work very well. This is a oldtime
problem. I would suggest you do some studies on what has been tried. You
also may find that a little knowledge in topography will go a long way,
since you may want to stretch and contract distances as a function of
poplution, etc. Micael
At 04:10 PM 5/23/03 -0700, you wrote:
>Hi,
>
>I don't know if there is anything particular to struts on this subject....
>
>What I want to do:
>
>I have a geo database with city,state and corresponding longitude,lattitude.
>I want to allow a specific city/state location to be specified and a
>distance to
>be selected. Then all locations (in my database) within that distance
>(square miles I guess)
>can be displayed.
>
>For example I provide a service from my home and service businesses
>within 20 square miles from my house and the following cities
>are located within that area:
>
>city1 (lattitude = xx.xxx, longitude = xxx.xxx)
>city2 (lattitude = xx.xxx, longitude = -xxx.xxx)
>city.... (lattitude = xx.xxx, longitude = xxx.xxx)
>
>
>I have tracked down some of the required equations which would allow one to
>calculate distance. Does anything exist in Java? Am I reinventing the wheel
>or do I need to code this myself?
>
>Thanks,
>Barry
LEGAL NOTICE
This electronic mail transmission and any accompanying documents contain
information belonging to the sender which may be confidential and legally
privileged. This information is intended only for the use of the
individual or entity to whom this electronic mail transmission was sent as
indicated above. If you are not the intended recipient, any disclosure,
copying, distribution, or action taken in reliance on the contents of the
information contained in this transmission is strictly prohibited. If you
have received this transmission in error, please delete the message. Thank
you
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: [OT] Calculating distance using Longitude/Latitude
Posted by Micael <ca...@harbornet.com>.
What I was saying was that you are reinventing the wheel, but I suspect
most of the good solutions are kept as secret as possible. It is a
valuable problem to solve. You need to give it a lot of thought, both
mathematical and practical. One good solution is to use shifting
grids. Clearly, too, it will be lots and lots faster to compute a square
within which the circle's radius exists. The quickest computions for the
radius solution, I find, are ones that calculate the total length of the
x/y axis's. They are all the values of x-max/y-0 to the square root of x
squared/2 for x and y on the right to x-0/y, blah, blah. If you make the
center of the circle 0, then you only have to calculate for one quadrant
and you can transpose all those values. But, if you can make a topographic
map of the country you are interested in with the parameters that you are
interested in, that is best. You can even stretch the map in that case so
that circles become squares. That is one solution area, in fact.
At 04:10 PM 5/23/03 -0700, you wrote:
>Hi,
>
>I don't know if there is anything particular to struts on this subject....
>
>What I want to do:
>
>I have a geo database with city,state and corresponding longitude,lattitude.
>I want to allow a specific city/state location to be specified and a
>distance to
>be selected. Then all locations (in my database) within that distance
>(square miles I guess)
>can be displayed.
>
>For example I provide a service from my home and service businesses
>within 20 square miles from my house and the following cities
>are located within that area:
>
>city1 (lattitude = xx.xxx, longitude = xxx.xxx)
>city2 (lattitude = xx.xxx, longitude = -xxx.xxx)
>city.... (lattitude = xx.xxx, longitude = xxx.xxx)
>
>
>I have tracked down some of the required equations which would allow one to
>calculate distance. Does anything exist in Java? Am I reinventing the wheel
>or do I need to code this myself?
>
>Thanks,
>Barry
LEGAL NOTICE
This electronic mail transmission and any accompanying documents contain
information belonging to the sender which may be confidential and legally
privileged. This information is intended only for the use of the
individual or entity to whom this electronic mail transmission was sent as
indicated above. If you are not the intended recipient, any disclosure,
copying, distribution, or action taken in reliance on the contents of the
information contained in this transmission is strictly prohibited. If you
have received this transmission in error, please delete the message. Thank
you
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org