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 to
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 =
this.getPersistentLatLong().getLatitudeValue().doubleValue();
double y1 =
this.getPersistentLatLong().getLongitudeValue().doubleValue();
double x2 =
otherAirport.getPersistentLatLong().getLatitudeValue().doubleValue();
double y2 =
otherAirport.getPersistentLatLong().getLongitudeValue().doubleValue();
log.info("x1: " + x1);
log.info("y1: " + y1);
log.info("x2: " + x2);
log.info("y2: " + y2);
double distanceInMeter =
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 = null;
Measure actualDistance = null;
AirportFilter filter = new AirportFilter();
filter.setLikeIcao("EBBR");
Airport brussels =
(Airport)BusinessFactory.getSafeAirportsFacade().findAirports(filter).get(0);
filter.setLikeIcao("LGAV");
Airport athens =
(Airport)BusinessFactory.getSafeAirportsFacade().findAirports(filter).get(0);
filter.setLikeIcao("KJFK");
Airport jfk =
(Airport)BusinessFactory.getSafeAirportsFacade().findAirports(filter).get(0);
assertTrue(brussels!=null);
assertTrue(athens!=null);
assertTrue(jfk!=null);
log.info("BRUSSELS: " +
brussels.getPersistentLatLong().getLatLong());
log.info("ATHENS:" +
athens.getPersistentLatLong().getLatLong());
log.info("JFK:" + athens.getPersistentLatLong().getLatLong());
log.info("*******CALCULATING BRU-JFK");
expectedDistance = Measure.valueOf(5901, 1, SI.KILO(SI.METER));
actualDistance = brussels.getOrthodromicDistance(jfk);
log.info("bru-jfk:" + actualDistance + "<> expected " +
expectedDistance);
log.info("*******CALCULATING JFK-ATH");
expectedDistance = Measure.valueOf(7952, 1, SI.KILO(SI.METER));
actualDistance = jfk.getOrthodromicDistance(athens);
log.info("jfk-ath:" + actualDistance+ "<> expected " +
expectedDistance);
log.info("*******CALCULATING BRU-ATH");
expectedDistance = Measure.valueOf(2104, 1, SI.KILO(SI.METER));
actualDistance = 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 °, 4.484444 °]
21:53:35,953 INFO AbstractTest:54 - ATHENS:[37.936358 °, 23.944467 °]
21:53:35,954 INFO AbstractTest:55 - JFK:[37.936358 °, 23.944467 °]
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 ± 1.9E-9)
m<> expected (5901.0 ± 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.0841626343788018E7
21:53:36,028 INFO AbstractTest:68 - jfk-ath:(1.08416263437880192E7 ±
1.9E-9) m<> expected (7952.0 ± 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 ±
4.7E-10) m<> expected (2104.0 ± 1.0) km
Somebody can tell me what I'm doing wrong ???
TIA !
Koen
--
View this message in context:
http://www.nabble.com/Orthodromic-distance-calculation-between-airports%3A-wrong-results-tf2212018.html#a6126286
Sent from the geotools-gt2-users forum at Nabble.com.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users