1

I'm using the popular JTS Vividsolutions API for Java. I'm struggling to find if I can perform calculation of the First (direct) geodetic problem with the API. Is there a way to calculate this with this API? It seems that simple one method not exist, but maybe using some combinations of existing methods of that API.

Note - I'm not looking for solutions of implementing the First (direct) geodetic problem algorithm using Java+JTS suite.

  • 1
    Feels like a stupid workaround but at least JTS can rotate. Create a vertical line with correct length and rotate it and find where the end point of the line travels. – user30184 Nov 20 '15 at 21:21
  • @user30184 actually very elegant solution – michael Nov 20 '15 at 21:33
  • @user30184 Thanks, found the solution and put it here for others – michael Nov 21 '15 at 8:39
2

I would much rather suggest doing it manually since the math is simple. This will be much faster than using so many potentially complex methods.

public static Point createPointInDistanceAtAngle(Point anchor, 
                                      double distance, double angle) {

    double dx = distance * Math.cos(Math.toRadians(angle));
    double dy = distance * Math.sin(Math.toRadians(angle));

    double x = anchor.getX() + dx;
    double y = anchor.getY() + dy;

    GeometryFactory geometryFactory = new GeometryFactory(); // maybe pass one
    Point point = geometryFactory.createPoint(new Coordinate(x, y));

    return point;
}
1

Ok, so I found by myself the solution thanks to @user30184 comment.

The key principal is using JTS rotation via Math Transformation.

//my base point
Coordinate ancorPoint = placeCoordinate;
//create orthogonal point in distance of 0.001 arc degrees
Coordinate endingCoordinate = new Coordinate(placeCoordinate.x+0.001, placeCoordinate.y);
//rotate by 90 degrees = pi/2 = 1.57 (radians)
AffineTransform affineTransform = AffineTransform.getRotateInstance(1.57, ancorPoint.x, ancorPoint.y);
MathTransform mathTransform = new AffineTransform2D(affineTransform);
try {
    //save the result "in place" - modify endingCoordinate to save memory
    JTS.transform(endingCoordinate, endingCoordinate, mathTransform);
} catch (Exception e) {}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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