|
From: Koen M. <ko...@ko...> - 2006-09-03 20:30:15
|
thx paul, that worked.
I'm stupid for not trying this earlier.
thx again !!
On 03/09/06, Paul Ramsey <pr...@re...> wrote:
>
> What happens if you make x longitude and y latitude? (Just guessing...)
>
> koma wrote:
> > Hi
> >
> > I'm new to geotools and I start using it to calculate the distance
> between
> > airports.
> >
> > From my research i learned that this distance is called orthodromic
> distance
> > and there are ellipsoids that appromixate the earth surface etc;..
> >
> > My problem is that my results do not match with what I find in the
> numerous
> > online tools that serve the same purpose of calculating this distance;
> >
> > for BRU-JFK, I get 8715 km while it should result in 5901 km. I tried t=
o
> > document as complete as possible how I get to this result below.
> >
> > *** Here is the part of my code where I actually call geotools - I put
> a
> > lot of logging in there so you can see the values below.
> >
> > public class Airport {
> >
> > ................
> >
> > public Measure getOrthodromicDistance(Airport otherAirport) {
> >
> > double x1 =3D this.getPersistentLatLong
> ().getLatitudeValue().doubleValue();
> > double y1 =3D this.getPersistentLatLong
> ().getLongitudeValue().doubleValue();
> > double x2 =3D
> > otherAirport.getPersistentLatLong().getLatitudeValue().doubleValue();
> > double y2 =3D
> > otherAirport.getPersistentLatLong().getLongitudeValue().doubleValue();
> >
> > log.info("x1: " + x1);
> > log.info("y1: " + y1);
> > log.info("x2: " + x2);
> > log.info("y2: " + y2);
> >
> > double distanceInMeter =3D
> DefaultEllipsoid.WGS84.orthodromicDistance(x1,
> > y1, x2, y2);
> >
> > log.info("distance in meter: " + distanceInMeter);
> >
> > return Measure.valueOf(distanceInMeter, SI.METER);
> > }
> >
> >
> > **** Here is how I called this function in a test case :
> >
> > Measure expectedDistance =3D null;
> > Measure actualDistance =3D null;
> >
> > AirportFilter filter =3D new AirportFilter();
> > filter.setLikeIcao("EBBR");
> > Airport brussels =3D
> >
> (Airport)BusinessFactory.getSafeAirportsFacade().findAirports(filter).get=
(0);
> > filter.setLikeIcao("LGAV");
> > Airport athens =3D
> >
> (Airport)BusinessFactory.getSafeAirportsFacade().findAirports(filter).get=
(0);
> > filter.setLikeIcao("KJFK");
> > Airport jfk =3D
> >
> (Airport)BusinessFactory.getSafeAirportsFacade().findAirports(filter).get=
(0);
> > assertTrue(brussels!=3Dnull);
> > assertTrue(athens!=3Dnull);
> > assertTrue(jfk!=3Dnull);
> >
> > log.info("BRUSSELS: " + brussels.getPersistentLatLong
> ().getLatLong());
> > log.info("ATHENS:" + athens.getPersistentLatLong
> ().getLatLong());
> > log.info("JFK:" + athens.getPersistentLatLong
> ().getLatLong());
> >
> >
> > log.info("*******CALCULATING BRU-JFK");
> > expectedDistance =3D Measure.valueOf(5901, 1, SI.KILO(
> SI.METER));
> > actualDistance =3D brussels.getOrthodromicDistance(jfk);
> >
> > log.info("bru-jfk:" + actualDistance + "<> expected " +
> expectedDistance);
> >
> > log.info("*******CALCULATING JFK-ATH");
> > expectedDistance =3D Measure.valueOf(7952, 1, SI.KILO(
> SI.METER));
> > actualDistance =3D jfk.getOrthodromicDistance(athens);
> >
> > log.info("jfk-ath:" + actualDistance+ "<> expected " +
> expectedDistance);
> >
> > log.info("*******CALCULATING BRU-ATH");
> > expectedDistance =3D Measure.valueOf(2104, 1, SI.KILO(
> SI.METER));
> > actualDistance =3D brussels.getOrthodromicDistance(athens=
);
> >
> > log.info("bru-ath:" + actualDistance+ "<> expected " +
> expectedDistance);
> >
> > ***************
> > ********** Here is the log output and you can see the mismatch in the
> > results !
> >
> > 21:53:35,949 INFO AbstractTest:53 - BRUSSELS: [50.901389 =B0, 4.484444=
=B0]
> > 21:53:35,953 INFO AbstractTest:54 - ATHENS:[37.936358 =B0, 23.944467 =
=B0]
> > 21:53:35,954 INFO AbstractTest:55 - JFK:[37.936358 =B0, 23.944467 =B0]
> >
> >
> > 21:53:35,955 INFO AbstractTest:58 - *******CALCULATING BRU-JFK
> > 21:53:35,966 INFO Airport:105 - x1: 50.901389
> > 21:53:35,967 INFO Airport:106 - y1: 4.484444
> > 21:53:35,968 INFO Airport:107 - x2: 40.63975
> > 21:53:35,968 INFO Airport:108 - y2: -73.778925
> > 21:53:36,011 INFO Airport:112 - distance in meter: 8715665.085436275
> > 21:53:36,022 INFO AbstractTest:62 - bru-jfk:(8.7156650854362752E6 =B1
> 1.9E-9)
> > m<> expected (5901.0 =B1 1.0) km
> > 21:53:36,023 INFO AbstractTest:64 - *******CALCULATING JFK-ATH
> > 21:53:36,023 INFO Airport:105 - x1: 40.63975
> > 21:53:36,024 INFO Airport:106 - y1: -73.778925
> > 21:53:36,026 INFO Airport:107 - x2: 37.936358
> > 21:53:36,027 INFO Airport:108 - y2: 23.944467
> > 21:53:36,027 INFO Airport:112 - distance in meter: 1.0841626343788018E=
7
> > 21:53:36,028 INFO AbstractTest:68 - jfk-ath:(1.08416263437880192E7 =B1
> > 1.9E-9) m<> expected (7952.0 =B1 1.0) km
> > 21:53:36,028 INFO AbstractTest:70 - *******CALCULATING BRU-ATH
> > 21:53:36,029 INFO Airport:105 - x1: 50.901389
> > 21:53:36,029 INFO Airport:106 - y1: 4.484444
> > 21:53:36,030 INFO Airport:107 - x2: 37.936358
> > 21:53:36,030 INFO Airport:108 - y2: 23.944467
> > 21:53:36,031 INFO Airport:112 - distance in meter: 2563549.1161598773
> > 21:53:36,032 INFO AbstractTest:74 - bru-ath:(2.56354911615987712E6 =B1
> > 4.7E-10) m<> expected (2104.0 =B1 1.0) km
> >
> > Somebody can tell me what I'm doing wrong ???
> >
> > TIA !
> >
> > Koen
>
>
|