rdf4j-postgis  Version 0.1.0.0
LLtoGARS Class Reference

https://github.com/mil-oss/GARSutils MIT License More...

Static Public Member Functions

static String getLongitudeBand (double longitude)
 Get the GARS 3 letter longitude band descriptor for a given longitude (-180.0..180.0) More...
 
static String getLatitudeBand (double latitude)
 Get the GARS 2 letter latitude band descriptor for a given latitude (-90..90) More...
 
static String getQudarant (double latitude, double longitude)
 Returns the GARS 15 minute quadrant cell identifier for a latitude, longitude pair.This identifier is the 6th character of the GARS code. More...
 
static String getKeyPad (double latitude, double longitude)
 Returns the GARS 5 minute keypad cell identifier for a latitude, longitude pair. More...
 
static String getGARS (double latitude, double longitude, String precision)
 Returns a GARS coordinate string for a point (latitude, longitude) More...
 
static String getGARS (double latitude, double longitude)
 Returns a GARS 5x5 minute coordinate string for a point (latitude, longitude) More...
 

Detailed Description

https://github.com/mil-oss/GARSutils MIT License

Author
marty

Member Function Documentation

◆ getGARS() [1/2]

static String getGARS ( double  latitude,
double  longitude 
)
static

Returns a GARS 5x5 minute coordinate string for a point (latitude, longitude)

Parameters
latitudeas double in degrees decimal
longitudeas double in degrees decimal
Returns
String representation of the GARS identifier, returns 0 if lat/lon is invalid
305  {
306  return getGARS(latitude, longitude, "5");
307  }//getGARS
static String getGARS(double latitude, double longitude, String precision)
Returns a GARS coordinate string for a point (latitude, longitude)
Definition: LLtoGARS.java:182

References LLtoGARS.getGARS().

◆ getGARS() [2/2]

static String getGARS ( double  latitude,
double  longitude,
String  precision 
)
static

Returns a GARS coordinate string for a point (latitude, longitude)

The precision parameter indicates if a 30x30min, 15x15min, or 5x5min GARS code is to be returned.

Valid precision values are ["30","15","5"]

