📄 rpftochandler.java
字号:
entries[i].coverage.reset(); if (chartSeriesCode == null) { chartSeries = RpfViewAttributes.ANY; } else { chartSeries = chartSeriesCode; } if (chartSeries.equalsIgnoreCase(RpfViewAttributes.ANY) || chartSeries.equalsIgnoreCase(entries[i].info.seriesCode)) { if (entries[i].coverage.setPercentCoverage(ullat, ullon, lrlat, lrlon) > 0f) { coverages.addElement(entries[i].coverage); } } } } /** * Given a coordinate box and a scale, find the entry in the table * of contents file with the right data. Zone is always of the * northern hemisphere, and is transformed to southern inside if * needed. The box will get filled in with the correct * information. The subframe description will have scaling * information for the subframes to be scaled to match the scale. * If proj is null, only exact matches will be found * * NOTE: method getZone() of the CADRG projection is only relevant * (according to OpenMap documentation) when you're viewing a map * type (ONC, etc) at its proper scale (i.e. 1:1mil for ONC). * There was a method in RpfTocHandler that only checked a TOC for * coverage if the TOC zone matched the zone of the projection. * This caused gaps of coverage when viewing the maps at large * scales that were different from their proper scale (e.g. * viewing JNC at 1:10mil). Modified this method so that it * obtains all the possible zones the current map projection could * be in, and compares the TOC zones to that set. * * Note that this now returns a list of coverage entries instead * of just one. * * @param ullat upper left latitude, in decimal degrees * @param ullon upper left longitude, in decimal degrees * @param lrlat lower right latitude, in decimal degrees * @param lrlon lower right longitude, in decimal degrees * @param proj CADRG projection describing map. * @param viewAtts view attributes determine chart selection. * @return a Vector of applicable RpfCoverageBoxes. */ public List getBestCoverageEntry(float ullat, float ullon, float lrlat, float lrlon, CADRG proj, RpfViewAttributes viewAtts) { if (!valid) return null; List coverageEntries = new Vector(); double scaleFactor = 0; double lowerScaleFactorLimit = 1.0; double upperScaleFactorLimit = 1.0; // Good for a preliminary check. It has to start at least as // 4 to have one corner matching. int prevBoundaryHits = 0; if (viewAtts != null) { lowerScaleFactorLimit = (double) (1.0 / viewAtts.imageScaleFactor); upperScaleFactorLimit = (double) viewAtts.imageScaleFactor; } int nscale = 0; int scale = (int) proj.getScale(); RpfTocEntry bestEntry = null; if (DEBUG_RPFTOCDETAIL) { Debug.output("getBestCoverageEntry(): Checking for coverage"); Debug.output(" nw_lat: " + ullat); Debug.output(" se_lat: " + lrlat); Debug.output(" nw_lon: " + ullon); Debug.output(" se_lon: " + lrlon); } int zone = getASCIIZone(ullat, proj.getZone()); char okZones[] = getOkZones(ullat, lrlat, (char) zone); 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 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -