I'm really new to GIS and i'm interested in finding angle between 2 lines. Each line is represented by start location(lat/lon) and end location(lat/lon).

Could some one point to an algorithm or any sample code(in any language), I can port that in to my desired language?

I tried searching in different forums but all i found was distance between 2 points and distance between a point and line, but not one to find the angle.


1 Answer 1


GeoTools provides a GeodeticCalculator for this sort of calculation, so something like this should solve your problem:

DefaultGeographicCRS crs = DefaultGeographicCRS.WGS84;
GeodeticCalculator calc = new GeodeticCalculator(crs);
GeometryFactory gf = new GeometryFactory();
Point point1 = gf.createPoint(new Coordinate(0,0));//GenerateRandomData.createRandomPoint();
calc.setStartingGeographicPoint(point1.getX(), point1.getY());

Point point2 =gf.createPoint(new Coordinate(10,10));// GenerateRandomData.createRandomPoint();
calc.setDestinationGeographicPoint(point2.getX(), point2.getY());

double azimuth1 = calc.getAzimuth();
System.out.println("Azimuth1 "+point1+", "+point2+" is "+ azimuth1);

Point point3 = gf.createPoint(new Coordinate(10,-10));//GenerateRandomData.createRandomPoint();
calc.setDestinationGeographicPoint(point3.getX(), point3.getY());

double azimuth2 = calc.getAzimuth();
System.out.println("Azimuth1 "+point1+", "+point3+" is "+ azimuth2);

System.out.println("Angle is "+(azimuth2-azimuth1));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.