Parameters
latitudeas double in degrees decimal
longitudeas double in degrees decimal
precisionas String representing the precision of the GARS string
Returns
String representation of the GARS identifier, returns 0 if lat/lon is invalid
182  {
183  /* North pole is an exception, read over and down */
184  if (latitude == 90.0) {
185  latitude = 89.99999999999;
186  }
187  // Check for valid lat/lon range
188  if (latitude < -90 || latitude > 90) {
189  return "0";
190  }
191  if (longitude < -180 || longitude > 180) {
192  return "0";
193  }
194  // Get the longitude band ==============================================
195  Double longBand = longitude + 180;
196  // Normalize to 0.0 <= longBand < 360
197  while (longBand < 0) {
198  longBand = longBand + 360;
199  }
200  while (longBand > 360) {
201  longBand = longBand - 360;
202  }
203  longBand = Math.floor(longBand * 2.0);
204  Integer intLongBand = longBand.intValue() + 1; // Start at 001, not 000
205  String strLongBand = intLongBand.toString();
206  // Left pad the string with 0's so X becomes 00X
207  while (strLongBand.length() < 3) {
208  strLongBand = "0" + strLongBand;
209  }
210 
211  // Get the latitude band ===============================================
212  char[] letterArray = "ABCDEFGHJKLMNPQRSTUVWXYZ".toCharArray();
213  Double offset = latitude + 90;
214  // Normalize offset to 0< offset <90
215  while (offset < 0) {
216  offset = offset + 180;
217  }
218  while (offset > 180) {
219  offset = offset - 180;
220  }
221  offset = Math.floor(offset * 2.0);
222  Double firstOffest = offset / letterArray.length;
223  Double secondOffest = offset % letterArray.length;
224  StringBuilder sb = new StringBuilder();
225  String strLatBand = sb.append(letterArray[firstOffest.intValue()]).append(letterArray[secondOffest.intValue()]).toString();
226 
227  // Id the precision is 30x30min then return the longitudinal and latitudinal bands
228  if (precision.contains("30")) {
229  return strLongBand + strLatBand;
230  }
231 
232  // Get the quadrant ====================================================
233  Double latBand = (Math.floor((latitude + 90.0) * 4.0) % 2.0);
234  longBand = (Math.floor((longitude + 180.0) * 4.0) % 2.0);
235  String quadrant = "0";
236  // return "0" if error occurs
237  if (latBand < 0 || latBand > 1) {
238  return "0";
239  }
240  if (longBand < 0 || longBand > 1) {
241  return "0";
242  }
243  // Otherwise get the quadrant
244  if (latBand == 0.0 && longBand == 0.0) {
245  quadrant = "3";
246  } else if (latBand == 1.0 && longBand == 0.0) {
247  quadrant = "1";
248  } else if (latBand == 1.0 && longBand == 1.0) {
249  quadrant = "2";
250  } else if (latBand == 0.0 && longBand == 1.0) {
251  quadrant = "4";
252  }
253 
254  // Id the precision is 15x15min then return the longitudinal and latitudinal bands
255  // plus the quadrant
256  if (precision.contains("15")) {
257  return strLongBand + strLatBand + quadrant;
258  }
259 
260  // Get the keypad ======================================================
261  /* Convert longitude and latitude from degrees to minutes */
262  /* longitude assumed in -180 <= long < +180 range */
263  double long_minutes = (longitude + 180) * 60.0;
264  double lat_minutes = (latitude + 90) * 60.0;
265  /* now we have a positive number of minutes */
266 
267  /* Find 30-min cell indices 0-719 and 0-359 */
268  long horiz_index_30 = (long) (long_minutes / 30.0);
269  long vert_index_30 = (long) (lat_minutes / 30.0);
270 
271  /* Compute remainders 0 <= x < 30.0 */
272  double long_remainder = long_minutes - (horiz_index_30) * 30.0;
273  double lat_remainder = lat_minutes - (vert_index_30) * 30.0;
274 
275  /* Find 15-min cell indices 0 or 1 */
276  long horiz_index_15 = (long) (long_remainder / 15.0);
277  long vert_index_15 = (long) (lat_remainder / 15.0);
278 
279  /* Compute remainders 0 <= x < 15.0 */
280  long_remainder = long_remainder - (horiz_index_15) * 15.0;
281  lat_remainder = lat_remainder - (vert_index_15) * 15.0;
282 
283  /* Find 5-min cell indices 0, 1, or 2 */
284  long horiz_index_5 = (long) (long_remainder / 5.0);
285  long vert_index_5 = (long) (lat_remainder / 5.0);
286 
287  String[][] _5_minute_array = {{"7", "4", "1"}, {"8", "5", "2"}, {"9", "6", "3"}};
288 
289  String keypad = _5_minute_array[(int) horiz_index_5][(int) vert_index_5];
290 
291  return strLongBand + strLatBand + quadrant + keypad;
292  }//getGARS

Referenced by LLtoGARS.getGARS(), and AsGARS.operation().

◆ getKeyPad()

static String getKeyPad ( double  latitude,
double  longitude 
)
static

Returns the GARS 5 minute keypad cell identifier for a latitude, longitude pair.

This is the seventh character of the GARS code.
Each 15-minute quadrant is divided into nine 5-minute by 5-minute areas. The areas are numbered sequentially, from west to east, starting with the northernmost band. The graphical representation of a 15-minute quadrant with numbered 5-minute by 5-minute areas resembles a telephone keypad.

This code was ported from the Geotrans 3.5 CCP implementation: http://earth-info.nga.mil/GandG/geotrans/

Parameters
latitudeas double in degrees decimal
longitudeas double in degrees decimal
Returns
String of the 5x5 identifier (1..9), returns 0 if lat/lon is invalid
123  {
124  // Check for valid lat/lon range
125  if (latitude < -90 || latitude > 90) {
126  return "0";
127  }
128  if (longitude < -180 || longitude > 180) {
129  return "0";
130  }
131 
132  /* Convert longitude and latitude from degrees to minutes */
133  /* longitude assumed in -180 <= long < +180 range */
134  double long_minutes = (longitude + 180) * 60.0;
135  double lat_minutes = (latitude + 90) * 60.0;
136  /* now we have a positive number of minutes */
137 
138  /* Find 30-min cell indices 0-719 and 0-359 */
139  long horiz_index_30 = (long) (long_minutes / 30.0);
140  long vert_index_30 = (long) (lat_minutes / 30.0);
141 
142  /* Compute remainders 0 <= x < 30.0 */
143  double long_remainder = long_minutes - (horiz_index_30) * 30.0;
144  double lat_remainder = lat_minutes - (vert_index_30) * 30.0;
145 
146  /* Find 15-min cell indices 0 or 1 */
147  long horiz_index_15 = (long) (long_remainder / 15.0);
148  long vert_index_15 = (long) (lat_remainder / 15.0);
149 
150  /* Compute remainders 0 <= x < 15.0 */
151  long_remainder = long_remainder - (horiz_index_15) * 15.0;
152  lat_remainder = lat_remainder - (vert_index_15) * 15.0;
153 
154  /* Find 5-min cell indices 0, 1, or 2 */
155  long horiz_index_5 = (long) (long_remainder / 5.0);
156  long vert_index_5 = (long) (lat_remainder / 5.0);
157 
158  String[][] _5_minute_array = {{"7", "4", "1"}, {"8", "5", "2"}, {"9", "6", "3"}};
159 
160  String keypad = _5_minute_array[(int) horiz_index_5][(int) vert_index_5];
161 
162  return keypad;
163 
164  }//getKeyPad

