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

📄 asrpdirectory.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        // Get image data.        if (tsi != null) {            int index = y * numHorBlocks_N + x;            // Check for not blowing the list end...            if (index >= tsi.size()) {                return null;            }            // Subtracting one because the values look like they start            // with 1.            int blockOffset = ((DDFSubfield) tsi.get(index)).intValue() - 1;            if (Debug.debugging("asrp")) {                Debug.output("ASRPDirectory.getBlock: index of (" + x + ", "                        + y + ") is " + blockOffset);            }            if (blockOffset < 0) {                // Can't have a negative offset...                if (Debug.debugging("asrp")) {                    Debug.output("     skipping...");                }                return null;            }            DDFModule mod = img.getInfo();            mod.seek(tileDataOffset + blockOffset);            int byteCount = 0; // Which data byte is being set            int numBlockPixels = numHorPixels_Q * numVerPixels_P;            byte[] data = new byte[numBlockPixels]; // image byte data            int rowCount = 0; // the per row count, should equal 128 (                              // numHorPixels_Q) at the end of every                              // row            int cpc = 0; // current pixel count for file pointer            int cpv = 0; // current pixel value for file pointer            while (byteCount < numBlockPixels) {                switch (pixelCountBits) {                case 8:                    cpc = mod.read();                    break;                case 4:                    cpc = mod.read() >> 4;                    // need to back pointer up 4 bits before reading                    // cpv??                    Debug.output("CAUTION:  4 bit count");                    break;                default:                    cpc = 1;                }                cpv = mod.read();                // OK, cpv has value, cpc says how many pixels that                // goes in.                try {                    for (int c = 0; c < cpc; c++) {                        rowCount++;                        if (colors != null && cpv > colors.length) {                            if (Debug.debugging("asrpdetail")) {                                Debug.output("Got value that is too big for colortable");                            }                        }                        data[byteCount + c] = (byte) cpv;                    }                } catch (ArrayIndexOutOfBoundsException aioobe) {                    if (Debug.debugging("asrp")) {                        Debug.output("ASRPDirectory.getBlock(): bad index for setting byte value: "                                + aioobe.getMessage());                    }                    // This try/catch block is really for the data[]                    // array indexing.                    // if byteCount + x was greater than                    // numBlockPixels,                    // we should be at the end of the image bytes, so                    // we                    // shouldn't have to worry about rowCount not                    // being                    // properly updated.                }                byteCount += cpc;                if (rowCount == numHorPixels_Q) {                    rowCount = 0;                }            }            if (Debug.debugging("asrpdetail")) {                Debug.output("ASRPDirectory creating image covering (" + ullat                        + ", " + ullon + "), (" + lrlat + ", " + lrlon + ")");            }            return new OMScalingRaster(ullat, ullon, lrlat, lrlon, numHorPixels_Q, numVerPixels_P, data, getColors(), 255);        }        return null;    }    /**     * Get the colors from the QAL file.     */    protected Color[] getColors() {        if (colors == null) {            DDFField col = qal.getField(QualityFile.COLOUR_CODE_ID);            List reds = col.getSubfields("NSR");            List greens = col.getSubfields("NSG");            List blues = col.getSubfields("NSB");            int numColors = reds.size();            colors = new Color[numColors];            for (int count = 0; count < numColors; count++) {                int red = ((DDFSubfield) reds.get(count)).intValue();                int green = ((DDFSubfield) greens.get(count)).intValue();                int blue = ((DDFSubfield) blues.get(count)).intValue();                //                 Debug.output("Created color " + count + " with " +                // red + ", " + green + ", " + blue);                // The zero color is supposed to tbe null color, and                // clear. Doesn't seem to be working.                colors[count] = new Color(red, green, blue, (count == 0 ? 0                        : 255));            }        }        return colors;    }    /**     * Read in the attribute information about the data.     *      * @param dirPath path to the ASRP directory.     * @param root name of all of the files, usually the same as the     *        ASRP directory itself.     * @param DD the occurance number, usually '01' of the files.     */    protected void initialize(String dirPath, String root, String DD)            throws IOException {        String rootPath = dirPath + "/" + root + DD + ".";        gen = new GeneralInformationFile(rootPath + GEN_NAME);        ger = new GeoReferenceFile(rootPath + GER_NAME);        qal = new QualityFile(rootPath + QAL_NAME);        sou = new SourceFile(rootPath + SOURCE_NAME);        img = new RasterGeoDataFile(rootPath + IMAGE_NAME);        DDFField sprInfo = gen.getField(GeneralInformationFile.DATA_SET_PARAMETERS);        numHorBlocks_N = sprInfo.getSubfield("NFC").intValue();        numVerBlocks_M = sprInfo.getSubfield("NFL").intValue();        numHorPixels_Q = sprInfo.getSubfield("PNC").intValue();        numVerPixels_P = sprInfo.getSubfield("PNL").intValue();        pixelCountBits = sprInfo.getSubfield("PCB").intValue();        pixelValueBits = sprInfo.getSubfield("PVB").intValue();        //assume there is a tile index map        DDFField genInfo = gen.getField(GeneralInformationFile.GENERAL_INFORMATION);        swo = genInfo.getSubfield("SWO").floatValue() / 3600f;        neo = genInfo.getSubfield("NEO").floatValue() / 3600f;        nea = genInfo.getSubfield("NEA").floatValue() / 3600f;        swa = genInfo.getSubfield("SWA").floatValue() / 3600f;        lso = genInfo.getSubfield("LSO").floatValue() / 3600f;        pso = genInfo.getSubfield("PSO").floatValue() / 3600f;        arv = genInfo.getSubfield("ARV").intValue();        brv = genInfo.getSubfield("BRV").intValue();        DDFField timInfo = gen.getField(GeneralInformationFile.TILE_INDEX_MAP);        tsi = timInfo.getSubfields("TSI");        DDFField pixelInfo = img.getField(RasterGeoDataFile.PIXEL);        // Finding this out lets you use the tile index map to access        // pixel data. This offset points to the start of the tile        // data.        tileDataOffset = pixelInfo.getHeaderOffset()                + pixelInfo.getDataPosition();        degPerHorBlock = 360f / (float) arv * (float) numHorPixels_Q;        degPerVerBlock = 360f / (float) brv * (float) numVerPixels_P;        if (Debug.debugging("asrp")) {            Debug.output("For " + rootPath + "\n\thave blocks ("                    + numHorBlocks_N + ", " + numVerBlocks_M                    + ")\n\twith pixels (" + numHorPixels_Q + ", "                    + numVerPixels_P + ")");            Debug.output("\tCoverage from (" + nea + ", " + swo + ") to ("                    + swa + ", " + neo + ")");            Debug.output("\tPadded coverage starting at (" + pso + ", " + lso                    + ")");            Debug.output("\tNumber of pixels 360 e-w (" + arv + ") , n-s ("                    + brv + ")");            Debug.output("\tdegrees per horizontal block: " + degPerHorBlock                    + ", vertical: " + degPerVerBlock);            Debug.output("\tImage Data made up of count bits: "                    + pixelCountBits + ", value bits: " + pixelValueBits);            if (Debug.debugging("asrpdetail")) {                Debug.output("Checking...");                float latdiff = nea - swa;                float londiff = neo - swo;                float horPixels = arv * (londiff / 360f);                float verPixels = brv * (latdiff / 360f);                Debug.output("\tCalculating " + (horPixels / numHorPixels_Q)                        + " hor blocks");                Debug.output("\tCalculating " + (verPixels / numVerPixels_P)                        + " hor blocks");                Debug.output("\tCalculating "                        + (lso + degPerHorBlock * numHorBlocks_N)                        + " end latitude");                Debug.output("\tCalculating "                        + (pso - degPerVerBlock * numVerBlocks_M)                        + " end latitude");            }        }        getColors();        gen.close();        ger.close();        qal.close();        sou.close();        img.close();    }    /**     * A private class to store cached images.     */    private static class ASRPBlockCacheObject extends CacheObject {        /**         * @param id passed to superclass         * @param obj passed to superclass         */        public ASRPBlockCacheObject(String id, OMGraphic obj) {            super(id, obj);        }        /**         * Calls dispose() on the contained frame, to make it eligible         * for garbage collection.         */        public void finalize() {}    }    /**     * Load a block image into the cache, based on the relative     * coordintes of the block as a key.     *      * @param xAndY String of form 'x,y' identifying the relative location     *        of the subframe image.     * @return Block image, hidden as a CacheObject.     */    public CacheObject load(String xAndY) {        if (xAndY != null) {            int commaIndex = xAndY.indexOf(',');            int x = Integer.parseInt(xAndY.substring(0, commaIndex));            int y = Integer.parseInt(xAndY.substring(commaIndex + 1));            if (Debug.debugging("asrpdetail")) {                Debug.output("Getting tiled image " + x + ", " + y + " (from "                        + xAndY + ")");            }            try {                OMGraphic block = getBlock(x, y);                if (block != null) {                    return new ASRPBlockCacheObject(xAndY.intern(), block);                }            } catch (IOException ioe) {                Debug.error("ASRPDirectory caught exception creating tiled image for "                        + xAndY);            }        }        return null;    }    public static void main(String[] argv) {        Debug.init();        if (argv.length < 1) {            Debug.output("Usage: ASRPDirectory dir_pathname");        } else {            new ASRPDirectory(argv[0]);        }        System.exit(0);    }}

⌨️ 快捷键说明

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