Package mil.nga.mgrs

Class MGRSUtils


  • public class MGRSUtils
    extends Object
    Military Grid Reference System utilities
    Author:
    wnewman, osbornb
    • Constructor Detail

      • MGRSUtils

        public MGRSUtils()
    • Method Detail

      • getPixel

        public static Pixel getPixel​(int width,
                                     int height,
                                     Bounds bounds,
                                     Point point)
        Get the pixel where the point fits into the bounds
        Parameters:
        width - width
        height - height
        bounds - bounds
        point - point
        Returns:
        pixel
      • getXPixel

        public static float getXPixel​(int width,
                                      Bounds bounds,
                                      double longitude)
        Get the X pixel for where the longitude in meters fits into the bounds
        Parameters:
        width - width
        bounds - bounds
        longitude - longitude in meters
        Returns:
        x pixel
      • getYPixel

        public static float getYPixel​(int height,
                                      Bounds bounds,
                                      double latitude)
        Get the Y pixel for where the latitude in meters fits into the bounds
        Parameters:
        height - height
        bounds - bounds
        latitude - latitude
        Returns:
        y pixel
      • getBounds

        public static Bounds getBounds​(int x,
                                       int y,
                                       int zoom)
        Get the tile bounds from the XYZ tile coordinates and zoom level
        Parameters:
        x - x coordinate
        y - y coordinate
        zoom - zoom level
        Returns:
        bounds
      • tilesPerSide

        public static int tilesPerSide​(int zoom)
        Get the tiles per side, width and height, at the zoom level
        Parameters:
        zoom - zoom level
        Returns:
        tiles per side
      • tileSize

        public static double tileSize​(int tilesPerSide)
        Get the tile size in meters
        Parameters:
        tilesPerSide - tiles per side
        Returns:
        tile size
      • getZoomLevel

        public static double getZoomLevel​(Bounds bounds)
        Get the zoom level of the bounds using the shortest bounds side length
        Parameters:
        bounds - bounds
        Returns:
        zoom level
      • toUnit

        public static Point toUnit​(Unit fromUnit,
                                   double longitude,
                                   double latitude,
                                   Unit toUnit)
        Convert a coordinate from a unit to another unit
        Parameters:
        fromUnit - unit of provided coordinate
        longitude - longitude
        latitude - latitude
        toUnit - desired unit
        Returns:
        point in unit
      • toUnit

        public static Point toUnit​(double longitude,
                                   double latitude,
                                   Unit unit)
        Convert a coordinate to the unit, assumes the coordinate is in the opposite unit
        Parameters:
        longitude - longitude
        latitude - latitude
        unit - desired unit
        Returns:
        point in unit
      • toMeters

        public static Point toMeters​(double longitude,
                                     double latitude)
        Convert a WGS84 coordinate to a point in meters
        Parameters:
        longitude - WGS84 longitude
        latitude - WGS84 latitude
        Returns:
        point in meters
      • toDegrees

        public static Point toDegrees​(double longitude,
                                      double latitude)
        Convert a coordinate in meters to a WGS84 point
        Parameters:
        longitude - longitude in meters
        latitude - latitude in meters
        Returns:
        WGS84 coordinate
      • validateZoneNumber

        public static void validateZoneNumber​(int number)
        Validate the zone number
        Parameters:
        number - zone number
      • validateBandLetter

        public static void validateBandLetter​(char letter)
        Validate the band letter
        Parameters:
        letter - band letter
      • nextBandLetter

        public static char nextBandLetter​(char letter)
        Get the next band letter
        Parameters:
        letter - band letter
        Returns:
        next band letter, 'Y' (MGRSConstants.MAX_BAND_LETTER + 1) if no next bands
      • previousBandLetter

        public static char previousBandLetter​(char letter)
        Get the previous band letter
        Parameters:
        letter - band letter
        Returns:
        previous band letter, 'B' (MGRSConstants.MIN_BAND_LETTER - 1) if no previous bands
      • getLabelName

        public static String getLabelName​(int zoneNumber,
                                          char bandLetter)
        Get the label name
        Parameters:
        zoneNumber - zone number
        bandLetter - band letter
        Returns:
        name
      • intersection

        public static Point intersection​(Line line1,
                                         Line line2)
        Get the point intersection between two lines
        Parameters:
        line1 - first line
        line2 - second line
        Returns:
        intersection point or null if no intersection
      • intsersection

        public static Point intsersection​(Point line1Point1,
                                          Point line1Point2,
                                          Point line2Point1,
                                          Point line2Point2)
        Get the point intersection between end points of two lines
        Parameters:
        line1Point1 - first point of the first line
        line1Point2 - second point of the first line
        line2Point1 - first point of the second line
        line2Point2 - second point of the second line
        Returns:
        intersection point or null if no intersection