Package mil.nga.mgrs
Class MGRSUtils
- java.lang.Object
-
- mil.nga.mgrs.MGRSUtils
-
public class MGRSUtils extends Object
Military Grid Reference System utilities- Author:
- wnewman, osbornb
-
-
Constructor Summary
Constructors Constructor Description MGRSUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BoundsgetBounds(int x, int y, int zoom)Get the tile bounds from the XYZ tile coordinates and zoom levelstatic StringgetLabelName(int zoneNumber, char bandLetter)Get the label namestatic PixelgetPixel(int width, int height, Bounds bounds, Point point)Get the pixel where the point fits into the boundsstatic floatgetXPixel(int width, Bounds bounds, double longitude)Get the X pixel for where the longitude in meters fits into the boundsstatic floatgetYPixel(int height, Bounds bounds, double latitude)Get the Y pixel for where the latitude in meters fits into the boundsstatic doublegetZoomLevel(Bounds bounds)Get the zoom level of the bounds using the shortest bounds side lengthstatic Pointintersection(Line line1, Line line2)Get the point intersection between two linesstatic Pointintsersection(Point line1Point1, Point line1Point2, Point line2Point1, Point line2Point2)Get the point intersection between end points of two linesstatic booleanisOmittedBandLetter(char letter)The the band letter an omitted letterMGRSConstants.BAND_LETTER_OMIT_IorMGRSConstants.BAND_LETTER_OMIT_Ostatic charnextBandLetter(char letter)Get the next band letterstatic charpreviousBandLetter(char letter)Get the previous band letterstatic doubletileSize(int tilesPerSide)Get the tile size in metersstatic inttilesPerSide(int zoom)Get the tiles per side, width and height, at the zoom levelstatic PointtoDegrees(double longitude, double latitude)Convert a coordinate in meters to a WGS84 pointstatic PointtoMeters(double longitude, double latitude)Convert a WGS84 coordinate to a point in metersstatic PointtoUnit(double longitude, double latitude, Unit unit)Convert a coordinate to the unit, assumes the coordinate is in the opposite unitstatic PointtoUnit(Unit fromUnit, double longitude, double latitude, Unit toUnit)Convert a coordinate from a unit to another unitstatic voidvalidateBandLetter(char letter)Validate the band letterstatic voidvalidateZoneNumber(int number)Validate the zone number
-
-
-
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- widthheight- heightbounds- boundspoint- 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- widthbounds- boundslongitude- 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- heightbounds- boundslatitude- 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 coordinatey- y coordinatezoom- 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 coordinatelongitude- longitudelatitude- latitudetoUnit- 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- longitudelatitude- latitudeunit- 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 longitudelatitude- 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 meterslatitude- 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
-
isOmittedBandLetter
public static boolean isOmittedBandLetter(char letter)
The the band letter an omitted letterMGRSConstants.BAND_LETTER_OMIT_IorMGRSConstants.BAND_LETTER_OMIT_O- Parameters:
letter- band letter- Returns:
- true if omitted
-
getLabelName
public static String getLabelName(int zoneNumber, char bandLetter)
Get the label name- Parameters:
zoneNumber- zone numberbandLetter- band letter- Returns:
- name
-
intersection
public static Point intersection(Line line1, Line line2)
Get the point intersection between two lines- Parameters:
line1- first lineline2- 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 lineline1Point2- second point of the first lineline2Point1- first point of the second lineline2Point2- second point of the second line- Returns:
- intersection point or null if no intersection
-
-