?? mgrspoint.java
字號(hào):
if (colInt == I || (colOrigin < I && colInt > I) || ((colInt > I || colOrigin < I) && rollover)) { colInt++; if (DEBUG) System.out.println("skipping I in col, new value: " + (char) colInt); } if (colInt == O || (colOrigin < O && colInt > O) || ((colInt > O || colOrigin < O) && rollover)) { colInt++; if (DEBUG) System.out.println("skipping O in col, new value: " + (char) colInt); if (colInt == I) { colInt++; if (DEBUG) System.out.println(" hit I, new value: " + (char) colInt); } } if (colInt > Z) { colInt = colInt - Z + A - 1; if (DEBUG) System.out.println("rolling(2) col, new value: " + (char) rowInt); } if (rowInt > V) { rowInt = rowInt - V + A - 1; rollover = true; if (DEBUG) System.out.println("rolling over row, new value: " + (char) rowInt); } else { rollover = false; } if (rowInt == I || (rowOrigin < I && rowInt > I) || ((rowInt > I || rowOrigin < I) && rollover)) { rowInt++; if (DEBUG) System.out.println("skipping I in row, new value: " + (char) rowInt); } if (rowInt == O || (rowOrigin < O && rowInt > O) || ((rowInt > O || rowOrigin < O) && rollover)) { rowInt++; if (DEBUG) System.out.println("skipping O in row, new value: " + (char) rowInt); if (rowInt == I) { rowInt++; if (DEBUG) System.out.println(" hit I, new value: " + (char) rowInt); } } if (rowInt > V) { rowInt = rowInt - V + A - 1; if (DEBUG) System.out.println("rolling(2) row, new value: " + (char) rowInt); } String twoLetter = (char) colInt + "" + (char) rowInt; if (DEBUG) { System.out.println("ending at = " + twoLetter); } return twoLetter; } /** * Testing method, used to print out the MGRS 100k two letter set * tables. */ protected void print100kSets() { StringBuffer sb = null; for (int set = 1; set <= 6; set++) { System.out.println("-------------\nFor 100K Set " + set + ":\n-------------\n"); for (int i = 19; i >= 0; i -= 1) { sb = new StringBuffer((i * 100000) + "\t| "); for (int j = 1; j <= 8; j++) { sb.append(" " + get100kID(j, i, set)); } sb.append(" |"); System.out.println(sb); } } } /** * The function getMinNorthing returns the minimum northing value * of a MGRS zone. * * portted from Geotrans' c Lattitude_Band_Value strucure table. * zoneLetter : MGRS zone (input) */ protected float getMinNorthing(char zoneLetter) throws NumberFormatException { float northing; switch (zoneLetter) { case 'C': northing = 1100000.0f; break; case 'D': northing = 2000000.0f; break; case 'E': northing = 2800000.0f; break; case 'F': northing = 3700000.0f; break; case 'G': northing = 4600000.0f; break; case 'H': northing = 5500000.0f; break; case 'J': northing = 6400000.0f; break; case 'K': northing = 7300000.0f; break; case 'L': northing = 8200000.0f; break; case 'M': northing = 9100000.0f; break; case 'N': northing = 0.0f; break; case 'P': northing = 800000.0f; break; case 'Q': northing = 1700000.0f; break; case 'R': northing = 2600000.0f; break; case 'S': northing = 3500000.0f; break; case 'T': northing = 4400000.0f; break; case 'U': northing = 5300000.0f; break; case 'V': northing = 6200000.0f; break; case 'W': northing = 7000000.0f; break; case 'X': northing = 7900000.0f; break; default: northing = -1.0f; } if (northing >= 0.0) { return northing; } else { throw new NumberFormatException("Invalid zone letter: " + zone_letter); } } private static void runTests(String fName, String inType) { LineNumberReader lnr = null; PrintStream pos = null; String record = null; StringBuffer outStr1 = new StringBuffer(); StringBuffer outStr2 = new StringBuffer(); try { /* * File inFile = new File(fName + ".dat"); File outFile = * new File(fName + ".out"); FileInputStream fis = new * FileInputStream(inFile); FileOutputStream fos = new * FileOutputStream(outFile); BufferedInputStream bis = * new BufferedInputStream(fis); */ pos = new PrintStream(new FileOutputStream(new File(fName + ".out"))); lnr = new LineNumberReader(new InputStreamReader(new BufferedInputStream(new FileInputStream(new File(fName))))); if (inType.equalsIgnoreCase("MGRS")) { outStr1.append("MGRS to LatLonPoint\n\tMGRS\t\tLatitude Longitude\n"); outStr2.append("MGRS to UTM\n\tMGRS\t\tZone Easting Northing\n"); } else if (inType.equalsIgnoreCase("UTM")) { outStr1.append("UTM to LatLonPoint\n\tUTM\t\tLatitude Longitude\n"); outStr2.append("UTM to MGRS\n\tUTM\t\tMGRS\n"); } else if (inType.equalsIgnoreCase("LatLon")) { outStr1.append("LatLonPoint to UTM\nLatitude Longitude\t\tZone Easting Northing \n"); outStr2.append("LatLonPoint to MGRS\nLatitude Longitude\t\tMGRS\n"); } while ((record = lnr.readLine()) != null) { if (inType.equalsIgnoreCase("MGRS")) { try { MGRSPoint mgrsp = new MGRSPoint(record); record.trim(); mgrsp.decode(record); outStr1.append(record + " is " + mgrsp.toLatLonPoint() + "\n"); outStr2.append(record + " to UTM: " + mgrsp.zone_number + " " + mgrsp.easting + " " + mgrsp.northing + "\n"); } catch (NumberFormatException nfe) { Debug.error(nfe.getMessage()); } } else if (inType.equalsIgnoreCase("UTM")) { MGRSPoint mgrsp; UTMPoint utmp; float e, n; int z; char zl; String tmp; record.trim(); tmp = record.substring(0, 2); z = Integer.parseInt(tmp); tmp = record.substring(5, 11); e = Float.parseFloat(tmp); tmp = record.substring(12, 19); n = Float.parseFloat(tmp); zl = record.charAt(3); utmp = new UTMPoint(n, e, z, zl); LatLonPoint llp = utmp.toLatLonPoint(); mgrsp = LLtoMGRS(llp); outStr1.append(record + " is " + llp + " back to " + LLtoUTM(llp) + "\n"); outStr2.append(record + " is " + mgrsp + "\n"); } else if (inType.equalsIgnoreCase("LatLon")) { float lat, lon; int index; String tmp; record.trim(); index = record.indexOf("\040"); if (index < 0) { index = record.indexOf("\011"); } tmp = record.substring(0, index); lat = Float.parseFloat(tmp); tmp = record.substring(index); lon = Float.parseFloat(tmp); LatLonPoint llp = new LatLonPoint(lat, lon); // UTMPoint utmp = LLtoUTM(llp); MGRSPoint mgrsp = LLtoMGRS(llp); outStr1.append(record + " to UTM: " + mgrsp.zone_number + " " + mgrsp.easting + " " + mgrsp.northing + "\n"); outStr2.append(record + " -> " + mgrsp.mgrs + "\n"); } } } catch (IOException e) { // catch io errors from FileInputStream or readLine() System.out.println("IO error: " + e.getMessage()); } finally { if (pos != null) { pos.print(outStr1.toString()); pos.print("\n"); pos.print(outStr2.toString()); pos.close(); } // if the file opened okay, make sure we close it if (lnr != null) { try { lnr.close(); } catch (IOException ioe) { } } } } public static void main(String[] argv) { Debug.init(); ArgParser ap = new ArgParser("MGRSPoint"); ap.add("mgrs", "Print Latitude and Longitude for MGRS value", 1); ap.add("latlon", "Print MGRS for Latitude and Longitude values", 2, true); ap.add("sets", "Print the MGRS 100k table"); ap.add("altsets", "Print the MGRS 100k table for the Bessel ellipsoid"); ap.add("rtc", "Run test case, with filename and input data type [MGRS | UTM | LatLon]", 2); if (!ap.parse(argv)) { ap.printUsage(); System.exit(0); } String arg[]; arg = ap.getArgValues("sets"); if (arg != null) { new MGRSPoint().print100kSets(); } arg = ap.getArgValues("altsets"); if (arg != null) { MGRSPoint mgrsp = new MGRSPoint(); mgrsp.setOriginColumnLetters(BESSEL_SET_ORIGIN_COLUMN_LETTERS); mgrsp.setOriginRowLetters(BESSEL_SET_ORIGIN_ROW_LETTERS); mgrsp.print100kSets(); } arg = ap.getArgValues("mgrs"); if (arg != null) { try { MGRSPoint mgrsp = new MGRSPoint(arg[0]); Debug.output(arg[0] + " is " + mgrsp.toLatLonPoint()); } catch (NumberFormatException nfe) { Debug.error(nfe.getMessage()); } } arg = ap.getArgValues("latlon"); if (arg != null) { try { float lat = Float.parseFloat(arg[0]); float lon = Float.parseFloat(arg[1]); LatLonPoint llp = new LatLonPoint(lat, lon); MGRSPoint mgrsp = LLtoMGRS(llp); UTMPoint utmp = LLtoUTM(llp); if (utmp.zone_letter == 'Z') { Debug.output(llp + "to UTM: latitude limit exceeded."); } else { Debug.output(llp + " is " + utmp); } Debug.output(llp + " is " + mgrsp); } catch (NumberFormatException nfe) { Debug.error("The numbers provided: " + argv[0] + ", " + argv[1] + " aren't valid"); } } arg = ap.getArgValues("rtc"); if (arg != null) { runTests(arg[0], arg[1]); } }}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -