📄 asrpdirectory.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/dataAccess/asrp/ASRPDirectory.java,v $// $RCSfile: ASRPDirectory.java,v $// $Revision: 1.1.2.7 $// $Date: 2005/08/11 21:03:20 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.dataAccess.asrp;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.dataAccess.iso8211.*;import com.bbn.openmap.layer.util.cacheHandler.*;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.omGraphics.OMRect;import com.bbn.openmap.omGraphics.OMScalingRaster;import com.bbn.openmap.proj.EqualArc;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;import java.awt.Color;import java.awt.Rectangle;import java.awt.Shape;import java.io.File;import java.io.IOException;import java.util.List;/** * An ASRP directory contains information needed to view images. It * contains multiple files, each containing complementary information * about the image. The GeneralInformationFile (GEN) contains * information about the image such as coverage and location. The * QualityFile (QAL) contains accuracy and color information. The * GeoReferenceFile (GER) contains projection information, the * SourceFile (SOU) contains information about the map that was used * to create the images. The RasterGeoDataFile (IMG) contains the * actual pixel information. * <P> * * This class knows how to use all of these files to create images, * which are made up of subframe tiles called blocks. */public class ASRPDirectory extends CacheHandler implements ASRPConstants { protected GeneralInformationFile gen; protected QualityFile qal; protected RasterGeoDataFile img; protected GeoReferenceFile ger; protected SourceFile sou; /** List of tile indexes. */ protected List tsi; /** Number of horizontal blocks. */ protected int numHorBlocks_N; /** Number of vertical blocks. */ protected int numVerBlocks_M; /** Number of horizontal pixels per block. */ protected int numHorPixels_Q; /** Number of vertical pixels per block. */ protected int numVerPixels_P; /** * When reading image bytes, the number of bits that represent the * number of pixels the next color index stands for. */ protected int pixelCountBits; /** * When reading image bytes, the number of bits that represent the * color index. */ protected int pixelValueBits; /* Bounding coordinates for coverage. */ protected float swo, nea, neo, swa; // west lon, north lat, east // lon, south lat /* Upper left latitude/longitude for top left tile. */ protected float lso, pso; // padded longitude, latitude of upper // left image corner /** Number of pixels 360 degrees east - west. */ protected int arv; /** Number of pixels 360 degrees north - south. */ protected int brv; /** * Calculated number of degrees per block in the horizontal * direction. */ protected float degPerHorBlock; /** * Calculated number of degrees per block in the vertical * direction. */ protected float degPerVerBlock; /** Byte offset into the IMG file where tile data starts. */ protected int tileDataOffset; /** The colors from the QAL file. */ protected Color[] colors; /** The OMRect used to track coverage boundaries. */ protected OMRect bounds; protected File dir; /** * Protective mechanism, doesn't display data that has images with * a base scale that is more than a factor of the scaleFactor away * from the scale of the map. */ protected double scaleFactor = 4; /** * Create a new ASRP directory for the given path. Calls * initialize() which will read in the different files to find out * the attribute information about the data. */ public ASRPDirectory(String path) { dir = new File(path); if (dir.exists()) { try { initialize(dir.getPath(), dir.getName(), "01"); } catch (IOException ioe) { Debug.error(ioe.getMessage()); ioe.printStackTrace(); return; } } else { Debug.error("ASRPDirectory (" + path + ") doesn't exist"); } } public String getPath() { if (dir != null) { return dir.getPath(); } return null; } /** * Get the OMRect used for calculating coverage area. */ public OMRect getBounds() { if (bounds == null) { bounds = new OMRect(pso, lso, pso - degPerVerBlock * numVerBlocks_M, lso + degPerHorBlock * numHorBlocks_N, OMGraphic.LINETYPE_GREATCIRCLE); } return bounds; } public void setScaleFactor(double scaleFactorIn) { scaleFactor = scaleFactorIn; } public double getScaleFactor() { return scaleFactor; } /** * Return true of current bounds covers the projection area. */ public boolean isOnMap(Projection proj) { OMRect bds = getBounds(); bds.generate(proj); Shape s = bds.getShape(); return s.intersects(0, 0, proj.getWidth(), proj.getHeight()); } public boolean validScale(Projection proj) { if (proj instanceof EqualArc) { EqualArc ea = (EqualArc) proj; double xPixConstant = ea.getXPixConstant(); double scale = xPixConstant / arv; boolean result = (scale < scaleFactor) && (scale > 1 / scaleFactor); if (Debug.debugging("asrp")) { Debug.output("Scale comparing arv = " + arv + ", " + xPixConstant + ", result: " + result); } return result; } return false; } /** * Get an OMGraphicList of files that cover the projection. * Returns an empty list if the coverage isn't over the map. */ public OMGraphicList checkProjAndGetTiledImages(Projection proj) throws IOException { if (!isOnMap(proj) || !validScale(proj)) { // off the map return new OMGraphicList(); } return getTiledImages(proj); } /** * Assumes that the projection checks have occured, have passed, * and just fetches the image tiles. */ public OMGraphicList getTiledImages(Projection proj) throws IOException { float ullat = pso; float ullon = lso; float lrlat = ullat - (degPerVerBlock * numVerBlocks_M); float lrlon = ullon + (degPerHorBlock * numHorBlocks_N); LatLonPoint llp1 = proj.getUpperLeft(); LatLonPoint llp2 = proj.getLowerRight(); int startX = (int) Math.floor((llp1.getLongitude() - ullon) / degPerHorBlock); int startY = (int) Math.floor((ullat - llp1.getLatitude()) / degPerVerBlock); int endX = numHorBlocks_N - (int) Math.floor((lrlon - llp2.getLongitude()) / degPerHorBlock); int endY = numVerBlocks_M - (int) Math.floor((llp2.getLatitude() - lrlat) / degPerVerBlock); if (startX < 0) startX = 0; if (startY < 0) startY = 0; if (endX > numHorBlocks_N) endX = numHorBlocks_N; if (endY > numVerBlocks_M) endY = numVerBlocks_M; return getTiledImages(new Rectangle(startX, startY, endX - startX, endY - startY), proj); } /** * Provide an OMGraphicList containing the tile blocks described * by the rectangle. * * @param rect rectangle defining the tile blocks to get. rect.x * and rect.y describe the starting upper left block to * get, rect.getWidth and rect.getHeight describe the * number of tiles to the right and down from the first * block to collect. */ protected OMGraphicList getTiledImages(Rectangle rect, Projection proj) throws IOException { if (Debug.debugging("asrp")) { Debug.output("ASRPDirectory: fielding request for " + rect); } OMGraphicList list = new OMGraphicList(); int startX = (int) rect.getX(); int startY = (int) rect.getY(); int endX = startX + (int) rect.getWidth(); int endY = startY + (int) rect.getHeight(); for (int x = startX; x < endX; x++) { for (int y = startY; y < endY; y++) { OMGraphic omg = (OMGraphic) get(new String(x + "," + y).intern()); if (omg != null) { omg.generate(proj); list.add(omg); } } } return list; } /** * Fetch the subframe tile block from the IMG file. */ public OMScalingRaster getBlock(int x, int y) throws IOException { float ullat = pso - y * degPerVerBlock; float ullon = lso + x * degPerHorBlock; float lrlat = ullat - degPerVerBlock; float lrlon = ullon + degPerHorBlock;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -