rpftochandler.java

来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 1,288 行 · 第 1/4 页

JAVA
1,288
字号
        for (int i = 0; i < numBoundaries; i++) {            RpfTocEntry currentEntry = entries[i];            if (DEBUG_RPFTOCDETAIL) {                Debug.output("********************");                Debug.output("  tochandler: Boundary #" + i);                Debug.output(currentEntry.toString());            }            // Try to get the boundary rectangle with the most            // coverage, so reset the entry for this particular query.            currentEntry.coverage.reset();            // Find the scale of the boundary rectangle            if (currentEntry.info == null                    || currentEntry.info.scale == RpfConstants.Various) {                nscale = (int) textScaleToLong(currentEntry.scale);                currentEntry.info = new RpfProductInfo();                // Reset the RpfProductInfo to the listed parameters                // in the A.TOC file.                currentEntry.info.scale = (float) nscale;                currentEntry.info.scaleString = currentEntry.scale;                currentEntry.coverage.scale = (float) nscale;            } else {                currentEntry.coverage.scale = currentEntry.info.scale;                nscale = (int) currentEntry.info.scale;            }            if (DEBUG_RPFTOCDETAIL) {                Debug.output("getBestCoverageEntry(): Query scale = " + scale                        + " vs. brect scale = " + nscale);            }            // if you want an exact match for scale...            if (viewAtts != null && !viewAtts.scaleImages) {                if (scale == nscale) {                    scaleFactor = 1.0;                } else                    scaleFactor = lowerScaleFactorLimit - 1.0;            } else {                scaleFactor = (double) nscale / (double) scale;            }            String chartSeries;            if (viewAtts == null) {                chartSeries = RpfViewAttributes.ANY;            } else {                chartSeries = viewAtts.chartSeries;            }            if (scaleFactor >= lowerScaleFactorLimit                    && scaleFactor <= upperScaleFactorLimit                    && (chartSeries.equalsIgnoreCase(RpfViewAttributes.ANY) || chartSeries.equalsIgnoreCase(currentEntry.info.seriesCode))) {                if (isOkZone(currentEntry.zone, okZones)) {                    // sets currentEntry.coverage.boundaryHits                    int hits = currentEntry.coverage.setBoundaryHits(ullat,                            ullon,                            lrlat,                            lrlon);                    if (DEBUG_RPFTOCDETAIL) {                        Debug.output("getBestCoverageEntry(): Boundary Hits = "                                + hits);                    }                    if (bestEntry != null) {                        boolean betterScale = false;                        float newScaleDiff = RpfFrameCacheHandler.scaleDifference(proj,                                currentEntry.coverage);                        float bestScaleDiff = RpfFrameCacheHandler.scaleDifference(proj,                                bestEntry.coverage);                        if (newScaleDiff <= bestScaleDiff) {                            betterScale = true;                        }                        if (betterScale                                && (currentEntry.coverage.setPercentCoverage(ullat,                                        ullon,                                        lrlat,                                        lrlon) >= bestEntry.coverage.getPercentCoverage())                                && (hits >= prevBoundaryHits || hits >= 6)) {                            // Add to list if has any hits and is                            // the best possible scale. If new scale                            // difference                            // is strictly better, remove other                            // entries                            if (newScaleDiff < bestScaleDiff) {                                coverageEntries.clear();                            }                            coverageEntries.add(currentEntry);                            bestEntry = currentEntry;                            prevBoundaryHits = hits;                            if (DEBUG_RPFTOC) {                                Debug.output("getBestCoverageEntry(): Found a match in a BR with coverage of "                                        + currentEntry.coverage.getPercentCoverage()                                        + "%.");                            }                        } else if (betterScale                                && currentEntry.coverage.getPercentCoverage() > 0f) {                            if (newScaleDiff < bestScaleDiff) {                                coverageEntries.clear();                            }                            coverageEntries.add(currentEntry);                        }                    } else if (hits > prevBoundaryHits                            && (currentEntry.coverage.setPercentCoverage(ullat,                                    ullon,                                    lrlat,                                    lrlon) > 0f)) {                        bestEntry = currentEntry;                        prevBoundaryHits = hits;                        // Add to list of coverageEntries                        coverageEntries.add(currentEntry);                        if (DEBUG_RPFTOC) {                            Debug.output("getBestCoverageEntry(): Found a match in a BR with coverage of "                                    + currentEntry.coverage.getPercentCoverage()                                    + "%.");                        }                    }                }            }        }        if (DEBUG_RPFTOC) {            if (bestEntry != null) {                Debug.output("getBestCoverageEntry(): found the best");                Debug.output("################");                Debug.output(bestEntry.toString());                Debug.output("Returning the following coverage boxes: ");                for (int i = 0; i < coverageEntries.size(); i++) {                    Debug.output(coverageEntries.get(i).toString());                }            } else {                Debug.output("getBestCoverageEntry(): no box found");            }        }        return coverageEntries;    }    public static char[] getOkZones(float ullat, float lrlat, char zone) {        // allow a maximum of 3 additional zones in either direction        char[] okZones = new char[7];        // add zone from projection        okZones[0] = zone;        // check above        char currentZone = zone;        char backupZone;        int i = 0;        for (; i < 3; i++) {            if (isAboveZone(ullat, currentZone)) {                backupZone = getHigherZone(currentZone);                okZones[i + 1] = backupZone;                currentZone = backupZone;            } else                break;        }        // check below        int k = i;        currentZone = zone;        for (; k < i + 3; k++) {            if (isBelowZone(ullat, currentZone)) {                backupZone = getLowerZone(currentZone);                okZones[k + 1] = backupZone;                currentZone = backupZone;            } else                break;        }        int size = 0;        for (int j = 0; j < okZones.length; j++) {            if (okZones[j] != 0) {                size++;            }        }        char[] returnZones = new char[size];        for (int j = 0; j < size; j++) {            returnZones[j] = okZones[j];        }        return returnZones;    }    public static boolean isOkZone(char zone, char[] okZones) {        boolean ok = false;        for (int i = 0; i < okZones.length; i++) {            if (zone == okZones[i]) {                ok = true;            }        }        return ok;    }    protected static boolean isBelowZone(float lowerLat, char zone) {        float zoneLowerLat = getLowerZoneExtent(zone);        if (lowerLat < zoneLowerLat) {            return true;        } else            return false;    }    protected static boolean isAboveZone(float upperLat, char zone) {        float zoneUpperLat = getUpperZoneExtent(zone);        if (upperLat > zoneUpperLat) {            return true;        } else            return false;    }    public static float getUpperZoneExtent(char zone) {        if (zone >= '0' && zone <= '9') {            int i = zone - 49;            return CADRG_zone_extents[i + 1];        } else {            int i = zone - 65;            if (i == 9)                i--; // Special care for j            return -1 * CADRG_zone_extents[i];        }    }    public static float getLowerZoneExtent(char zone) {        if (zone >= '0' && zone <= '9') {            int i = zone - 49;            return CADRG_zone_extents[i];        } else {            int i = zone - 65;            if (i == 9)                i--; // Special care for J            return -1 * CADRG_zone_extents[i + 1];        }    }    public static char getLowerZone(char zone) {        // if zone = 'J' do nothing        if (zone >= '2' && zone <= '9') {            zone--;        } else if (zone == '1') {            zone = 'A';        } else if (zone >= 'A' && zone < 'H') {            zone++;        } else if (zone == 'H') {            zone = 'J';        }        return zone;    }    public static char getHigherZone(char zone) {        // if zone = '9' do nothing        if (zone >= '1' && zone < '9') {            zone++;        } else if (zone >= 'B' && zone < 'J' || zone >= 'b' && zone < 'j') {            zone--;        } else if (zone == 'J' || zone == 'j') {            zone -= 2;        } else if (zone == 'A' || zone == 'a') {            zone = '1';        }        return zone;    }    /** Return the list of grouped frames. */    public RpfTocEntry[] getEntries() {        return entries;    }    public String getATocFilePath() {        return aTocFilePath;    }    public void setATocFilePath(String tocFilePath) {        aTocFilePath = tocFilePath;    }    public boolean isFullPathsInATOC() {        return fullPathsInATOC;    }    public void setFullPathsInATOC(boolean fullPathsInATOC) {        this.fullPathsInATOC = fullPathsInATOC;    }    public static void main(String[] args) {        if (args.length != 1) {            Debug.output("Usage: java RpfTocHandler <path to RPF directory>");            return;        }        Debug.init(System.getProperties());        RpfTocHandler toc = new RpfTocHandler();        if (!toc.loadFile(args[0]))            Debug.output("RpfTocHandler: NOT read sucessfully!");        else {            RpfTocEntry[] e = toc.getEntries();            Debug.output("For A.TOC: " + args[0]);            for (int i = 0; i < e.length; i++)                Debug.output(e[i].toString());        }        System.exit(0);    }}

⌨️ 快捷键说明

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