Class GeographyUtilities


  • public class GeographyUtilities
    extends Object
    Some utilities for geographic data
    Author:
    Erwan Bocher
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static double RADIUS_OF_EARTH_IN_METERS
      The approximate radius of earth as defined for WGS84 see .
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double computeLatitudeDistance​(double meters)
      Computes the amount of degrees of latitude for a given distance in meters.
      static double computeLongitudeDistance​(double meters, double latitude)
      Computes the amount of degrees of longitude for a given distance in meters.
      static org.locationtech.jts.geom.Envelope createEnvelope​(org.locationtech.jts.geom.Coordinate point, double dx, double dy)
      This method is used to create a JTS envelope by a given point coordinates in degrees and spatial increments in meters.
      static org.locationtech.jts.geom.Envelope createEnvelope​(org.locationtech.jts.geom.Coordinate point, double dx, double dy, int quadrant)
      This method is used to create a JTS envelope by a given point coordinates in degrees and spatial increments in meters.
      static org.locationtech.jts.geom.Envelope expandEnvelopeByMeters​(org.locationtech.jts.geom.Envelope envelope, double distance)
      This method is used to expand a JTS envelope by a given distance in degrees in all directions.
      static double getHaversineDistanceInMeters​(org.locationtech.jts.geom.Coordinate coordA, org.locationtech.jts.geom.Coordinate coordB)
      Calculate the spherical distance between two coordinates in meters using the Haversine formula.
      static int getSRID​(Connection connection, float latitude, float longitude)
      Return a SRID code from latitude and longitude coordinates
    • Field Detail

      • RADIUS_OF_EARTH_IN_METERS

        public static final double RADIUS_OF_EARTH_IN_METERS
        The approximate radius of earth as defined for WGS84 see .
        See Also:
        Constant Field Values
    • Constructor Detail

      • GeographyUtilities

        public GeographyUtilities()
    • Method Detail

      • createEnvelope

        public static org.locationtech.jts.geom.Envelope createEnvelope​(org.locationtech.jts.geom.Coordinate point,
                                                                        double dx,
                                                                        double dy)
        This method is used to create a JTS envelope by a given point coordinates in degrees and spatial increments in meters.
        Parameters:
        point - Coordinates of a point used to build an envelope.
        dx - Spatial horizontal increment expressed in meters
        dy - Spatial vertical increment expressed in meters.
        Returns:
        an envelope
      • createEnvelope

        public static org.locationtech.jts.geom.Envelope createEnvelope​(org.locationtech.jts.geom.Coordinate point,
                                                                        double dx,
                                                                        double dy,
                                                                        int quadrant)
        This method is used to create a JTS envelope by a given point coordinates in degrees and spatial increments in meters.
        Parameters:
        point - Coordinates of a point used to build an envelope in degrees.
        dx - Spatial horizontal increment expressed in meters.
        dy - Spatial vertical increment expressed in meters.
        quadrant - One of the four quadrants delimiting the plane (counter-clockwise and starting from the upper right)
        Returns:
        an envelope
      • expandEnvelopeByMeters

        public static org.locationtech.jts.geom.Envelope expandEnvelopeByMeters​(org.locationtech.jts.geom.Envelope envelope,
                                                                                double distance)
        This method is used to expand a JTS envelope by a given distance in degrees in all directions. see : https://www.mkompf.com/gps/distcalc.html
        Parameters:
        envelope - to expand
        distance - expressed in degrees
        Returns:
        a new envelope
      • computeLatitudeDistance

        public static double computeLatitudeDistance​(double meters)
        Computes the amount of degrees of latitude for a given distance in meters.
        Parameters:
        meters - distance in meters
        Returns:
        latitude degrees
      • computeLongitudeDistance

        public static double computeLongitudeDistance​(double meters,
                                                      double latitude)
        Computes the amount of degrees of longitude for a given distance in meters.
        Parameters:
        meters - distance in meters
        latitude - the latitude at which the calculation should be performed
        Returns:
        longitude degrees
      • getHaversineDistanceInMeters

        public static double getHaversineDistanceInMeters​(org.locationtech.jts.geom.Coordinate coordA,
                                                          org.locationtech.jts.geom.Coordinate coordB)
        Calculate the spherical distance between two coordinates in meters using the Haversine formula. See https://fr.wikipedia.org/wiki/Formule_de_haversine This calculation is done using the approximate earth radius
        Parameters:
        coordA -
        coordB -
        Returns:
        distance in meters
      • getSRID

        public static int getSRID​(Connection connection,
                                  float latitude,
                                  float longitude)
                           throws SQLException
        Return a SRID code from latitude and longitude coordinates
        Parameters:
        connection - to the database
        latitude -
        longitude -
        Returns:
        a SRID code
        Throws:
        SQLException