Search in sources :

Example 1 with GeodeticCalculator

use of org.geotools.referencing.GeodeticCalculator in project dhis2-core by dhis2.

the class GeoUtils method getBoxShape.

/**
     * Returns boundaries of a box shape which centre is the point defined by the 
     * given longitude and latitude. The distance between the center point and the
     * edges of the box is defined in meters by the given distance. Based on standard
     * EPSG:4326 long/lat projection. The result is an array of length 4 where
     * the values at each index are:
     * 
     * <ul>
     * <li>Index 0: Maximum latitude (north edge of box shape).</li>
     * <li>Index 1: Maxium longitude (east edge of box shape).</li>
     * <li>Index 2: Minimum latitude (south edge of box shape).</li>
     * <li>Index 3: Minumum longitude (west edge of box shape).</li>
     * </ul>
     * 
     * @param longitude the longitude.
     * @param latitude the latitude.
     * @param distance the distance in meters to each box edge.
     * @return an array of length 4.
     */
public static double[] getBoxShape(double longitude, double latitude, double distance) {
    double[] box = new double[4];
    GeodeticCalculator calc = new GeodeticCalculator();
    calc.setStartingGeographicPoint(longitude, latitude);
    calc.setDirection(0, distance);
    Point2D north = calc.getDestinationGeographicPoint();
    calc.setDirection(90, distance);
    Point2D east = calc.getDestinationGeographicPoint();
    calc.setDirection(180, distance);
    Point2D south = calc.getDestinationGeographicPoint();
    calc.setDirection(-90, distance);
    Point2D west = calc.getDestinationGeographicPoint();
    box[0] = north.getY();
    box[1] = east.getX();
    box[2] = south.getY();
    box[3] = west.getX();
    return box;
}
Also used : Point2D(java.awt.geom.Point2D) GeodeticCalculator(org.geotools.referencing.GeodeticCalculator)

Example 2 with GeodeticCalculator

use of org.geotools.referencing.GeodeticCalculator in project dhis2-core by dhis2.

the class GeoUtils method getDistanceBetweenTwoPoints.

/**
     * Computes the distance between two points.
     *
     * @param from the origin point.
     * @param to the end point.
     * @return the orthodromic distance between the given points.
     */
public static double getDistanceBetweenTwoPoints(Point2D from, Point2D to) {
    GeodeticCalculator calc = new GeodeticCalculator();
    calc.setStartingGeographicPoint(from);
    calc.setDestinationGeographicPoint(to);
    return calc.getOrthodromicDistance();
}
Also used : GeodeticCalculator(org.geotools.referencing.GeodeticCalculator)

Aggregations

GeodeticCalculator (org.geotools.referencing.GeodeticCalculator)2 Point2D (java.awt.geom.Point2D)1