Class GeoUtils

java.lang.Object
org.deltava.util.GeoUtils

public class GeoUtils extends Object
A utility class for performing geocoding operations.
Since:
1.0
Version:
11.6
Author:
Luke
  • Method Details

    • greatCircle

      public static List<GeoLocation> greatCircle(GeoLocation start, GeoLocation end, int granularity)
      Creates a Great Circle route between two points.
      Parameters:
      start - the start location
      end - the end location
      granularity - the maxmimum distance between points
      Returns:
      a List of GeoPositions describing the Great Circle route
    • format2D

      public static String format2D(GeoLocation loc)
      Formats a geographic location as "longitude,latitude".
      Parameters:
      loc - the location
      Returns:
      the formatted location string
    • format3D

      public static String format3D(GeoLocation loc, int altitude)
      Formats a geospatial location as "longitude,latitude,altitude". The altitude will be converted from feet to meters for Google Earth.
      Parameters:
      loc - the location
      altitude - the altitude in feet
      Returns:
      the formatted location string
    • format3D

      public static String format3D(GeospaceLocation loc)
      Formats a geospatial location as "longitude,latitude,altitude". The altitude will be converted from feet to meters for Google Earth.
      Parameters:
      loc - the location
      Returns:
      the formatted location string
    • formatFS9

      public static String formatFS9(GeoLocation loc)
      Formats a location into a format suitable for inclusion in a Microsoft Flight Simulator 2004 flight plan.
      Parameters:
      loc - the location
      Returns:
      a formatted location
    • formatFSX

      public static String formatFSX(GeoLocation loc)
      Formats a location into a format suitable for inclusion in a Microsoft Flight Simulator X or Lockheed-Martin Prepar3D flight plan.
      Parameters:
      loc - the location
      Returns:
      a formatted location
    • formatFSElevation

      public static String formatFSElevation(int elevation)
      Formats an elevation for Flight Simulator flight plans
      Parameters:
      elevation - the elevation in feet
      Returns:
      the formatted elevation
    • normalize

      public static double normalize(double degrees)
      "Normalizes" an angle by ensuring it is between 0 and 360.
      Parameters:
      degrees - the angle in degrees
      Returns:
      the normalized angle
    • delta

      public static double delta(double hdg1, double hdg2)
      Calculates the delta between two headings.
      Parameters:
      hdg1 - the first heading in degrees
      hdg2 - the second heading in degrees
      Returns:
      the delta in degrees
    • getBoundingBox

      public static Tuple<GeoLocation, GeoLocation> getBoundingBox(Collection<? extends GeoLocation> locs)
      Returns a bounding box that contains all of the specified locations.
      Parameters:
      locs - a Collection of GeoLocations
      Returns:
      a Tuple with the northeast and southwest limits of the box
    • normalize

      public static GeoLocation normalize(double lat, double lng)
      "Normalizes" a geographic location by ensuring that the latitude is between -90 and 90 degrees, and the longitude is between -180 and 180 degrees.
      Parameters:
      lat - the latitude
      lng - the longitude
      Returns:
      the normalized location
    • bearingPointS

      public static GeoLocation bearingPointS(GeoLocation p1, double distance, double angle)
      Determines the coordinates of a second point on a particular heading from the first, assuming a spherical globe.
      Parameters:
      p1 - the original point
      distance - the distance in miles
      angle - the angle in degrees
      Returns:
      a GeoLocation
    • neighbors

      public static List<GeoLocation> neighbors(GeoLocation gl, Collection<? extends GeoLocation> points, int distance)
      Returns all the neighbors of a location within a certain distance.
      Parameters:
      gl - the point
      points - the locations to check
      distance - the distance in miles
      Returns:
      a Collection of GeoLocations
    • course

      public static double course(GeoLocation l1, GeoLocation l2)
      Calculates the course between two points.
      Parameters:
      l1 - the first GeoLocation
      l2 - the second GeoLocation
      Returns:
      the initial course in degrees
    • meridianLatitude

      public static double meridianLatitude(GeoLocation l1, GeoLocation l2, double lng)
      Returns the latitude at which point a Greate Cirlce route intersects a meridian.
      Parameters:
      l1 - the first GeoLocation
      l2 - the second GeoLocation
      lng - the longitude in degrees
      Returns:
      the latitude in degrees
    • crossesMeridian

      public static boolean crossesMeridian(GeoLocation l1, GeoLocation l2, double lng)
      Returns whether a direct Great Circle route crosses a meridian.
      Parameters:
      l1 - the first GeoLocation
      l2 - the second GeoLocation
      lng - the longitude in degrees
      Returns:
      TRUE if the meridian is crossed on the most direct route, otherwise FALSE
    • stripDetours

      public static <T extends GeoLocation> List<T> stripDetours(Collection<T> entries, int minDetour)
      Strips out spurious waypoints from a route, that are at least a certain number of miles off the most direct route.
      Parameters:
      entries - a Collection of GeoLocation objects
      minDetour - the minimum
      Returns:
      the stripped list of GeoLocations
    • parseXACARS

      public static GeoLocation parseXACARS(String pos)
      Parses XACARS-format geolocations.
      Parameters:
      pos - an XACARS format geolocation
      Returns:
      a GeoLocation
    • isValid

      public static boolean isValid(GeoLocation loc)
      Returns whether a location is valid (ie. not 0/0/0)
      Parameters:
      loc - a GeoLocation
      Returns:
      TRUE if valid, otherwise FALSE
    • toRing

      public static com.vividsolutions.jts.geom.LinearRing toRing(Collection<GeoLocation> pts)
      Converts a Collection of GeoLocations into a LinearRing object.
      Parameters:
      pts - a Collection of GeoLocations
      Returns:
      a LinearRing object
    • toGeometry

      public static com.vividsolutions.jts.geom.Geometry toGeometry(Collection<GeoLocation> pts)
      Converts a Collection of GeoLocations into a Geometry object.
      Parameters:
      pts - a Collection of GeoLocations
      Returns:
      a Geometry object
    • toMultiPolygon

      public static com.vividsolutions.jts.geom.MultiPolygon toMultiPolygon(Collection<Collection<GeoLocation>> pts)
      Converts a Collection of GeoLocations into a Geometry object.
      Parameters:
      pts - a Collection of GeoLocations
      Returns:
      a Geometry object
    • fromGeometry

      public static Collection<GeoLocation> fromGeometry(com.vividsolutions.jts.geom.Geometry geo)
      Parses a Geometry object and converts it into a Collection of GeoLocations.
      Parameters:
      geo - a Geometry
      Returns:
      a Collection of GeoLocations
    • fromMultiPolygon

      public static Collection<Collection<GeoLocation>> fromMultiPolygon(com.vividsolutions.jts.geom.MultiPolygon mp)
      Parses a MultiPolygon object and converts each of its Geometries into a Collection of GeoLocations.
      Parameters:
      mp - a MultiPolygon
      Returns:
      a Collection of Collections of GeoLocations
    • round

      public static GeoLocation round(GeoLocation loc, double precision)
      Rounds a GeoLocation down to a specific number of decimal places.
      Parameters:
      loc - a GeoLocation
      precision - the preicison amount
      Returns:
      a GeoLocation
    • toCoordinate

      public static com.vividsolutions.jts.geom.Coordinate toCoordinate(GeoLocation loc)
      Converts a GeoLocation to a JTS Coordinate.
      Parameters:
      loc - a GeoLocation
      Returns:
      a JTS Coordinate
    • fromCoordinate

      public static GeoLocation fromCoordinate(com.vividsolutions.jts.geom.Coordinate c)
      Converts a JTS Coordinate to a GeoLocation.
      Parameters:
      c - a Coordinate
      Returns:
      a GeoLocation