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

📄 dtedframe.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            left = lrlon;        }        if (lrlat > ullat) {            upper = lrlat;            lower = ullat;        }        int[] ret = new int[4];        float ullat_index = (upper - dsi.sw_lat) * 36000F                / uhl.lat_post_interval;        float ullon_index = (left - dsi.sw_lon) * 36000F                / uhl.lon_post_interval;        float lrlat_index = (lower - dsi.sw_lat) * 36000F                / uhl.lat_post_interval;        float lrlon_index = (right - dsi.sw_lon) * 36000F                / uhl.lon_post_interval;        ret[0] = (int) Math.round(ullon_index);        ret[1] = (int) Math.round(lrlat_index);        ret[2] = (int) Math.round(lrlon_index);        ret[3] = (int) Math.round(ullat_index);        if (ret[0] < 0)            ret[0] = 0;        if (ret[0] > uhl.num_lon_lines - 2)            ret[0] = uhl.num_lon_lines - 2;        if (ret[1] < 0)            ret[1] = 0;        if (ret[1] > uhl.num_lat_points - 2)            ret[1] = uhl.num_lat_points - 2;        if (ret[2] < 0)            ret[2] = 0;        if (ret[2] > uhl.num_lon_lines - 2)            ret[2] = uhl.num_lon_lines - 2;        if (ret[3] < 0)            ret[3] = 0;        if (ret[3] > uhl.num_lat_points - 2)            ret[3] = uhl.num_lat_points - 2;        return ret;    }    /**     * Return a two dimensional array of posts between lat lons.     *      * @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 array of elevations in meters. The spacing of the posts     *         depends on the DTED level.     */    public short[][] getElevations(float ullat, float ullon, float lrlat,                                   float lrlon) {        int[] indexes = getIndexesFromLatLons(ullat, ullon, lrlat, lrlon);        return getElevations(indexes[0], indexes[1], indexes[2], indexes[3]);    }    /**     * Return a two dimensional array of posts between lat lons.     * Assumes that the indexes are checked to not exceed their bounds     * as defined in the file. getIndexesFromLatLons() checks this.     *      * @param startx starting index (left) of the greater matrix to     *        make the left side of the returned matrix.     * @param starty starting index (lower) of the greater matrix to     *        make the bottom side of the returned matrix.     * @param endx ending index (right) of the greater matrix to make     *        the left side of the returned matrix.     * @param endy ending index (top) of the greater matrix to make     *        the top side of the returned matrix.     * @return array of elevations in meters. The spacing of the posts     *         depends on the DTED level.     */    public short[][] getElevations(int startx, int starty, int endx, int endy) {        int upper = endy;        int lower = starty;        int right = endx;        int left = startx;        // 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 (startx > endx) {            right = startx;            left = endx;        }        if (starty > endy) {            upper = starty;            lower = endy;        }        short[][] matrix = new short[right - left + 1][upper - lower + 1];        int matrixColumn = 0;        for (int x = left; x <= right; x++) {            if (elevations[x] == null)                readDataRecord(x);            System.arraycopy(elevations[x],                    lower,                    matrix[matrixColumn],                    0,                    (upper - lower + 1));            matrixColumn++;        }        return matrix;    }    // ////////////////    // Internal methods    // ////////////////    /**     * A try at interoplating the corners of the surrounding posts,     * given a lat lon. Called from a function where the data for the     * lon has been read in.     */    private float resolveFourPoints(int ul, int ur, int lr, int ll,                                    float lat_index, float lon_index) {        float top_avg = ((lon_index - new Double(Math.floor(lon_index)).floatValue()) * (float) (ur - ul))                + ul;        float bottom_avg = ((lon_index - new Double(Math.floor(lon_index)).floatValue()) * (float) (lr - ll))                + ll;        float right_avg = ((lat_index - new Double(Math.floor(lat_index)).floatValue()) * (float) (ur - lr))                + lr;        float left_avg = ((lat_index - new Double(Math.floor(lat_index)).floatValue()) * (float) (ul - ll))                / 100.0F + ll;        float lon_avg = ((lat_index - new Double(Math.floor(lat_index)).floatValue()) * (top_avg - bottom_avg))                + bottom_avg;        float lat_avg = ((lon_index - new Double(Math.floor(lon_index)).floatValue()) * (right_avg - left_avg))                + left_avg;        float result = (lon_avg + lat_avg) / 2.0F;        return result;    }    /**     * Reads one longitude line of posts. Assumes that the binFile is     * valid.     *      * @return true if the column of data was successfully read     */    protected boolean readDataRecord(int lon_index) {        try {            if (binFile == null) {                if (!reopen()) {                    return false;                }            }            // Set to beginning of file section, then skip to index            // data            // 12 = 1+3+2+2+4 = counts and checksum            // 2*uhl....size of elevation post space            binFile.seek(UHL_SIZE + DSI_SIZE + ACC_SIZE                    + (lon_index * (12 + (2 * uhl.num_lat_points))));            binFile.read(); // sent byte            binFile.skipBytes(3); // 3 byte data_block_count            binFile.readShort(); // longitude count            binFile.readShort(); // latitude count            // Allocate the rows of the row            elevations[lon_index] = new short[uhl.num_lat_points];            for (int j = 0; j < uhl.num_lat_points; j++) {                elevations[lon_index][j] = binFile.readShort();            }        } catch (IOException e3) {            Debug.error("DTEDFrame.RDR: Error reading file.");            e3.printStackTrace();            elevations[lon_index] = null;            return false;        } catch (FormatException f) {            Debug.error("DTEDFrame.RDR: File IO Format error!");            elevations[lon_index] = null;            return false;        }        return true;    }    /**     * Read all the elevation posts, at one time. Assumes that the     * file is open and ready.     *      * @return true if the elevation columns were read.     */    protected boolean readDataRecords() {        boolean ret = true;        for (int lon_index = 0; lon_index < uhl.num_lon_lines; lon_index++) {            if (readDataRecord(lon_index) == false) {                ret = false;            }        }        return ret;    }    public OMGrid getOMGrid() {        // vResolution decimal degrees per row        double vResolution = (double) dsi.lat_post_interval / 36000.0; // Tenths        // of        // seconds        // between        // data        // rows        // hResolution decimal degrees per column        double hResolution = (double) dsi.lon_post_interval / 36000.0; // Tenths        // of        // seconds        // between        // data        // columns.        if (Debug.debugging("grid")) {            Debug.output("DTEDFrame creating OMGrid with vResolution: "                    + vResolution + ",  hResolution: " + hResolution                    + ", created from:" + "\n\tNE LAT: " + dsi.ne_lat                    + "\n\tSW LAT: " + dsi.sw_lat + "\n\tNE LON: " + dsi.ne_lon                    + "\n\tSW LON: " + dsi.sw_lon + "\n\tlat lines: "                    + dsi.num_lat_lines + "\n\tlon points: "                    + dsi.num_lon_points);        }        OMDTEDGrid omg = new OMDTEDGrid(dsi.lat_origin, dsi.lon_origin, dsi.ne_lat, dsi.ne_lon, (float) vResolution, (float) hResolution, new OMGridData.Short(elevations));        omg.setUnits(Length.METER);        return omg;    }    /**     * If you just want to get an image for the DTEDFrame, then call     * this. One OMRaster for the entire DTEDFrame will be returned,     * with the default rendering parameters (Colored shading) and the     * default colortable. Use the other getOMRaster method if you     * want something different. This method actually calls that other     * method, so read the documentation for that as well.     *      * @param proj EqualArc projection to use to create image.     * @return raster image to display in OpenMap.     */    public OMRaster getOMRaster(EqualArc proj) {        OMGrid grid = getOMGrid();        grid.generate(proj);        SlopeGenerator sg = new SlopeGenerator();        return sg.generateRasterForProjection(grid, proj);    }    public static void main(String args[]) {        Debug.init();        if (args.length < 1) {            System.out.println("DTEDFrame:  Need a path/filename");            System.exit(0);        }        System.out.println("DTEDFrame: " + args[0]);        DTEDFrame df = new DTEDFrame(args[0], true);        if (df.frame_is_valid) {            System.out.println(df.uhl);            System.out.println(df.dsi);            System.out.println(df.acc);            // int startx = 5;            // int starty = 6;            // int endx = 10;            // int endy = 30;            // short[][] e = df.getElevations(startx, starty, endx,            // endy);            // for (int i = e[0].length-1; i >= 0; i--) {            // for (int j = 0; j < e.length; j++) {            // System.out.print(e[j][i] + " ");            // }            // System.out.println("");            // }        }        float lat = df.dsi.lat_origin + .5f;        float lon = df.dsi.lon_origin + .5f;        CADRG crg = new CADRG(new com.bbn.openmap.LatLonPoint(lat, lon), 1500000, 600, 600);        final com.bbn.openmap.omGraphics.OMRaster ras = df.getOMRaster(crg);        java.awt.Frame window = new java.awt.Frame(args[0]) {            public void paint(java.awt.Graphics g) {                if (ras != null) {                    g.translate(-300 + ras.getWidth() / 2, -300                            + ras.getHeight() / 2);                    ras.render(g);                }            }        };        window.addWindowListener(new java.awt.event.WindowAdapter() {            public void windowClosing(java.awt.event.WindowEvent e) {                // need a shutdown event to notify other gui beans and                // then exit.                System.exit(0);            }        });        window.setSize(ras.getWidth(), ras.getHeight());        window.show();        window.repaint();    }}

⌨️ 快捷键说明

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