/** * Calculate the bearing between the 2 points. See calculateBearing below. Uses default Earth * object. * * @param pt1 Point 1 * @param pt2 Point 2 * @param result Object to use if non-null * @return The bearing */ public static Bearing calculateBearing(LatLonPoint pt1, LatLonPoint pt2, Bearing result) { return calculateBearing( defaultEarth, pt1.getLatitude(), pt1.getLongitude(), pt2.getLatitude(), pt2.getLongitude(), result); }
/** * Convert a LatLonPoint to projection coordinates * * @param latLon convert from these lat, lon coordinates * @param result the object to write to * @return the given result */ public ProjectionPoint latLonToProj(LatLonPoint latLon, ProjectionPointImpl result) { double toX, toY; double fromLat = latLon.getLatitude(); double fromLon = latLon.getLongitude(); double fromLat_r = Math.toRadians(fromLat); // infinite projection if ((Math.abs(90.0 - Math.abs(fromLat))) < TOLERANCE) { toX = Double.POSITIVE_INFINITY; toY = Double.POSITIVE_INFINITY; } else { toX = A * Math.toRadians(LatLonPointImpl.range180(fromLon - this.lon0)); toY = A * SpecialMathFunction.atanh(Math.sin(fromLat_r)); // p 41 Snyder } result.setLocation(toX + falseEasting, toY + falseNorthing); return result; }
/** * set lat and lon by using UTM coordinates * * @param strZone UTM-zone, e.g. 32U * @param strNorthing Northing component * @param strEasting Easting component */ public void set(String strZone, String strNorthing, String strEasting) { LatLonPoint ll = new LatLonPoint(); utm.zone_letter = strZone.charAt(strZone.length() - 1); utm.zone_number = Convert.toInt(strZone.substring(0, strZone.length() - 1)); utm.northing = (float) Common.parseDouble(strNorthing); utm.easting = (float) Common.parseDouble(strEasting); ll = utm.toLatLonPoint(); // returns null if unvalit UTM-coordinates if (ll != null) { this.utmValid = true; this.latDec = ll.getLatitude(); this.lonDec = ll.getLongitude(); } else { this.latDec = 91; this.lonDec = 361; } }
/** * Convert a LatLonPoint to projection coordinates * * @param latLon convert from these lat, lon coordinates * @param result the object to write to * @return the given result */ public ProjectionPoint latLonToProj(LatLonPoint latLon, ProjectionPointImpl result) { double toX, toY; double fromLat = latLon.getLatitude(); double fromLon = latLon.getLongitude(); fromLat = Math.toRadians(fromLat); double lonDiff = Math.toRadians(LatLonPointImpl.lonNormal(fromLon - lon0Degrees)); double cosc = sinLat0 * Math.sin(fromLat) + cosLat0 * Math.cos(fromLat) * Math.cos(lonDiff); if (cosc >= 0) { toX = R * Math.cos(fromLat) * Math.sin(lonDiff); toY = R * (cosLat0 * Math.sin(fromLat) - sinLat0 * Math.cos(fromLat) * Math.cos(lonDiff)); } else { toX = Double.POSITIVE_INFINITY; toY = Double.POSITIVE_INFINITY; } result.setLocation(toX, toY); return result; }
void timeProjection(ProjectionImpl proj) { java.util.Random r = new java.util.Random((long) this.hashCode()); LatLonPointImpl startL = new LatLonPointImpl(); double[][] from = new double[2][NPTS]; for (int i = 0; i < NPTS; i++) { from[0][i] = (180.0 * (r.nextDouble() - .5)); // random latlon point from[1][i] = (360.0 * (r.nextDouble() - .5)); // random latlon point } int n = REPEAT * NPTS; // double[][] result = new double[2][NTRIALS]; // normal long t1 = System.currentTimeMillis(); for (int k = 0; k < REPEAT; k++) { for (int i = 0; i < NPTS; i++) { ProjectionPoint p = proj.latLonToProj(from[0][i], from[1][i]); LatLonPoint endL = proj.projToLatLon(p); if (checkit) { assert close(from[0][i], endL.getLatitude()) : "lat: " + from[0][i] + "!=" + endL.getLatitude(); assert close(from[1][i], endL.getLongitude()) : "lon: " + from[1][i] + "!=" + endL.getLongitude(); } } } long took = System.currentTimeMillis() - t1; sumNormal += took; System.out.println( n + " normal " + proj.getClassName() + " took " + took + " msecs "); // == "+ .001*took/NTRIALS+" secs/call "); // array long t2 = System.currentTimeMillis(); for (int k = 0; k < REPEAT; k++) { double[][] to = proj.latLonToProj(from); double[][] result2 = proj.projToLatLon(to); if (checkit) { for (int i = 0; i < NPTS; i++) { assert close(from[0][i], result2[0][i]) : "lat: " + from[0][i] + "!=" + result2[0][i]; assert close(from[1][i], result2[1][i]) : "lon: " + from[1][i] + "!=" + result2[1][i]; } } } took = System.currentTimeMillis() - t2; sumArray += took; System.out.println( n + " array " + proj.getClassName() + " took " + took + " msecs "); // == "+ .001*took/NTRIALS+" secs/call "); // System.out.println(NTRIALS + " array "+ proj.getClassName()+" took "+took+ " msecs == "+ // .001*took/NTRIALS/REPEAT+" secs/call "); }
/** * Create CWPoint by using a LatLonPoint * * @param CWPoint LatLonPoint */ public CWPoint(LatLonPoint llPoint) { super(llPoint.getLatitude(), llPoint.getLongitude()); this.utmValid = false; }
/** * Set CWPoint by using a LatLonPoint * * @param CWPoint LatLonPoint */ public void set(LatLonPoint llPoint) { this.latDec = llPoint.getLatitude(); this.lonDec = llPoint.getLongitude(); this.utmValid = false; }
/** * Calculate a position given an azimuth and distance from another point. Uses default Earth. * * @param pt1 Point 1 * @param az azimuth (degrees) * @param dist distance from the point (km) * @param result Object to use if non-null * @return The LatLonPoint * @see #findPoint(double,double,double,double,LatLonPointImpl) */ public static LatLonPointImpl findPoint( LatLonPoint pt1, double az, double dist, LatLonPointImpl result) { return findPoint(defaultEarth, pt1.getLatitude(), pt1.getLongitude(), az, dist, result); }