Class GeodeticUtility


  • public class GeodeticUtility
    extends java.lang.Object
    A collection of geodetic routines used within OpenSextant. This is a light wrapper around the most common routines - a full API exists in other APIs such as GISCore, Geodesy, or Spatial4J
    Author:
    ubaldino
    • Constructor Summary

      Constructors 
      Constructor Description
      GeodeticUtility()  
    • Method Summary

      Modifier and Type Method Description
      static double distanceDegrees​(double lat1, double lon1, double lat2, double lon2)
      This returns distance in degrees, e.g., this is a Cartesian distance.
      static double distanceDegrees​(GeoBase p1, GeoBase p2)
      This returns distance in degrees, e.g., this is a Cartesian distance.
      static long distanceMeters​(LatLon p1, LatLon p2)
      Haversine distance using LL1 to LL2;
      static java.lang.String formatLatLon​(LatLon yx)
      Create a string representation of a decimal lat/lon.
      static java.lang.String geohash​(double lat, double lon)  
      static java.lang.String geohash​(LatLon yx)  
      static int getFeaturePrecision​(java.lang.String feat_type, java.lang.String feat_code)
      For a given feature type and code, determine what sort of resolution or precision should be considered for that place, approximately.
      static int getGeohashPrecision​(java.lang.String feat_type, java.lang.String feat_code)
      For a given Geonames feature class/designation provide a guess about how long geohash should be.
      static boolean isCoord​(double lat, double lon)  
      static boolean isCoord​(Geocoding xy)  
      static boolean isCoord​(LatLon p)  
      static boolean isValidNonZeroCoordinate​(double lat, double lon)
      A common check required by practical applications -- 0,0 is not interesting, so this is a simple java-based check.
      static boolean isZeroCoord​(double lat, double lon)
      Just tests if location is not 0,0 ...
      static LatLon parseLatLon​(java.lang.Object lat, java.lang.Object lon)
      Parse coordinate from object
      static LatLon parseLatLon​(java.lang.String lat_lon)
      The most simplistic parsing and validation of "lat lon" or "lat, lon" any amount of whitespace is allowed, provided the lat lon order is there.
      static boolean validateCoordinate​(double lat, double lon)
      TODO: consider using geodesy, however that API has no obvious simple validator.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • FEATURE_PRECISION

        public static final java.util.Map<java.lang.String,​java.lang.Integer> FEATURE_PRECISION
        Precision -- this is a first draft attempt at assigning some error bars to geocoding results. TODO: move this to a configuration file feat/code: prec # precision is meters of error for a given gazetteer entry with feat/code) A/ADM1: 50000 # ADM1 is generally +/- 50km, world wide P/PPL: 1000 # city is generally +/- 1km within center point P/PPLC: 10000 # major capital city is 10km of error, etc.
      • FEATURE_GEOHASH_PRECISION

        public static final java.util.Map<java.lang.String,​java.lang.Integer> FEATURE_GEOHASH_PRECISION
      • DEFAULT_GEOHASH_PRECISION

        public static final int DEFAULT_GEOHASH_PRECISION
        See Also:
        Constant Field Values
    • Constructor Detail

      • GeodeticUtility

        public GeodeticUtility()
    • Method Detail

      • validateCoordinate

        public static final boolean validateCoordinate​(double lat,
                                                       double lon)
        TODO: consider using geodesy, however that API has no obvious simple validator.
        Parameters:
        lat - latitude
        lon - longitude
        Returns:
        if lat/lon is valid
      • isValidNonZeroCoordinate

        public static final boolean isValidNonZeroCoordinate​(double lat,
                                                             double lon)
        A common check required by practical applications -- 0,0 is not interesting, so this is a simple java-based check. double (and all number) values by default have a value = 0. This appears to be true for class attributes, but not for locals. Hence the NaN check in validateCoordinate.
        Parameters:
        lat - in degrees
        lon - in degress
        Returns:
        true if coordinate is non-zero (0.000, 0.000) AND is valid abs(lon) < 180.0, etc.
      • isCoord

        public static boolean isCoord​(Geocoding xy)
        Parameters:
        xy - a geocoding
        Returns:
        true if geocoding has a non-zero coordinate
      • isZeroCoord

        public static boolean isZeroCoord​(double lat,
                                          double lon)
        Just tests if location is not 0,0 ... if provided as floating point objects Java has rounding error off in 0.0000001 place. Close enough to 0,0 counts as zero-coordinate.
        Parameters:
        lat - latitude
        lon - longitude
        Returns:
        true if coordinate is set and is other than (0,0)
      • isCoord

        public static final boolean isCoord​(double lat,
                                            double lon)
      • isCoord

        public static final boolean isCoord​(LatLon p)
      • distanceDegrees

        public static final double distanceDegrees​(GeoBase p1,
                                                   GeoBase p2)
        This returns distance in degrees, e.g., this is a Cartesian distance. Only to be used for fast comparison of two locations relatively close together, e.g., within the same 1 or 2 degrees of lat or lon. Beyond that there can be a lot of distortion in the physical distance.
        Parameters:
        p1 - point
        p2 - point
        Returns:
        distance between p1 and p2 in degrees.
      • distanceMeters

        public static final long distanceMeters​(LatLon p1,
                                                LatLon p2)
        Haversine distance using LL1 to LL2;
        Parameters:
        p1 - geodesy API LatLon
        p2 - geodesy API LatLon
        Returns:
        distance in meters.
      • distanceDegrees

        public static double distanceDegrees​(double lat1,
                                             double lon1,
                                             double lat2,
                                             double lon2)
        This returns distance in degrees, e.g., this is a Cartesian distance. Only to be used for fast comparison of two locations relatively close together, e.g., within the same 1 or 2 degrees of lat or lon. Beyond that there can be a lot of distortion in the physical distance.
        Parameters:
        lat1 - P1.lat
        lon1 - P1.lon
        lat2 - P2.lat
        lon2 - P2.lon
        Returns:
        distance between p1 and p2 in degrees.
      • getFeaturePrecision

        public static int getFeaturePrecision​(java.lang.String feat_type,
                                              java.lang.String feat_code)
        For a given feature type and code, determine what sort of resolution or precision should be considered for that place, approximately.
        Parameters:
        feat_type - major feature type
        feat_code - minor feature type or designation
        Returns:
        precision approx error in meters for a given feature. -1 if no feature type given.
      • getGeohashPrecision

        public static int getGeohashPrecision​(java.lang.String feat_type,
                                              java.lang.String feat_code)
        For a given Geonames feature class/designation provide a guess about how long geohash should be. Geohash in this use is very approximate
        Parameters:
        feat_type - major feature type
        feat_code - minor feature type or designation
        Returns:
        prefix length for a geohash, e.g., for a province in general is 3 chars of geohash sufficient?
      • parseLatLon

        public static LatLon parseLatLon​(java.lang.String lat_lon)
                                  throws java.text.ParseException
        The most simplistic parsing and validation of "lat lon" or "lat, lon" any amount of whitespace is allowed, provided the lat lon order is there.
        Parameters:
        lat_lon - string form of a simple lat/lon, e.g., "Y X"; No symbols
        Returns:
        LatLon object
        Throws:
        java.text.ParseException - if string is unparsable
      • parseLatLon

        public static LatLon parseLatLon​(java.lang.Object lat,
                                         java.lang.Object lon)
                                  throws java.text.ParseException
        Parse coordinate from object
        Parameters:
        lat - latitude
        lon - longitude
        Returns:
        LatLon object
        Throws:
        java.text.ParseException - if objects are not valid numbers
      • formatLatLon

        public static final java.lang.String formatLatLon​(LatLon yx)
        Create a string representation of a decimal lat/lon.
        Parameters:
        yx - LatLon object
        Returns:
        "lat, lon" formatted with 4 decimal places; that is an average amount of precision for common XY=> String uses.
      • geohash

        public static final java.lang.String geohash​(LatLon yx)
        Parameters:
        yx - lat,lon obj
        Returns:
        geohash representation of the lat,lon
      • geohash

        public static final java.lang.String geohash​(double lat,
                                                     double lon)