Package mil.nga.mgrs
Class MGRS
- java.lang.Object
-
- mil.nga.mgrs.MGRS
-
public class MGRS extends Object
Military Grid Reference System Coordinate- Author:
- wnewman, osbornb
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
accuracy()
Get the MGRS coordinate accuracy number of digitsstatic int
accuracy(String mgrs)
Get the MGRS coordinate accuracy number of digitsString
coordinate()
Get the MGRS coordinate with one meter precisionString
coordinate(int accuracy)
Get the MGRS coordinate with the accuracy number of digits in the easting and northing values.String
coordinate(GridType type)
Get the MGRS coordinate with specified grid precisionstatic MGRS
create(int zone, char band, char column, char row, long easting, long northing)
Createstatic MGRS
create(int zone, char band, long easting, long northing)
Createstatic MGRS
from(double longitude, double latitude)
Convert the coordinate to MGRSstatic MGRS
from(Point point)
Encodes a point as a MGRS stringchar
getBand()
Get the band letterchar
getColumn()
Get the column letterstatic char
getColumnLetter(int zoneNumber, double easting)
Get the column letter from the zone number and eastingstatic char
getColumnLetter(UTM utm)
Get the column letter from the UTMString
getColumnRowId()
Get the two letter column and row 100k designatorstatic String
getColumnRowId(double easting, double northing, int zoneNumber)
Get the two letter column and row 100k designator for a given UTM easting, northing and zone number valuelong
getEasting()
Get the eastingString
getEastingAndNorthing(GridType type)
Get the easting and northing concatenated value in the grid type precisionGridZone
getGridZone()
Get the GZD grid zoneHemisphere
getHemisphere()
Get the hemispherelong
getNorthing()
Get the northingchar
getRow()
Get the row letterstatic char
getRowLetter(int zoneNumber, double northing)
Get the row letter from the zone number and northingstatic char
getRowLetter(UTM utm)
Get the row letter from the UTMdouble
getUTMEasting()
Get the UTM eastingdouble
getUTMNorthing()
Get the UTM northingint
getZone()
Get the zone numberstatic boolean
isMGRS(String mgrs)
Return whether the given string is valid MGRS stringstatic MGRS
parse(String mgrs)
Parse a MGRS stringGridType
precision()
Get the MGRS coordinate grid precisionstatic GridType
precision(String mgrs)
Parse the MGRS string for the precisionPoint
toPoint()
Convert to a pointString
toString()
UTM
toUTM()
Convert to UTM coordinate
-
-
-
Constructor Detail
-
MGRS
public MGRS(int zone, char band, char column, char row, long easting, long northing)
Constructor- Parameters:
zone
- zone numberband
- band lettercolumn
- column letterrow
- row lettereasting
- eastingnorthing
- northing
-
MGRS
public MGRS(int zone, char band, long easting, long northing)
Constructor- Parameters:
zone
- zone numberband
- band lettereasting
- eastingnorthing
- northing
-
-
Method Detail
-
create
public static MGRS create(int zone, char band, char column, char row, long easting, long northing)
Create- Parameters:
zone
- zone numberband
- band lettercolumn
- column letterrow
- row lettereasting
- eastingnorthing
- northing- Returns:
- MGRS
-
create
public static MGRS create(int zone, char band, long easting, long northing)
Create- Parameters:
zone
- zone numberband
- band lettereasting
- eastingnorthing
- northing- Returns:
- MGRS
-
getZone
public int getZone()
Get the zone number- Returns:
- zone number
-
getBand
public char getBand()
Get the band letter- Returns:
- band letter
-
getColumn
public char getColumn()
Get the column letter- Returns:
- column letter
-
getRow
public char getRow()
Get the row letter- Returns:
- row letter
-
getEasting
public long getEasting()
Get the easting- Returns:
- easting
-
getNorthing
public long getNorthing()
Get the northing- Returns:
- northing
-
getHemisphere
public Hemisphere getHemisphere()
Get the hemisphere- Returns:
- hemisphere
-
coordinate
public String coordinate()
Get the MGRS coordinate with one meter precision- Returns:
- MGRS coordinate
-
coordinate
public String coordinate(GridType type)
Get the MGRS coordinate with specified grid precision- Parameters:
type
- grid type precision- Returns:
- MGRS coordinate
-
getEastingAndNorthing
public String getEastingAndNorthing(GridType type)
Get the easting and northing concatenated value in the grid type precision- Parameters:
type
- grid type precision- Returns:
- easting and northing value
-
coordinate
public String coordinate(int accuracy)
Get the MGRS coordinate with the accuracy number of digits in the easting and northing values. Accuracy must be inclusively between 0 (GridType.HUNDRED_KILOMETER
) and 5 (GridType.METER
).- Parameters:
accuracy
- accuracy digits between 0 (inclusive) and 5 (inclusive)- Returns:
- MGRS coordinate
-
precision
public GridType precision()
Get the MGRS coordinate grid precision- Returns:
- grid type precision
-
accuracy
public int accuracy()
Get the MGRS coordinate accuracy number of digits- Returns:
- accuracy digits
-
getColumnRowId
public String getColumnRowId()
Get the two letter column and row 100k designator- Returns:
- the two letter column and row 100k designator
-
getGridZone
public GridZone getGridZone()
Get the GZD grid zone- Returns:
- GZD grid zone
-
toPoint
public Point toPoint()
Convert to a point- Returns:
- point
-
toUTM
public UTM toUTM()
Convert to UTM coordinate- Returns:
- UTM
-
getUTMEasting
public double getUTMEasting()
Get the UTM easting- Returns:
- UTM easting
-
getUTMNorthing
public double getUTMNorthing()
Get the UTM northing- Returns:
- UTM northing
-
isMGRS
public static boolean isMGRS(String mgrs)
Return whether the given string is valid MGRS string- Parameters:
mgrs
- potential MGRS string- Returns:
- true if MGRS string is valid, false otherwise
-
from
public static MGRS from(Point point)
Encodes a point as a MGRS string- Parameters:
point
- point- Returns:
- MGRS
-
from
public static MGRS from(double longitude, double latitude)
Convert the coordinate to MGRS- Parameters:
longitude
- longitudelatitude
- latitude- Returns:
- MGRS
- Since:
- 2.1.1
-
parse
public static MGRS parse(String mgrs) throws ParseException
Parse a MGRS string- Parameters:
mgrs
- MGRS string- Returns:
- MGRS
- Throws:
ParseException
- upon failure to parse the MGRS string
-
precision
public static GridType precision(String mgrs) throws ParseException
Parse the MGRS string for the precision- Parameters:
mgrs
- MGRS string- Returns:
- grid type precision
- Throws:
ParseException
- upon failure to parse the MGRS string
-
accuracy
public static int accuracy(String mgrs) throws ParseException
Get the MGRS coordinate accuracy number of digits- Parameters:
mgrs
- MGRS string- Returns:
- accuracy digits
- Throws:
ParseException
- upon failure to parse the MGRS string
-
getColumnRowId
public static String getColumnRowId(double easting, double northing, int zoneNumber)
Get the two letter column and row 100k designator for a given UTM easting, northing and zone number value- Parameters:
easting
- eastingnorthing
- northingzoneNumber
- zone number- Returns:
- the two letter column and row 100k designator
-
getColumnLetter
public static char getColumnLetter(UTM utm)
Get the column letter from the UTM- Parameters:
utm
- UTM- Returns:
- column letter
-
getColumnLetter
public static char getColumnLetter(int zoneNumber, double easting)
Get the column letter from the zone number and easting- Parameters:
zoneNumber
- zone numbereasting
- easting- Returns:
- column letter
-
getRowLetter
public static char getRowLetter(UTM utm)
Get the row letter from the UTM- Parameters:
utm
- UTM- Returns:
- row letter
-
getRowLetter
public static char getRowLetter(int zoneNumber, double northing)
Get the row letter from the zone number and northing- Parameters:
zoneNumber
- zone numbernorthing
- northing- Returns:
- row letter
-
-