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

📄 dtedframe.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/layer/dted/DTEDFrame.java,v $// $RCSfile: DTEDFrame.java,v $// $Revision: 1.3.2.3 $// $Date: 2005/08/09 18:10:43 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.dted;import java.io.FileNotFoundException;import java.io.IOException;import com.bbn.openmap.io.BinaryBufferedFile;import com.bbn.openmap.io.BinaryFile;import com.bbn.openmap.io.Closable;import com.bbn.openmap.io.FormatException;import com.bbn.openmap.omGraphics.OMRaster;import com.bbn.openmap.omGraphics.OMRasterObject;import com.bbn.openmap.proj.CADRG;import com.bbn.openmap.proj.EqualArc;import com.bbn.openmap.util.Debug;/** * The DTEDFrame is the representation of the DTED (Digital Terrain * Elevation Data) data from a single dted data file. It keeps track * of all the attribute information of it's data, and also maintains * an array of images (DTEDFrameSubframe) that represent views of the * elevation posts. */public class DTEDFrame implements Closable {    public final static int UHL_SIZE = 80;    public final static int DSI_SIZE = 648;    public final static int ACC_SIZE = 2700;    public final static int ACC_SR_SIZE = 284;    /** The binary buffered file to read the data from the file. */    protected BinaryFile binFile;    /** The path to the frame, including the frame name. */    protected String path;    /**     * The array of elevation posts. Note: the 0 index of the array in     * both directions is in the lower left corner of the matrix. As     * you increase indexes in both dimensions, you go up-right.     */    protected short[][] elevations; // elevation posts    /** Data set indentification section of the file. */    public DTEDFrameDSI dsi;    /** User header label section of the file. */    public DTEDFrameUHL uhl;    /** The colortable used to create the images. */    public DTEDFrameColorTable colorTable;    /** The subframe presentation attributes. */    public DTEDFrameSubframeInfo subframeInfo; // master    /** Validity flag for the quality of the data file. */    public boolean frame_is_valid = false;    /**     * The frame image is divided into 200x200 pixel subframes, with a     * leftover frame at the end. This is how many horizontal     * subframes there are.     */    public int number_horiz_subframes;    /**     * The frame image is divided into 200x200 pixel subframes, with a     * leftover frame at the end. This is how many vertical subframes     * there are.     */    public int number_vert_subframes;    /** The image array for the subframes. */    public DTEDFrameSubframe subframes[][];    //////////////////    // Administrative methods    //////////////////    /**     * Simplest constructor.     *      * @param filePath complete path to the DTED frame.     */    public DTEDFrame(String filePath) {        this(filePath, null, null, false);    }    /**     * Constructor with colortable and presentation information.     *      * @param filePath complete path to the DTED frame.     * @param cTable the colortable to use for the images.     * @param info presentation parameters.     */    public DTEDFrame(String filePath, DTEDFrameColorTable cTable,            DTEDFrameSubframeInfo info) {        this(filePath, cTable, info, false);    }    /**     * Constructor with colortable and presentation information.     *      * @param filePath complete path to the DTED frame.     * @param readWholeFile If true, all of the elevation data will be     *        read at load time. If false, elevation post data will be     *        read in per longitude column depending on the need.     *        False is recommended for DTEd level 1 and 2.     */    public DTEDFrame(String filePath, boolean readWholeFile) {        this(filePath, null, null, readWholeFile);    }    /**     * Constructor with colortable and presentation information.     *      * @param filePath complete path to the DTED frame.     * @param cTable the colortable to use for the images.     * @param info presentation parameters.     * @param readWholeFile If true, all of the elevation data will be     *        read at load time. If false, elevation post data will be     *        read in per longitude column depending on the need.     *        False is recommended for DTED level 1 and 2.     */    public DTEDFrame(String filePath, DTEDFrameColorTable cTable,            DTEDFrameSubframeInfo info, boolean readWholeFile) {        try {            binFile = new BinaryBufferedFile(filePath);            read(binFile, readWholeFile);            if (readWholeFile)                close(true);            else                BinaryFile.addClosable(this);        } catch (FileNotFoundException e) {            Debug.error("DTEDFrame: file " + filePath + " not found");        } catch (java.io.IOException e) {            Debug.error("DTEDFrame: File IO Error!\n" + e.toString());        }        colorTable = cTable;        subframeInfo = info;        path = filePath;    }    public void setColorTable(DTEDFrameColorTable c_Table) {        colorTable = c_Table;    }    public DTEDFrameColorTable getColorTable() {        return colorTable;    }    /**     * Reads the DTED frame file. Assumes that the File f is     * valid/exists.     *      * @param binFile the binary buffere file opened on the DTED frame     *        file     * @param readWholeFile flag controlling whether all the row data     *        is read at this time. Otherwise, the rows are read as     *        needed.     */    protected void read(BinaryFile binFile, boolean readWholeFile) {        binFile.byteOrder(true); //boolean msbfirst        dsi = new DTEDFrameDSI(binFile);        uhl = new DTEDFrameUHL(binFile);        //  Allocate just the columns now - we'll do the rows as        // needed...        elevations = new short[uhl.num_lon_lines][];        if (readWholeFile)            read_data_records();        frame_is_valid = true;    }    /**     * This must get called to break a reference cycle that prevents     * the garbage collection of frames.     */    public void dispose() {        //System.out.println("DTED Frame Disposed " + me);        this.close(true);        BinaryFile.removeClosable(this);    }    //     public void finalize() {    //         System.out.println("DTED Frame Finalized!" + me);    //     }    /**     * Part of the Closable interface. Closes the BinaryFile pointer,     * because someone else needs another file open, and the system     * needs a file pointer. Sets the binFile variable to null.     */    public boolean close(boolean done) {        try {            binFile.close();            binFile = null;            return true;        } catch (java.io.IOException e) {            Debug.error("DTEDFrame close(): File IO Error!\n" + e.toString());            return false;        }    }    /**     * If the BinaryBufferedFile was closed, this method attempts to     * reopen it.     *      * @return true if the opening was successful.     */    protected boolean reopen() {        try {            binFile = new BinaryBufferedFile(path);            //          binFile = new BinaryFile(path);            return true;        } catch (FileNotFoundException e) {            Debug.error("DTEDFrame reopen(): file " + path + " not found");            return false;        } catch (java.io.IOException e) {            Debug.error("DTEDFrame close(): File IO Error!\n" + e.toString());            return false;        }    }    //////////////////    // These functions can be called from the outside,    // as queries about the data    //////////////////    /**     * The elevation at the closest SW post to the given lat/lon. This     * is just a go-to-the-closest-post solution.     *      * @param lat latitude in decimal degrees.     * @param lon longitude in decimal degrees.     * @return elevation at lat/lon in meters.     */    public int elevationAt(float lat, float lon) {        if (frame_is_valid == true) {            if (lat >= dsi.sw_lat && lat <= dsi.ne_lat && lon >= dsi.sw_lon                    && lon <= dsi.ne_lon) {                // lat/lon_post_intervals are *10 too big -                // extra 0 in 36000 to counteract                int lat_index = Math.round((lat - dsi.sw_lat) * 36000                        / uhl.lat_post_interval);                int lon_index = Math.round((lon - dsi.sw_lon) * 36000                        / uhl.lon_post_interval);                if (elevations[lon_index] == null)                    read_data_record(lon_index);                return (int) elevations[lon_index][lat_index];            }        }        return -32767; // Considered a null elevation value    }    /**     * Interpolated elevation at a given lat/lon - should be more     * precise than elevationAt(), but that depends on the resolution     * of the data.     *      * @param lat latitude in decimal degrees.     * @param lon longitude in decimal degrees.     * @return elevation at lat/lon in meters.     */    public int interpElevationAt(float lat, float lon) {        if (frame_is_valid == true) {            if (lat >= dsi.sw_lat && lat <= dsi.ne_lat && lon >= dsi.sw_lon                    && lon <= dsi.ne_lon) {                // lat/lon_post_intervals are *10 too big -                // extra 0 in 36000 to counteract                float lat_index = (lat - dsi.sw_lat) * 36000F                        / uhl.lat_post_interval;                float lon_index = (lon - dsi.sw_lon) * 36000F                        / uhl.lon_post_interval;                int lflon_index = (int) Math.floor(lon_index);                int lclon_index = (int) Math.ceil(lon_index);                /*int lflat_index = (int) Math.floor(lat_index);*/                int lclat_index = (int) Math.ceil(lat_index);                if (elevations[lflon_index] == null)                    read_data_record(lflon_index);                if (elevations[lclon_index] == null)                    read_data_record(lclon_index);                //////////////////////////////////////////////////////                // Print out grid of 20x20 elevations with                // the "asked for" point being in the middle                //          System.out.println("***Elevation Map***");                //          for(int l = lclat_index + 5; l > lflat_index - 5;                // l--) {                //              System.out.println();                //              for(int k = lflon_index - 5; k < lclon_index + 5;                // k++) {                //                  if (elevations[k]==null) read_data_record(k);                //                  System.out.print(elevations[k][l] + " ");                //              }                //          }                //          System.out.println();System.out.println();                //////////////////////////////////////////////////////                int ul = elevations[lflon_index][lclat_index];                int ur = elevations[lclon_index][lclat_index];                int ll = elevations[lflon_index][lclat_index];                int lr = elevations[lclon_index][lclat_index];                float answer = resolve_four_points(ul,                        ur,                        lr,                        ll,                        lat_index,                        lon_index);                return Math.round(answer);            }        }        return -32767; // Considered a null elevation value    }    /**     * Return an index of ints representing the starting x, y and     * ending x, y of elevation posts given a lat lon box. It does     * check to make sure that the upper lat is larger than the lower,     * and left lon is less than the right.     *      * @param ullat upper latitude in decimal degrees.     * @param ullon left longitude in decimal degrees.     * @param lrlat lower latitude in decimal degrees.     * @param lrlon right longitude in decimal degrees.     * @return int[4] array of start x, start y, end x, and end y.     */    public int[] getIndexesFromLatLons(float ullat, float ullon, float lrlat,                                       float lrlon) {        float upper = ullat;        float lower = lrlat;        float right = lrlon;        float left = ullon;        // Since matrix indexes depend on these being in the right        // order, we'll double check and flip values, just to make        // sure lower is lower, and higher is higher.        if (ullon > lrlon) {            right = ullon;            left = lrlon;        }        if (lrlat > ullat) {            upper = lrlat;            lower = ullat;

⌨️ 快捷键说明

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