⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mgrspoint.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
// **********************************************************************//// <copyright>//// BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000//// Copyright (C) BBNT Solutions LLC. All rights reserved.//// </copyright>// **********************************************************************//// $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/proj/coords/MGRSPoint.java,v $// $RCSfile: MGRSPoint.java,v $// $Revision: 1.5.2.8 $// $Date: 2005/10/24 14:41:17 $// $Author: dietrick $//// **********************************************************************package com.bbn.openmap.proj.coords;import java.io.BufferedInputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStreamReader;import java.io.LineNumberReader;import java.io.PrintStream;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.proj.Ellipsoid;import com.bbn.openmap.util.ArgParser;import com.bbn.openmap.util.Debug;/** * A class representing a MGRS coordinate that has the ability to * provide the decimal degree lat/lon equivalent, as well as the UTM * equivalent. This class does not do checks to see if the MGRS * coordiantes provided actually make sense. It assumes that the * values are valid. */public class MGRSPoint extends ZonedUTMPoint {    /**     * UTM zones are grouped, and assigned to one of a group of 6     * sets.     */    protected final static int NUM_100K_SETS = 6;    /**     * The column letters (for easting) of the lower left value, per     * set.     */    public final static int[] SET_ORIGIN_COLUMN_LETTERS = { 'A', 'J', 'S', 'A',            'J', 'S' };    /**     * The row letters (for northing) of the lower left value, per     * set.     */    public final static int[] SET_ORIGIN_ROW_LETTERS = { 'A', 'F', 'A', 'F',            'A', 'F' };    /**     * The column letters (for easting) of the lower left value, per     * set,, for Bessel Ellipsoid.     */    public final static int[] BESSEL_SET_ORIGIN_COLUMN_LETTERS = { 'A', 'J',            'S', 'A', 'J', 'S' };    /**     * The row letters (for northing) of the lower left value, per     * set, for Bessel Ellipsoid.     */    public final static int[] BESSEL_SET_ORIGIN_ROW_LETTERS = { 'L', 'R', 'L',            'R', 'L', 'R' };    public final static int SET_NORTHING_ROLLOVER = 20000000;    /**     * Use 5 digits for northing and easting values, for 1 meter     * accuracy of coordinate.     */    public final static int ACCURACY_1_METER = 5;    /**     * Use 4 digits for northing and easting values, for 10 meter     * accuracy of coordinate.     */    public final static int ACCURACY_10_METER = 4;    /**     * Use 3 digits for northing and easting values, for 100 meter     * accuracy of coordinate.     */    public final static int ACCURACY_100_METER = 3;    /**     * Use 2 digits for northing and easting values, for 1000 meter     * accuracy of coordinate.     */    public final static int ACCURACY_1000_METER = 2;    /**     * Use 1 digits for northing and easting values, for 10000 meter     * accuracy of coordinate.     */    public final static int ACCURACY_10000_METER = 1;    /** The set origin column letters to use. */    protected int[] originColumnLetters = SET_ORIGIN_COLUMN_LETTERS;    /** The set origin row letters to use. */    protected int[] originRowLetters = SET_ORIGIN_ROW_LETTERS;    public final static int A = 'A';    public final static int I = 'I';    public final static int O = 'O';    public final static int V = 'V';    public final static int Z = 'Z';    protected boolean DEBUG = false;    /** The String holding the MGRS coordinate value. */    protected String mgrs;    /**     * Controls the number of digits that the MGRS coordinate will     * have, which directly affects the accuracy of the coordinate.     * Default is ACCURACY_1_METER, which indicates that MGRS     * coordinates will have 10 digits (5 easting, 5 northing) after     * the 100k two letter code, indicating 1 meter resolution.     */    protected int accuracy = ACCURACY_1_METER;    /**     * Point to create if you are going to use the static methods to     * fill the values in.     */    public MGRSPoint() {        DEBUG = Debug.debugging("mgrs");    }    /**     * Constructs a new MGRS instance from a MGRS String.     */    public MGRSPoint(String mgrsString) {        this();        setMGRS(mgrsString);    }    /**     * Contructs a new MGRSPoint instance from values in another     * MGRSPoint.     */    public MGRSPoint(MGRSPoint point) {        this();        mgrs = point.mgrs;        northing = point.northing;        easting = point.easting;        zone_number = point.zone_number;        zone_letter = point.zone_letter;        accuracy = point.accuracy;    }    /**     * Create a MGRSPoint from UTM values;     */    public MGRSPoint(float northing, float easting, int zoneNumber,            char zoneLetter) {        super(northing, easting, zoneNumber, zoneLetter);    }    /**     * Contruct a MGRSPoint from a LatLonPoint, assuming a WGS_84     * ellipsoid.     */    public MGRSPoint(LatLonPoint llpoint) {        this(llpoint, Ellipsoid.WGS_84);    }    /**     * Construct a MGRSPoint from a LatLonPoint and a particular     * ellipsoid.     */    public MGRSPoint(LatLonPoint llpoint, Ellipsoid ellip) {        this();        LLtoMGRS(llpoint, ellip, this);    }    /**     * Set the MGRS value for this Point. Will be decoded, and the UTM     * values figured out. You can call toLatLonPoint() to translate     * it to lat/lon decimal degrees.     */    public void setMGRS(String mgrsString) {        try {            mgrs = mgrsString.toUpperCase(); // Just to make sure.            decode(mgrs);        } catch (StringIndexOutOfBoundsException sioobe) {            throw new NumberFormatException("MGRSPoint has bad string: "                    + mgrsString);        } catch (NullPointerException npe) {            // Blow off        }    }    /**     * Get the MGRS string value - the honkin' coordinate value.     */    public String getMGRS() {        if (mgrs == null) {            resolve();        }        return mgrs;    }    /**     * Convert this MGRSPoint to a LatLonPoint, and assume a WGS_84     * ellisoid.     */    public LatLonPoint toLatLonPoint() {        return toLatLonPoint(Ellipsoid.WGS_84, new LatLonPoint());    }    /**     * Convert this MGRSPoint to a LatLonPoint, and use the given     * ellipsoid.     */    public LatLonPoint toLatLonPoint(Ellipsoid ellip) {        return toLatLonPoint(ellip, new LatLonPoint());    }    /**     * Fill in the given LatLonPoint with the converted values of this     * MGRSPoint, and use the given ellipsoid.     */    public LatLonPoint toLatLonPoint(Ellipsoid ellip, LatLonPoint llpoint) {        return MGRStoLL(this, ellip, llpoint);    }    /**     * Returns a string representation of the object.     *      * @return String representation     */    public String toString() {        return "MGRSPoint[" + mgrs + "]";    }    /**     * Create a LatLonPoint from a MGRSPoint.     *      * @param mgrsp to convert.     * @param ellip Ellipsoid for earth model.     * @param llp a LatLonPoint to fill in values for. If null, a new     *        LatLonPoint will be returned. If not null, the new     *        values will be set in this object, and it will be     *        returned.     * @return LatLonPoint with values converted from MGRS coordinate.     */    public static LatLonPoint MGRStoLL(MGRSPoint mgrsp, Ellipsoid ellip,                                       LatLonPoint llp) {        // return UTMtoLL(mgrsp, ellip, llp);        return UTMtoLL(ellip,                mgrsp.northing,                mgrsp.easting,                mgrsp.zone_number,                MGRSPoint.MGRSZoneToUTMZone(mgrsp.zone_letter),                llp);    }    /**     * Create a LatLonPoint from a MGRSPoint.     *      * @param mgrsp to convert.     * @param ellip Ellipsoid for earth model.     * @param llp a LatLonPoint to fill in values for. If null, a new     *        LatLonPoint will be returned. If not null, the new     *        values will be set in this object, and it will be     *        returned.     * @return LatLonPoint with values converted from MGRS coordinate.     */    public static LatLonPoint MGRStoLL(Ellipsoid ellip, float northing,                                       float easting, int zoneNumber,                                       char zoneLetter, LatLonPoint llp) {        // return UTMtoLL(mgrsp, ellip, llp);        return UTMtoLL(ellip,                northing,                easting,                zoneNumber,                MGRSPoint.MGRSZoneToUTMZone(zoneLetter),                llp);    }    /**     * Converts a LatLonPoint to a MGRS Point, assuming the WGS_84     * ellipsoid.     *      * @return MGRSPoint, or null if something bad happened.     */    public static MGRSPoint LLtoMGRS(LatLonPoint llpoint) {        return LLtoMGRS(llpoint, Ellipsoid.WGS_84, new MGRSPoint());    }    /**     * Converts a LatLonPoint to a MGRS Point.     *      * @param llpoint the LatLonPoint to convert.     * @param mgrsp a MGRSPoint to put the results in. If it's null, a     *        MGRSPoint will be allocated.     * @return MGRSPoint, or null if something bad happened. If a     *         MGRSPoint was passed in, it will also be returned on a     *         successful conversion.     */    public static MGRSPoint LLtoMGRS(LatLonPoint llpoint, MGRSPoint mgrsp) {        return LLtoMGRS(llpoint, Ellipsoid.WGS_84, mgrsp);    }    /**     * Create a MGRSPoint from a LatLonPoint.     *      * @param llp LatLonPoint to convert.     * @param ellip Ellipsoid for earth model.     * @param mgrsp a MGRSPoint to fill in values for. If null, a new     *        MGRSPoint will be returned. If not null, the new values     *        will be set in this object, and it will be returned.     * @return MGRSPoint with values converted from lat/lon.     */    public static MGRSPoint LLtoMGRS(LatLonPoint llp, Ellipsoid ellip,                                     MGRSPoint mgrsp) {        mgrsp = (MGRSPoint) LLtoUTM(llp, ellip, mgrsp);        mgrsp.resolve();        return mgrsp;    }    /**     * Convert MGRS zone letter to UTM zone letter, N or S.     *      * @param mgrsZone     * @return N of given zone is equal or larger than N, S otherwise.     */    public static char MGRSZoneToUTMZone(char mgrsZone) {        if (Character.toUpperCase(mgrsZone) >= 'N') {            return 'N';        } else {            return 'S';        }    }    /**     * Method that provides a check for MGRS zone letters. Returns an     * uppercase version of any valid letter passed in.     */    protected char checkZone(char zone) {        zone = Character.toUpperCase(zone);        if (zone <= 'A' || zone == 'B' || zone == 'Y' || zone >= 'Z'                || zone == 'I' || zone == 'O') {            throw new NumberFormatException("Invalid MGRSPoint zone letter: "                    + zone);        }        return zone;    }    /**     * Set the number of digits to use for easting and northing     * numbers in the mgrs string, which reflects the accuracy of the     * corrdinate. From 5 (1 meter) to 1 (10,000 meter).     */    public void setAccuracy(int value) {        accuracy = value;        mgrs = null;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -