📄 rpfutil.java
字号:
//**********************************************************************////<copyright>////BBN Technologies, a Verizon Company//10 Moulton Street//Cambridge, MA 02138//(617) 873-8000////Copyright (C) BBNT Solutions LLC. All rights reserved.////</copyright>//**********************************************************************////$Source:///cvs/darwars/ambush/aar/src/com/bbn/ambush/mission/MissionHandler.java,v//$//$RCSfile: RpfUtil.java,v $//$Revision: 1.1.2.1 $//$Date: 2005/08/24 20:19:54 $//$Author: dietrick $////**********************************************************************package com.bbn.openmap.layer.rpf;import java.io.File;import java.io.FileNotFoundException;import java.io.IOException;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import com.bbn.openmap.util.ArgParser;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.FileUtils;/** * The RpfUtil is a program that will allow you to manage RPF data * geographically. You can copy and delete RPF data frames from RPF * data directories, make an A.TOC file for a RPF directory (even * after copying and/or deleting), and you can zip an RPF directory * into an archive if you like. You can limit the commands to only * affect those frames completely inside or outside a specified area, * or for those frames that intersect and are contained by that area * (default). You can also limit the charts affected based on their * map scales, providing a scale and indicating that you only want * those frames that match the scale, do not match the scale, are * greater or less than the scale. Greater than or less than refers to * the scale number of the chart being greater or less than the scale * number provided, NOT whether the resuting scale ratio is greater or * less than. These things are opposite if each other, and we're just * working with the numbers. * <p> * * When you call RpfUtil.setRpfDir, that calls organizeFrames(rpfDir), * which creates a list of the frames affected by the scale and * boundary settings. Then, the operation runs on those frames. * <p> * * It is important that the A.TOC file in the source RPF directory * reflects the current state of the data in that directory. If you * are not sure, run this program with the -maketoc option on that * directory to update it. * * @author dietrick */public class RpfUtil { public final static char SCALE_EQUALS = 'e'; public final static char SCALE_NOTEQUALS = 'n'; public final static char SCALE_GREATERTHAN = 'g'; public final static char SCALE_LESSTHAN = 'l'; public final static float ALL_SCALES = 0f; public final static int BOUNDED = 0; public final static int INSIDE = 1; public final static int OUTSIDE = 2; protected int boundaryLimits = BOUNDED; protected float scale = ALL_SCALES; protected char scaleDelim = SCALE_EQUALS; protected float upperLat = 90f; protected float leftLon = -180; protected float lowerLat = -90f; protected float rightLon = 180f; protected String rpfDir; protected boolean verbose = false; protected List frameList; /** * Create a default RpfUtil considering all data. */ public RpfUtil() {} /** * Create a RpfUtil considering data intersecting the provided * boundary. The RPF data directory still needs to be set. * * @param ulat upper latitude * @param llon left longitude * @param llat lower latitude * @param rlon right longitude */ public RpfUtil(float ulat, float llon, float llat, float rlon) { this(null, ulat, llon, llat, rlon, 0f, SCALE_EQUALS, BOUNDED); } /** * Create a RpfUtil considering data intersecting the provided * boundary, involving the provided RPF directory. * * @param rpfDir the RPF directory to search and consider frames * over. * @param ulat upper latitude * @param llon left longitude * @param llat lower latitude * @param rlon right longitude */ public RpfUtil(String rpfDir, float ulat, float llon, float llat, float rlon) { this(rpfDir, ulat, llon, llat, rlon, 0f, SCALE_EQUALS, BOUNDED); } /** * Full control over the RpfUtil settings. * * @param rpfDir the RPF directory to search and consider frames * over. * @param ulat upper latitude * @param llon left longitude * @param llat lower latitude * @param rlon right longitude * @param scale the scale of the charts to consider. * @param scaleDelimiter character 'g'reater than, 'l'ess than, * 'n'ot equal to, 'e'qual to. e is the default. * @param boundaryLimits INSIDE, OUTSIDE or BOUNDARY */ public RpfUtil(String rpfDir, float ulat, float llon, float llat, float rlon, float scale, char scaleDelimiter, int boundaryLimits) { this.upperLat = ulat; this.lowerLat = llat; this.leftLon = llon; this.rightLon = rlon; this.scale = scale; this.scaleDelim = scaleDelimiter; this.boundaryLimits = boundaryLimits; setRpfDir(rpfDir); } /** * Creates the list of frames to consider, based on settings. This * method does a cursory check of scale settings before moving to * geographical settings. * * @param rpfDir * @return List of relative path names to frames. */ protected List organizeFrames(String rpfDir) { RpfTocHandler toc = new RpfTocHandler(rpfDir); List frameList = new LinkedList(); if (toc.isValid()) { RpfTocEntry[] entries = toc.getEntries(); if (verbose) { Debug.output("Figuring out which frames fit the criteria..."); } for (int i = 0; i < entries.length; i++) { RpfTocEntry entry = entries[i]; double udinterval = (entry.coverage.nw_lat - entry.coverage.se_lat) / entry.vertFrames; double rlinterval = (entry.coverage.se_lon - entry.coverage.nw_lon) / entry.horizFrames; if (scale > 0) { float rectScale = (float) RpfTocHandler.textScaleToLong(entry.scale); if (rectScale == RpfConstants.UK.scale) { if (verbose) { Debug.output(" RpfTocEntry[" + i + "] scale unknown (" + entry.coverage.chartCode + "), skipping"); } continue; } switch (scaleDelim) { case SCALE_EQUALS: if (scale == rectScale) frameList.addAll(getFrameList(entry, rlinterval, udinterval)); break; case SCALE_GREATERTHAN: if (scale >= rectScale) frameList.addAll(getFrameList(entry, rlinterval, udinterval)); break; case SCALE_LESSTHAN: if (scale <= rectScale) frameList.addAll(getFrameList(entry, rlinterval, udinterval)); break; case SCALE_NOTEQUALS: if (scale != rectScale) frameList.addAll(getFrameList(entry, rlinterval, udinterval)); default: break; } // switch } else { frameList.addAll(getFrameList(entry, rlinterval, udinterval)); } } } return frameList; } /** * Middle management for frames for A.TOC entry box. * * @param entry RpfTocEntry to consider. * @param rlinterval right to left decimal degree interval for * entry. * @param udinterval up to down decimal degree interval for entry * @return List of frames that pass current settings. */ protected List getFrameList(RpfTocEntry entry, double rlinterval, double udinterval) { List frameList = new LinkedList(); for (int hor = 0; hor < entry.horizFrames; hor++) { for (int ver = 0; ver < entry.vertFrames; ver++) { RpfFrameEntry frame = entry.frames[ver][hor]; double left = entry.coverage.nw_lon + (rlinterval * hor); double right = left + rlinterval; double up = entry.coverage.nw_lat - (udinterval * ver); double down = up - udinterval; if (frame.exists && frameFitsCriteria(left, right, up, down, rlinterval, udinterval)) { String name = frame.directory + frame.filename; frameList.add(name); if (verbose) { Debug.output(" getFrameList: adding file " + name); } } } } return frameList; } /** * Geographical evaluation of frame file * * @return true if file should be added to the list. */ protected boolean frameFitsCriteria(double left, double right, double up, double down, double rlinterval, double udinterval) { switch (boundaryLimits) { case OUTSIDE: return (left < leftLon && right < leftLon) || (left > rightLon && right > rightLon) || (up < lowerLat && down < lowerLat) || (up > upperLat && down > upperLat); case INSIDE: return (left > leftLon && right > leftLon && left < rightLon && right < rightLon && up > lowerLat && down > lowerLat && up < upperLat && down < upperLat); default: return (((right <= rightLon && left >= leftLon - rlinterval) || (left >= leftLon && right <= rightLon + rlinterval) || (left <= leftLon && right >= rightLon)) && ((up <= upperLat + udinterval && down >= lowerLat) || (down >= lowerLat - udinterval && up <= upperLat) || (up >= upperLat && down <= lowerLat))); } } /** * Copy the frame files currently set on the FrameList to the * provided RPF directory. * * @param toRpfDir * @return true if it works. */ public boolean copy(String toRpfDir) { File toDir = new File(toRpfDir); boolean ret = false; String sourceRpfDir = getRpfDir(); if ((toDir.exists() || toDir.mkdirs()) && frameList != null) { if (verbose) { Debug.output("From " + sourceRpfDir + " to " + toRpfDir + ":"); } for (Iterator it = frameList.iterator(); it.hasNext();) { String relativeFilePath = "/" + (String) it.next(); File fromFile = new File(sourceRpfDir + relativeFilePath); File toFile = new File(toRpfDir + relativeFilePath); File toParent = toFile.getParentFile(); if (!toParent.exists()) { toParent.mkdirs(); } if (verbose) { Debug.output("Copying " + relativeFilePath); } try { FileUtils.copy(fromFile, toFile, 400000); } catch (IOException ioe) { Debug.error("RpfUtil.copy: IOExeption copying files: " + ioe.getMessage()); return false; } } ret = true; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -