Class GeodeticUtility

java.lang.Object
org.opensextant.util.GeodeticUtility

public class GeodeticUtility extends 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
  • Field Details

    • LAT_MAX

      public static final int LAT_MAX
      See Also:
    • LON_MAX

      public static final int LON_MAX
      See Also:
    • EARTH_RADIUS

      public static final long EARTH_RADIUS
      See Also:
    • FEATURE_PRECISION

      public static final Map<String,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 Map<String,Integer> FEATURE_GEOHASH_PRECISION
    • DEFAULT_PRECISION

      public static final int DEFAULT_PRECISION
      See Also:
    • DEFAULT_GEOHASH_PRECISION

      public static final int DEFAULT_GEOHASH_PRECISION
      See Also:
  • Method Details

    • validateCoordinate

      public static 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 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 boolean isCoord(double lat, double lon)
    • isCoord

      public static boolean isCoord(LatLon p)
    • distanceDegrees

      public static 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 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(String feat_type, 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(String feat_type, 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(String lat_lon) throws 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:
      ParseException - if string is unparsable
    • parseLatLon

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

      public static 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 String geohash(LatLon yx)
      Parameters:
      yx - lat,lon obj
      Returns:
      geohash representation of the lat,lon
    • geohash

      public static String geohash(double lat, double lon)