?? libraryselectiontable.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/vpf/LibrarySelectionTable.java,v $// $Revision: 1.9.2.3 $ $Date: 2005/08/09 21:17:52 $ $Author: dietrick $// **********************************************************************package com.bbn.openmap.layer.vpf;import java.io.File;import java.util.ArrayList;import java.util.Enumeration;import java.util.HashMap;import java.util.Hashtable;import java.util.Iterator;import java.util.List;import java.util.Map;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.io.BinaryFile;import com.bbn.openmap.io.FormatException;import com.bbn.openmap.util.Debug;/** * Reads the VPF LibraryAttribute table and constructs * CoverageAttributeTables for each of the library coverages (north * america, browse, etc) that exist. * * <p> * NOTE: This class maintains a whole bunch of cached information, and * also hangs onto references to classes that cache even more * information. When using this class, you are much better off sharing * an instance of this class, rather than creating multiple * instantiations of it for the same VPF data directory. * * @see CoverageAttributeTable */public class LibrarySelectionTable { /** cutoff scale for browse coverage. */ public final static int DEFAULT_BROWSE_CUTOFF = 31000000; protected int BROWSE_CUTOFF = DEFAULT_BROWSE_CUTOFF; /** * the names of the VPF libraries listed in the library attribute * table */ //private String libraryname[] = null; //library [i] /** the bounding rectangle of the respective libraries */ private Map boundrec = new HashMap();//bounding rect as [W,S,E,N] /** the CoverageAttributeTables corresponding to the different libs */ private Map CATs = new HashMap(); /** the names of the lat columns */ final private static String LATColumns[] = { Constants.LAT_LIBNAME, Constants.LAT_XMIN, Constants.LAT_YMIN, Constants.LAT_XMAX, Constants.LAT_YMAX }; /** the expected schema types for the library attribute table */ final private static char LATschematype[] = { 'T', 'F', 'F', 'F', 'F' }; /** the expected schema lengths for the library attribute table */ final private static int LATschemalength[] = { -1 /* 8 */, 1, 1, 1, 1 }; /** the name of the database */ private String databaseName; /** the database description of itself */ private String databaseDesc; /** * Construct a LibrarySelectionTable without a path to data. */ public LibrarySelectionTable() {} /** * Construct a LibrarySelectionTable with a path to data. * * @param vpfpath the path to the base data directory; the file * opened is <code>vpfpath</code> /lat. * @exception FormatException some error was encountered while * trying to handle the file. */ public LibrarySelectionTable(String vpfpath) throws FormatException { addDataPath(vpfpath); } /** * Construct a LibrarySelectionTable with a path to data. * * @param vpfpaths the paths to the data directories; the file * opened is <code>vpfpath</code> /lat. * @exception FormatException some error was encountered while * trying to handle the file. */ public LibrarySelectionTable(String vpfpaths[]) throws FormatException { for (int i = 0; i < vpfpaths.length; i++) { addDataPath(vpfpaths[i]); } } /** * Set the cutoff scale where if the map scale number is larger * (smaller overall map scale), the coverage won't be returned. * For example, if the scale cutoff is 30000000, if the map scale * is 1:31000000, no map data will be returned. */ public void setCutoffScale(int scale) { BROWSE_CUTOFF = scale; } /** * Get the cutoff scale where data will be retrieved. */ public int getCutoffScale() { return BROWSE_CUTOFF; } /** * add a path to LibrarySelectionTable. Adding different types of * VPF libraries to the same LST is likely to cause trouble. (e.g. * it would be bad to add both DCW and VMAP paths to the same LST. * adding each DCW disk separately is why this method exists.) * * @param vpfpath the path to the base DCW directory; the file * opened is <code>vpfpath</code> /lat. * @exception FormatException some error was encountered while * trying to handle the file. */ public void addDataPath(String vpfpath) throws FormatException { if (Debug.debugging("vpf")) { Debug.output("LST.addDataPath(" + vpfpath + ")"); } // Figure out how files names should be constructed... boolean addSlash = true; if (vpfpath.endsWith("/") || vpfpath.endsWith(File.separator)) { addSlash = false; } String latf = vpfpath + (addSlash ? "/" : "") + "lat"; String dhtf = vpfpath + (addSlash ? "/" : "") + "dht"; if (!BinaryFile.exists(latf)) { latf = latf + "."; dhtf = dhtf + "."; } DcwRecordFile latrf = new DcwRecordFile(latf); DcwRecordFile dhtrf = new DcwRecordFile(dhtf); List databaseVec = dhtrf.parseRow(); int dcol = dhtrf.whatColumn("database_name"); if (dcol != -1) { databaseName = (String) databaseVec.get(dcol); } dcol = dhtrf.whatColumn("database_desc"); if (dcol != -1) { databaseDesc = (String) databaseVec.get(dcol); } dhtrf.close(); dhtrf = null; int latcols[] = latrf.lookupSchema(LATColumns, true, LATschematype, LATschemalength, false); Debug.message("vpf", "lst.adp: looked up schema"); for (List l = new ArrayList(latrf.getColumnCount()); latrf.parseRow(l);) { String lname = ((String) l.get(latcols[0])).toLowerCase(); float br[] = new float[] { ((Float) l.get(latcols[1])).floatValue(), ((Float) l.get(latcols[2])).floatValue(), ((Float) l.get(latcols[3])).floatValue(), ((Float) l.get(latcols[4])).floatValue() }; try { CoverageAttributeTable table = new CoverageAttributeTable(vpfpath, lname); CATs.put(lname, table); boundrec.put(lname, br); if (Debug.debugging("vpf")) { Debug.output(lname + " " + br[0] + " " + br[1] + " " + br[2] + " " + br[3]); } } catch (FormatException fe) { if (Debug.debugging("vpf")) { Debug.output("*****\nVPFLayer.LST: Couldn't create CoverageAttributeTable for " + vpfpath + " " + lname + " " + fe.getMessage() + "\n--- Not a problem if you have multiple paths, and " + lname + " is included in another path ---\n*****"); fe.printStackTrace(); } else { Debug.output("VPFLayer.LST: CAT discrepancy (run with -Ddebug.vpf for more details)"); } } } latrf.close(); latrf = null; } /** * Return the list of libraries that this database has. * * @return the list of libraries. for DCW, this is typically * NOAMER, BROWSE, etc. */ public String[] getLibraryNames() { return (String[]) CATs.keySet().toArray(Constants.EMPTY_STRING_ARRAY); } /** * Return the name of the database we are reading from. */ public String getDatabaseName() { return databaseName; } /** * Return the description of the database we are reading from. */ public String getDatabaseDescription() { return databaseDesc; } /** * Return the coverage attribute table (list of coverages * available for the given library) for the given library name. * * @param library the name of the library to get the CAT for * @return the CoverageAttributeTable requested (null if the * library requested doesn't exist in the database) * @exception FormatException exceptions from opening the CAT for * the library */ public CoverageAttributeTable getCAT(String library) throws FormatException { return (CoverageAttributeTable) CATs.get(library); } /** * */ public void drawTile(int scale, int screenwidth, int screenheight, String covname, VPFGraphicWarehouse warehouse, LatLonPoint ll1, LatLonPoint ll2) { if (Debug.debugging("vpf")) { Debug.output("Library selection table coverage: " + covname); Debug.output("Library selection table - edges: " + warehouse.drawEdgeFeatures()); Debug.output("Library selection table - text: " + warehouse.drawTextFeatures()); Debug.output("Library selection table - areas: " + warehouse.drawAreaFeatures()); Debug.output("Warehouse: " + warehouse); Debug.output("Warehouse: cutoff scale " + BROWSE_CUTOFF); } // handle Dateline if ((scale < BROWSE_CUTOFF) && (ll1.getLongitude() > ll2.getLongitude())) { drawTile(scale,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -