-
Notifications
You must be signed in to change notification settings - Fork 171
Closed
Labels
Description
Hi,
I am currently testing spatial4j and struggle with correctly calculating distances. For example, I tried to calculate the distance between Berlin and Hamburg with this:
SpatialContext ctx = SpatialContext.GEO;
Point berlin = ctx.getShapeFactory().pointXY(52.5200, 13.4050);
Point hamburg = ctx.getShapeFactory().pointXY(53.511, 9.9937);
logger.info(ctx.getDistCalc().distance(berlin, hamburg) * DEG_TO_KM);Unfortunately, this results in ~394km when the real value is 253.4km.
As I could not find out what I was doing wrong, I looked into your test cases to see whether I can reproduce the results of the "testSomeDistances" test. So I tried this code snippet:
Point ctr = ctx.getShapeFactory().pointXY(0, 100);
logger.info(ctx.getDistCalc().distance(ctr, GEO.getShapeFactory().pointXY(10, 0)));Unfortunately, this throws an InvalidShapeException (Bad Y value 100.0 is not in boundary Rect(minX=-180.0,maxX=180.0,minY=-90.0,maxY=90.0)), so I wonder: why is the test working?
Reactions are currently unavailable