⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coverageattributetable.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// **********************************************************************// // <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/CoverageAttributeTable.java,v $// $Revision: 1.5.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.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import com.bbn.openmap.io.BinaryFile;import com.bbn.openmap.io.FormatException;import com.bbn.openmap.util.Debug;/** * Handle the library level VPF directory. "noamer" in DCW is an * example of the library level data. This class loads the associated * tiling information, and the coverage types, and make them available * to the client. */public class CoverageAttributeTable {    /** the name of the library we are, for example "noamer" in DCW */    final protected String libraryname;    /** the path to our directory */    final protected String dirpath;    /** are we tiled or untiled coverage */    private boolean isTiled = false;    /** coverage name to CoverageEntry map */    final private Map coverages = new HashMap();    /**     * The tiles that compose our coverage area. The size of the array     * is going to be set to record count + 1, and the tiles will have     * their ID number as their index.     */    private TileDirectory containedTiles[];    /** the column names in the cat. file */    private final static String CATColumns[] = { Constants.CAT_COVNAME,            Constants.CAT_DESC, Constants.CAT_LEVEL };    /** expected schema types for the cat. file */    private final static char CATschematype[] = {            DcwColumnInfo.VPF_COLUMN_TEXT, DcwColumnInfo.VPF_COLUMN_TEXT,            DcwColumnInfo.VPF_COLUMN_INT_OR_SHORT };    /** expected schema lengths for cat. file */    private final static int CATschemalength[] = { -1 /* 8 */, -1 /* 50 */, 1 };    /**     * Construct a new coverage attribute table     *      * @param libname the name of the library     * @param dcwpath the path to the library     * @exception FormatException may throw FormatExceptions     */    public CoverageAttributeTable(String dcwpath, String libname)            throws FormatException {        libraryname = libname;        dirpath = dcwpath + "/" + libraryname;        String cat = dirpath + "/cat";        if (!BinaryFile.exists(cat)) {            cat = cat + ".";        }        DcwRecordFile rf = new DcwRecordFile(cat);        int catcols[] = rf.lookupSchema(CATColumns,                true,                CATschematype,                CATschemalength,                false);        List l = new ArrayList(rf.getColumnCount());        while (rf.parseRow(l)) {            int topL = ((Number) l.get(catcols[2])).intValue();            String desc = (String) l.get(catcols[1]);            String covtype = ((String) l.get(catcols[0])).toLowerCase()                    .intern();            coverages.put(covtype, new CoverageEntry(topL, desc));        }        rf.close();        rf = null;        doTileRefStuff(dirpath + "/tileref");    }    /**     * is this library tiled     *      * @return <code>true</code> for tiled coverage.     *         <code>false</code> else     */    public final boolean isTiledCoverage() {        return isTiled;    }    /**     * the name of the library     *      * @return the name of the library     */    public String getLibraryName() {        return libraryname;    }    /** the columns we need in fbr for tiling */    private static final String[] fbrColumns = { Constants.FBR_XMIN,            Constants.FBR_YMIN, Constants.FBR_XMAX, Constants.FBR_YMAX };    /** the columns we need in fcs for tiling */    private static final String[] fcsColumns = { Constants.FCS_FEATURECLASS,            Constants.FCS_TABLE1, Constants.FCS_TABLE1KEY,            Constants.FCS_TABLE2, Constants.FCS_TABLE2KEY };    /** the columns we need in fcs for tiling for DCW */    private static final String[] fcsColumnsDCW = { Constants.FCS_FEATURECLASS,            Constants.FCS_TABLE1, Constants.DCW_FCS_TABLE1KEY,            Constants.FCS_TABLE2, Constants.DCW_FCS_TABLE2KEY };    /**     * an internal function to load the tiling information     *      * @param pathname the path to the tile directory     */    private void doTileRefStuff(String pathname) {        doTileRefStuff(pathname, false);    }    /**     * an internal function to load the tiling information, with an     * option to use DCW column names.     *      * @param pathname the path to the tile directory     * @param DCW use DCW column names.     */    private void doTileRefStuff(String pathname, boolean DCW) {        String faceIDColumnName = null;        // Figure out how files names should be constructed...        boolean addSlash = true;        //      if (pathname.endsWith(File.separator)) {        if (pathname.endsWith("/") || pathname.endsWith(File.separator)) {            addSlash = false;        }        //read fcs to figure out what column in tileref.aft we need        // to use to        //read the fbr (face bounding rectangle) table        try {            String fcsFile = pathname + (addSlash ? "/" : "") + "fcs";            if (!BinaryFile.exists(fcsFile)) {                fcsFile = fcsFile + ".";            }            DcwRecordFile fcs = new DcwRecordFile(fcsFile);            List fcsv = new ArrayList(fcs.getColumnCount());            int fcscols[];            if (!DCW) {                fcscols = fcs.lookupSchema(fcsColumns, true);            } else {                fcscols = fcs.lookupSchema(fcsColumnsDCW, true);            }            while (fcs.parseRow(fcsv)) {                String fclass = (String) fcsv.get(fcscols[0]);                String table1 = (String) fcsv.get(fcscols[1]);                String table1_key = (String) fcsv.get(fcscols[2]);                /* Not used                String table2 = (String) fcsv.get(fcscols[3]);                String table2_key = (String) fcsv.get(fcscols[4]);                */                if ("tileref".equalsIgnoreCase(fclass)                        && "tileref.aft".equalsIgnoreCase(table1)) {                    faceIDColumnName = table1_key.toLowerCase();                    break;                }            }            fcs.close();        } catch (FormatException f) {            // If DCW, we'll get here, need to try lookupSchema with            // proper column names            if (!DCW)                doTileRefStuff(pathname, true);            return;            //either way, return. The recursive call may have worked.        } catch (NullPointerException npe) {            return; // file wasn't found...        }        if (faceIDColumnName == null) {            return; //won't be able to read the tiling info. abort        }        isTiled = true;        //Okay, we've got info on what column we use from tileref.aft        //to index into the fbr.        try {            DcwRecordFile aft = new DcwRecordFile(pathname                    + (addSlash ? "/" : "") + "tileref.aft");            int faceIDColumn = aft.whatColumn(faceIDColumnName.toLowerCase());            int tileNameColumn = aft.whatColumn("tile_name");            if ((faceIDColumn == -1) || (tileNameColumn == -1)) {                aft.close();                return;            }            String fbrFile = pathname + (addSlash ? "/" : "") + "fbr";            if (!BinaryFile.exists(fbrFile)) {                fbrFile = fbrFile + ".";            }            DcwRecordFile fbr = new DcwRecordFile(fbrFile);            int fbrIDColumn = fbr.whatColumn(Constants.ID);            List aftv = new ArrayList(aft.getColumnCount());            List fbrv = new ArrayList(fbr.getColumnCount());            int fbrcols[] = fbr.lookupSchema(fbrColumns, true);            // set the array size to record count + 1, to be able to            // use the tileID as the index into the array            // aft.getRecordCount() is not reliable if file is being            // read with a network input stream. So, we have to            // create the TileDirectory[] a different way.            //          containedTiles = new TileDirectory[aft.getRecordCount()            // + 1];            // This is part of that solution...            ArrayList tileArrayList = new ArrayList(500);            Object nullTile = new Object();            while (aft.parseRow(aftv)) {                int fac_num = ((Number) aftv.get(faceIDColumn)).intValue();                fbr.getRow(fbrv, fac_num); //mutates fbrv                int tileid = ((Number) aftv.get(fbrIDColumn)).intValue();                String tilename = (String) aftv.get(tileNameColumn);                char chs[] = tilename.toCharArray();                boolean goodTile = false;                for (int i = 0; i < chs.length; i++) {                    if ((chs[i] != '\\') && (chs[i] != ' ')) {                        goodTile = true;                    }                    if (chs[i] == '\\') {                        //                      chs[i] = File.separatorChar;                        chs[i] = '/'; // we're using BinaryFile, in                                      // java land...                    }                }                tilename = new String(chs);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -