📄 dtedcoveragemanager.java
字号:
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/layer/dted/DTEDCoverageManager.java,v $// $RCSfile: DTEDCoverageManager.java,v $// $Revision: 1.3.2.2 $// $Date: 2004/10/14 18:27:04 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.dted;/* Java Core */import java.awt.Color;import java.awt.Paint;import java.io.BufferedInputStream;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.net.URL;import java.net.MalformedURLException;/* OpenMap */import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.event.ProgressEvent;import com.bbn.openmap.event.ProgressListener;import com.bbn.openmap.event.ProgressSupport;import com.bbn.openmap.io.BinaryBufferedFile;import com.bbn.openmap.io.BinaryFile;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.omGraphics.OMRect;import com.bbn.openmap.proj.Cylindrical;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;/** * A DTEDCoverageManager knows how to look at DTED data and figure out * what coverage is available. When it is constructed, it needs to * know where the data is located, and where it can look for a * coverage summary file. If a coverage summary file is not available, * it will create one after looking at the data. Using the file is * soooo much faster. The coverage manager also takes a URL of a * coverage file, but assumes that the file is there. If it isn't, * then it falls back on it's behavior of looking for a local summary * file, and then to the data itself, to come up with coverage. */public class DTEDCoverageManager { /** The default line color for level 0. */ public final static String defaultLevel0ColorString = "CE4F3F"; // redish /** The default line color for level 1. */ public final static String defaultLevel1ColorString = "339159"; // greenish /** The default line color for level 2. */ public final static String defaultLevel2ColorString = "0C75D3"; // bluish /** The color to outline the shapes for level 0. */ protected Paint level0Color = new Color(Integer.parseInt(defaultLevel0ColorString, 16)); /** The color to outline the shapes for level 1. */ protected Paint level1Color = new Color(Integer.parseInt(defaultLevel1ColorString, 16)); /** The color to outline the shapes for level 2. */ protected Paint level2Color = new Color(Integer.parseInt(defaultLevel2ColorString, 16)); /** * A setting for how transparent to make the images. The default * is 255, which is totally opaque. */ protected int opaqueness = 255; /** Flag to fill the coverage rectangles. */ protected boolean fillRects = false; /** The array of coverage for level 0 data. */ protected boolean[][] level0Frames = null; /** The array of coverage for level 1 data. */ protected boolean[][] level1Frames = null; /** The array of coverage for level 2 data. */ protected boolean[][] level2Frames = null; protected ProgressSupport progressSupport; public DTEDCoverageManager(String[] paths, String[] paths2, String coverageURL, String coverageFile) { progressSupport = new ProgressSupport(this); if (!readCoverageFile(coverageURL, coverageFile)) { // Swing issues with threading, this is trouble. // ProgressListenerGauge plg = new // ProgressListenerGauge("Creating DTED Coverage File"); // addProgressListener(plg); fireProgressUpdate(ProgressEvent.START, "Building DTED Coverage file...", 0, 100); level0Frames = new boolean[180][360]; level1Frames = new boolean[180][360]; level2Frames = new boolean[180][360]; if (paths != null || paths2 != null) { Debug.output("DTEDCoverageManager: Scanning for frames - This could take several minutes!"); checkOutCoverage(paths, paths2); } else { Debug.message("dtedcov", "DTEDCoverageManader: No paths for DTED data given."); } //Write out the new coverage file. if (coverageFile != null) { fireProgressUpdate(ProgressEvent.UPDATE, "Writing DTED Coverage file...", 100, 100); writeCoverageFile(coverageFile); } else { Debug.message("dtedcov", "DTEDCoverageManager: No file path specified to write coverage file!"); } fireProgressUpdate(ProgressEvent.DONE, "Wrote DTED Coverage file", 100, 100); } } /** * Set the color arraignment for the rectangles. Opaqueness is not * supported in JDK 1.1, so this doesn't really mean anything. * It's a hook for later. * * @param lev0Color Paint for level 0 frame rectangles. * @param lev1Color Paint for level 1 frame rectangles. * @param lev2Color Paint for level 2 frame rectangles. * @param opaque how transparent the frames should be if they are * filled. * @param fillRectangles whether to fill the rectangles with * Paint. */ public void setPaint(Paint lev0Color, Paint lev1Color, Paint lev2Color, int opaque, boolean fillRectangles) { level0Color = lev0Color; level1Color = lev1Color; level2Color = lev2Color; opaqueness = opaque; fillRects = fillRectangles; } /** * The method that cycles through all the paths, looking for the * frames. This takes time, so it's only done when a coverage file * can't be found. * * @param paths paths to the level 0 and 1 dted root directory. * @param paths2 paths to the level 2 dted root directory. */ public void checkOutCoverage(String[] paths, String[] paths2) { int latindex, lonindex; int maxNumPaths = 0; if (paths != null) maxNumPaths = paths.length; if ((paths2 != null) && (paths2.length > maxNumPaths)) maxNumPaths = paths2.length; if (maxNumPaths == 0) { System.err.println("DTEDCoverageManader: No paths for DTED data given."); return; } if (paths != null) { Debug.message("dtedcov", "DTEDCoverageManager: checking out DTED level 0, 1 at paths:"); for (int d1 = 0; d1 < paths.length; d1++) { if (Debug.debugging("dtedcov")) { Debug.output(" " + paths[d1]); } if (!BinaryFile.exists(paths[d1])) { paths[d1] = null; Debug.message("dtedcov", " - path invalid, ignoring."); } } } else { Debug.message("dtedcov", "DTEDCoverageManager: No DTED level 0, 1 paths specified."); } if (paths2 != null) { Debug.message("dtedcov", "DTEDCoverageManager: checking out DTED level 2 at paths:"); for (int d1 = 0; d1 < paths2.length; d1++) { if (Debug.debugging("dtedcov")) { Debug.output(" " + paths2[d1]); } if (!BinaryFile.exists(paths2[d1])) { paths2[d1] = null; Debug.message("dtedcov", " - path invalid, ignoring."); } } } else { Debug.message("dtedcov", "DTEDCoverageManager: No DTED level 2 paths specified."); } for (int pathNum = 0; pathNum < maxNumPaths; pathNum++) { for (int lat = -90; lat < 90; lat++) { for (int lon = -180; lon < 180; lon++) { latindex = lat + 90; lonindex = lon + 180; if (paths != null && pathNum < paths.length) { if (paths[pathNum] != null) { if (level0Frames[latindex][lonindex] == false) { level0Frames[latindex][lonindex] = BinaryFile.exists(paths[pathNum] + File.separator + DTEDFrameUtil.lonToFileString((float) lon) + File.separator + DTEDFrameUtil.latToFileString((float) lat, 0)); } if (level1Frames[latindex][lonindex] == false) { level1Frames[latindex][lonindex] = BinaryFile.exists(paths[pathNum] + File.separator + DTEDFrameUtil.lonToFileString((float) lon) + File.separator + DTEDFrameUtil.latToFileString((float) lat, 1)); } } } if ((paths2 != null) && (pathNum < paths2.length)) { if (paths2[pathNum] != null) { if (level2Frames[latindex][lonindex] == false) { level2Frames[latindex][lonindex] = BinaryFile.exists(paths2[pathNum] + File.separator + DTEDFrameUtil.lonToFileString((float) lon) + File.separator + DTEDFrameUtil.latToFileString((float) lat, 1)); } } } } float pathFactor = ((float) pathNum + 1f) / (float) maxNumPaths; float latFactor = 100f * ((float) lat + 90f) / 180f; int whereWeAre = (int) (pathFactor * latFactor); if (Debug.debugging("dtedcov")) { Debug.output("Building DTED Coverage, " + whereWeAre + "% complete."); } fireProgressUpdate(ProgressEvent.UPDATE, "Finding DTED frames...", whereWeAre, 100); } } } /** * Method organizes the query based on the projection, and returns * the applicable rectangles representing the frame coverages. If * the coverage spans over the dateline, then two queries are * performed, one for each side of the dateline. * * @param proj the projection of the screen * @return an array of lists, one for each level of dted data. */ public OMGraphicList[] getCoverageRects(Projection proj) { OMGraphicList[] ret1; OMGraphicList[] ret2; int LineType; LatLonPoint ul = proj.getUpperLeft(); LatLonPoint lr = proj.getLowerRight(); int startx = (int) Math.floor(ul.getLongitude()); int endx = (int) Math.floor(lr.getLongitude()); if (endx > 179) endx = 179; if (startx > 179) startx = 179; int starty = (int) Math.floor(lr.getLatitude()); int endy = (int) Math.floor(ul.getLatitude()); if (endy > 89) endy = 89; if (starty > 89) starty = 89;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -