Java Geometry Algorithm lonLatToString(Point2D.Double pt)

Here you can find the source of lonLatToString(Point2D.Double pt)

Description

Converts signed double longitude and latitude to string.

License

Creative Commons License

Declaration

public static String lonLatToString(Point2D.Double pt) 

Method Source Code


//package com.java2s;
//License from project: Creative Commons License 

import java.awt.geom.Point2D;

public class Main {
    public static final char DEGREE_SYMBOL = (char) 0xb0;

    /**//from w w  w  .  j a va 2 s .  c  om
     * Converts signed double longitude and latitude to string.
     * @see Util#longitudeToString(double)
     * @see Util#latitudeToString(double)
     */
    public static String lonLatToString(Point2D.Double pt) {
        return String.format("%s, %s", longitudeToString(pt.x), latitudeToString(pt.y));
    }

    /**
     * Converts signed double longitude to string east or west value.
     * @param lon longitude
     * @return string rep of longitude
     */
    public static String longitudeToString(double lon) {
        while (lon < -180) {
            lon += 360;
        }
        while (lon > 180) {
            lon -= 360;
        }
        char ew = 'E';
        if (lon < 0) {
            ew = 'W';
        }

        lon = Math.abs(lon);
        return String.format("%.4f", lon) + DEGREE_SYMBOL + ew;
    }

    /**
     * Converts signed double latitude to string north or south value.
     * @param lat latitude
     * @return string rep of latitude
     */
    public static String latitudeToString(double lat) {
        char ns = 'N';
        if (lat < 0) {
            ns = 'S';
        }

        lat = Math.abs(lat);
        return String.format("%.4f", lat) + DEGREE_SYMBOL + ns;
    }
}

Related

  1. hitsLine(final Point2D p, final Point2D fromPoint, final Point2D toPoint, final double thickness)
  2. insidePoly(Polygon pg, Point p)
  3. interceptLineAndBox(Point2D startPosition, Point2D endPosition, RectangularShape boundingBox)
  4. interpol(Point p1, Point p2, float factor)
  5. invVec(final Point2D v)
  6. makeCircle(double xCenter, double yCenter, double r, int nPoints)
  7. makeCornerTo(GeneralPath gp, Point2D cornerPoint, Point2D nextCornerPoint, float radius)
  8. makeLine(Point2D.Double center, Point2D.Double north, Point2D.Double east)
  9. makeNeighbor(Point theHex, int direction)