Class TLcdGARSFormat
- All Implemented Interfaces:
ILcdFormatter,ILcdParser,Serializable,Cloneable
ILcdPoint.
The formatting and parsing of GARS coordinate strings can be customized using a TLcdGARSFormat.Precision or a GARS format string.
An example of a GARS coordinate string is 182QW37. This string consists of
182: A number identifying the easting component of a 30 minutes square, starting at -180 degrees longitude.QW: Letters identifying the northing component of a 30 minutes square, starting at -90 degrees latitude.3: One digit identifying a 15 minute square within this 30 minutes square.7: One digit identifying a 5 minute square within this 15 minutes square.
Examples
Formatting with precision
ILcdPoint point = new TLcdLonLatPoint(21.036681004382054, -89.98288423774106);
TLcdGARSFormat formatInstance = new TLcdGARSFormat(TLcdGARSFormat.Precision.KEYPAD);
String format = formatInstance.format(point);
Formatting with format string
ILcdPoint point = new TLcdLonLatPoint(21.036681004382054, -89.98288423774106);
TLcdGARSFormat formatInstance = new TLcdGARSFormat("X3YQK");
String format = formatInstance.format(point);
Parsing with precision
TLcdGARSFormat format = new TLcdGARSFormat(TLcdGARSFormat.Precision.KEYPAD);
ILcdPoint point = format.parse("403AA37");
Parsing with format string
TLcdGARSFormat format = new TLcdGARSFormat("X3_Y_Q_K");
ILcdPoint point = format.parse("403_AA_3_7");
Patterns
| GARS | Lon lat | Precision | Format string |
|---|---|---|---|
| 403AA37 | 21.04166..., -89.95833.. | KEYPAD | X3YQK |
| 403AA3 | 21.125, -89.875 | QUADRANT | X3YQ |
| 403AA | 21.25, -89.75 | CELL | X3Y |
- Since:
- 2020.1
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe precision of the formatted GARS coordinate strings.Nested classes/interfaces inherited from class java.text.Format
Format.Field -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newTLcdGARSFormatthat uses a default precision ofTLcdGARSFormat.Precision.KEYPAD(5-minute by 5-minute grid) to format anILcdPoint.TLcdGARSFormat(TLcdGARSFormat.Precision aPrecision) Creates a newTLcdGARSFormatthat uses the given precision to format anILcdPoint.TLcdGARSFormat(String aFormat) Creates a newTLcdGARSFormatthat uses the given format to format anILcdPoint. -
Method Summary
Modifier and TypeMethodDescriptionbooleanformat(Object aObject, StringBuffer aToAppendTo, FieldPosition aPosition) Formats anILcdPointand appends the resulting text to a given string buffer.Returns the GARS pattern used as described inTLcdGARSFormat(java.lang.String).Returns the precision when formatting points as GARS coordinate strings.inthashCode()parseObject(String aSource, ParsePosition aPosition) Parses text from a GARS coordinate string to produce anILcdPointwith WGS84 longitude latitude coordinates.voidsetPrecision(TLcdGARSFormat.Precision aPrecision) Sets the precision when formatting points as GARS coordinate strings.toString()Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObjectMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.luciad.util.ILcdFormatter
format
-
Constructor Details
-
TLcdGARSFormat
public TLcdGARSFormat()Creates a newTLcdGARSFormatthat uses a default precision ofTLcdGARSFormat.Precision.KEYPAD(5-minute by 5-minute grid) to format anILcdPoint. Default constructor forTLcdGARSFormat.- See Also:
-
TLcdGARSFormat
Creates a newTLcdGARSFormatthat uses the given precision to format anILcdPoint.- Parameters:
aPrecision- aPrecisionas an argument, nevernull- Throws:
NullPointerException- ifaPrecisionis null.- See Also:
-
TLcdGARSFormat
Creates a newTLcdGARSFormatthat uses the given format to format anILcdPoint.The format should be expressed in EBNF notation (expressions enclosed in
[]brackets are optional, expressions enclosed in{}brackets may be omitted or repeated):<pattern> ::= <cellX> {<separator>} <cellY> [{<separator>} <quadrant>] [{<separator>} <keypad>] <cellX> ::= "X" | "X", <cellMinimumCharacterLength> <cellY> ::= "Y" | "Y", <cellMinimumCharacterLength> <quadrant> ::= "Q" <keypad> ::= "K" <cellMinimumCharacterLength> ::= "2" | "3" <separator> ::= { ? any character ? }When the minimum character length is higher than the amount of actual characters, it will be padded with default characters. For X it will be padded with "0" (zero), for Y it will be padded with " " (space). When the minimum character length is lower than or equal to the amount of characters, the minimum character length has no effect. For example:- "340X15" has format "XYQK"
- "182_ QW_7_2" has format "X3_Y3_K_Q"
- Parameters:
aFormat- a format string, nevernull- Throws:
NullPointerException- ifaFormatis null.- Since:
- 2021.1
-
-
Method Details
-
getPattern
Returns the GARS pattern used as described inTLcdGARSFormat(java.lang.String).- Returns:
- the current GARS pattern in EBNF format
- Since:
- 2021.1
-
getPrecision
Returns the precision when formatting points as GARS coordinate strings.For example, a precision value of
TLcdGARSFormat.Precision.KEYPADwill output GARS coordinate strings representing a grid of 5-minute by 5-minute area on the map.- Returns:
- the precision when formatting points as GARS coordinate strings
-
setPrecision
Sets the precision when formatting points as GARS coordinate strings.For example, a precision value of
TLcdGARSFormat.Precision.KEYPADwill output GARS coordinate strings representing a grid of 5-minute by 5-minute area on the map.- Parameters:
aPrecision-Precisionfor the GARS grid coordinate format, nevernull
-
format
Formats anILcdPointand appends the resulting text to a given string buffer. If theaPositionargument identifies a field used by the format, its indices are set to the beginning and end of the first such field encountered.- Specified by:
formatin classFormat- Parameters:
aObject- The object to format. This should be anILcdPoint.aToAppendTo- where the text is to be appendedaPosition- AFieldPositionidentifying a field in the formatted text- Returns:
- the string buffer passed in as
aToAppendTo, with formatted GARS Coordinate String appended - Throws:
NullPointerException- ifaObjectoraToAppendTois nullIllegalArgumentException- if the Format cannot format the given object
-
parse
- Specified by:
parsein interfaceILcdParser- Parameters:
aString- theStringrepresenting a GARS coordinate to be parsed.- Returns:
- an
ILcdPoint - Throws:
IllegalArgumentException- if theStringcan't be parsed.
-
parseObject
Parses text from a GARS coordinate string to produce anILcdPointwith WGS84 longitude latitude coordinates.The method attempts to parse a string representing a GARS coordinate, starting at the index given by
aPosition. Parsing does not necessarily use all characters up to the end of the string. If parsing succeeds, the index ofaPositionis updated to the index after the last character used, and the parsed object is returned. The updatedaPositioncan be used to indicate the starting point for the next call to this method. If an error occurs, the index ofaPositionis not changed. The error index ofaPositionis set to the index of the character where the error occurred, and null is returned.- Specified by:
parseObjectin classFormat- Parameters:
aSource- AStringrepresenting a GARS coordinate, part of which should be parsed.aPosition- AParsePositionobject with index and error index information as described above.- Returns:
- an
ILcdPointparsed from the string. In case of error, returnsnull. - Throws:
NullPointerException- ifaSourceoraPositionisnull.- See Also:
-
toString
-
equals
-
hashCode
public int hashCode()
-