/** * Convert projection coordinates to a LatLonPoint * Note: a new object is not created on each call for the return value. * * @param world convert from these projection coordinates * @param result the object to write to * @return LatLonPoint convert to these lat/lon coordinates */ @Override public LatLonPoint projToLatLon(ProjectionPoint world, LatLonPointImpl result) { double fromX = (world.getX() - falseEasting) / totalScale; // assumes cartesian coords in km double fromY = (world.getY() - falseNorthing) / totalScale; Point2D.Double dst = projectInverse(fromX, fromY, new Point2D.Double()); if (dst.x < -Math.PI) { dst.x = -Math.PI; } else if (dst.x > Math.PI) { dst.x = Math.PI; } if (projectionLongitude != 0 && !Double.isNaN(dst.x)) { dst.x = MapMath.normalizeLongitude(dst.x + projectionLongitude); } result.setLatitude(Math.toDegrees(dst.y)); result.setLongitude(Math.toDegrees(dst.x)); return result; }
/** * Convert projection coordinates to a LatLonPoint * Note: a new object is not created on each call for the return value. * * @param world convert from these projection coordinates * @param result the object to write to * @return LatLonPoint convert to these lat/lon coordinates */ @Override public LatLonPoint projToLatLon(ProjectionPoint world, LatLonPointImpl result) { double fromX = (world.getX() - falseEasting) / totalScale; // assumes cartesian coords in km double fromY = (world.getY() - falseNorthing) / totalScale; ProjectionPointImpl pp = new ProjectionPointImpl(); projectInverse(fromX, fromY, pp); if (pp.getX() < -Math.PI) { pp.setX(-Math.PI); } else if (pp.getX() > Math.PI) { pp.setX(Math.PI); } if (projectionLongitude != 0 && !Double.isNaN(pp.getX())) { pp.setX(MapMath.normalizeLongitude(pp.getX() + projectionLongitude)); } result.setLatitude( Math.toDegrees(pp.getY())); result.setLongitude( Math.toDegrees(pp.getX())); return result; }
/** * Convert projection coordinates to a LatLonPoint * Note: a new object is not created on each call for the return value. * * @param world convert from these projection coordinates * @param result the object to write to * @return LatLonPoint convert to these lat/lon coordinates */ @Override public LatLonPoint projToLatLon(ProjectionPoint world, LatLonPointImpl result) { double fromX = (world.getX() - falseEasting) / totalScale; // assumes cartesian coords in km double fromY = (world.getY() - falseNorthing) / totalScale; ProjectionPointImpl pp = new ProjectionPointImpl(); projectInverse(fromX, fromY, pp); if (pp.getX() < -Math.PI) { pp.setX(-Math.PI); } else if (pp.getX() > Math.PI) { pp.setX(Math.PI); } if (projectionLongitude != 0 && !Double.isNaN(pp.getX())) { pp.setX(MapMath.normalizeLongitude(pp.getX() + projectionLongitude)); } result.setLatitude( Math.toDegrees(pp.getY())); result.setLongitude( Math.toDegrees(pp.getX())); return result; }