◆ getLatitudeBand()

static String getLatitudeBand ( double  latitude)
static

Get the GARS 2 letter latitude band descriptor for a given latitude (-90..90)

The fourth and fifth characters of a GARS code represent 30-minute latitudinal bands and are numbered from AA through QZ, starting at -90 through 90.

Parameters
latitudeas double in degrees decimal
Returns
String representation of the 2 character latitudinal band
51  {
52  char[] letterArray = "ABCDEFGHJKLMNPQRSTUVWXYZ".toCharArray();
53  Double offset = latitude + 90;
54  // Normalize offset to 0< offset <90
55  while (offset < 0) {
56  offset = offset + 180;
57  }
58  while (offset > 180) {
59  offset = offset - 180;
60  }
61  offset = Math.floor(offset * 2.0);
62  Double firstOffest = offset / letterArray.length;
63  Double secondOffest = offset % letterArray.length;
64  StringBuilder sb = new StringBuilder();
65  sb.append(letterArray[firstOffest.intValue()]).append(letterArray[secondOffest.intValue()]);
66  return sb.toString();
67  }//getLatitudeBand

◆ getLongitudeBand()

static String getLongitudeBand ( double  longitude)
static

Get the GARS 3 letter longitude band descriptor for a given longitude (-180.0..180.0)

The longitude band are the first three characters of the GARS code.
The bands are numbered from 001 through 720, starting at -180 through 180 and depict 30-minute longitudinal bands.

Parameters
longitudeas double in degrees decimal
Returns
String representation of the 3 character longitudinal band
21  {
22  Double longBand = longitude + 180;
23  // Normalize to 0.0 <= longBand < 360
24  while (longBand < 0) {
25  longBand = longBand + 360;
26  }
27  while (longBand > 360) {
28  longBand = longBand - 360;
29  }
30  longBand = Math.floor(longBand * 2.0);
31  Integer intLongBand = longBand.intValue() + 1; // Start at 001, not 000
32  String strLongBand = intLongBand.toString();
33  // Left pad the string with 0's so X becomes 00X
34  while (strLongBand.length() < 3) {
35  strLongBand = "0" + strLongBand;
36  }
37  return strLongBand;
38  }//getLongitudeBand

◆ getQudarant()

static String getQudarant ( double  latitude,
double  longitude 
)
static

Returns the GARS 15 minute quadrant cell identifier for a latitude, longitude pair.This identifier is the 6th character of the GARS code.


Each 30-minute cell is divided into four 15-minute by 15-minute quadrants. The quadrants are numbered sequentially, from west to east, starting with the northernmost band. Specifically, the northwest quadrant is 1; the northeast quadrant is 2; the southwest quadrant is 3; the southeast quadrant is 4.

Parameters
latitudeas double in degrees decimal
longitudeas double in degrees decimal
Returns
String of the quadrant identifier (1..4), returns 0 if lat/lon is invalid
84  {
85  Double latBand = (Math.floor((latitude + 90.0) * 4.0) % 2.0);
86  Double longBand = (Math.floor((longitude + 180.0) * 4.0) % 2.0);
87  // Return "0" if error occurs
88  if (latBand < 0 || latBand > 1) {
89  return "0";
90  }
91  if (longBand < 0 || longBand > 1) {
92  return "0";
93  }
94  // Otherwise return the quadrant
95  if (latBand == 0.0 && longBand == 0.0) {
96  return "3";
97  } else if (latBand == 1.0 && longBand == 0.0) {
98  return "1";
99  } else if (latBand == 1.0 && longBand == 1.0) {
100  return "2";
101  } else if (latBand == 0.0 && longBand == 1.0) {
102  return "4";
103  }
104  return "0";
105  }//getQudarant