📄 coveragetable.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/CoverageTable.java,v $// $Revision: 1.7.2.5 $ $Date: 2005/08/11 21:03:13 $ $Author: dietrick $// **********************************************************************package com.bbn.openmap.layer.vpf;import java.io.File;import java.util.ArrayList;import java.util.Collections;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;/** * Encapsulate a VPF coverage directory. This class handles requests * that happen for a particular coverage type (political boundary, * road, etc.) for a particular library (north america, browse, etc.). */public class CoverageTable { /** our coverage type - such as "po", "bnd", "hydro" */ final public String covtype; /** the directory for our coverage type */ final protected String tablepath; /** a table to cache int.vdt information */ final private Map intvdtrec = new HashMap(); /** a table to cache char.vdt information */ final private Map charvdtrec = new HashMap(); /** hack - used by EdgeTable */ public int cachedLineSchema[] = null; /** hack - used by AreaTable */ public int cachedAreaSchema[] = null; /** hack - used by TextTable */ public int cachedTextSchema[] = null; /** hack - used by nodetable */ public int cachedEPointSchema[] = null; /** hack - used by nodetable */ public int cachedCPointSchema[] = null; /** featureclasses used for the line feature type */ public FeatureClassInfo lineinfo[] = new FeatureClassInfo[0]; /** featureclasses used for the area feature type */ public FeatureClassInfo areainfo[] = new FeatureClassInfo[0]; /** featureclasses used for the text feature type */ public FeatureClassInfo textinfo[] = new FeatureClassInfo[0]; /** featureclasses used for the entity node feature type */ public FeatureClassInfo epointinfo[] = new FeatureClassInfo[0]; /** featureclasses used for the connected node feature type */ public FeatureClassInfo cpointinfo[] = new FeatureClassInfo[0]; /** * Feature classes to look up FeatureClassInfo via feature name. */ protected Hashtable featureTypes = new Hashtable(); protected Hashtable featureTypeInfo; /** do we need to append a '.' to three-character file names */ public boolean appendDot = false; /** * Need this in case we have to go from the coverage type->feature * type->tile */ protected CoverageAttributeTable cat; /** hackage for the antactica polygon in DCW browse coverage */ final public boolean doAntarcticaWorkaround; public static final char EDGE_FEATURETYPE = 'L'; public static final char AREA_FEATURETYPE = 'A'; public static final char TEXT_FEATURETYPE = 'T'; public static final char UPOINT_FEATURETYPE = 'P'; public static final char EPOINT_FEATURETYPE = 'E'; public static final char CPOINT_FEATURETYPE = 'N'; public static final char COMPLEX_FEATURETYPE = 'C'; public static final char SKIP_FEATURETYPE = 'S'; /** * Construct a CoverageTable object. Data is expected to be in a * directory called path/covtype. * * @param path the path to the parent directory of where our data * resides * @param covtype the subdirectory name for the coverage data */ public CoverageTable(String path, String covtype) { this.covtype = covtype; tablepath = path + "/" + covtype + "/"; doAntarcticaWorkaround = (tablepath.indexOf("browse") >= 0); internSchema(); loadIntVDT(); loadCharVDT(); featureTypeInfo = getFeatureTypeInfo(); } /** * Construct a CoverageTable object. Data is expected to be in a * directory called path/covtype. * * @param path the path to the parent directory of where our data * resides * @param covtype the subdirectory name for the coverage data * @param cat the CoverageAttributeTable reference, in case we * need to backtrack the tiles through the feature tables. */ public CoverageTable(String path, String covtype, CoverageAttributeTable cat) { this(path, covtype); this.cat = cat; } /** required column names for char.vdt and int.vdt files */ public final static String VDTColumnNames[] = { Constants.VDT_TABLE, Constants.VDT_ATTRIBUTE, Constants.VDT_VALUE, Constants.VDT_DESC }; /** expected schema types for int.vdt files */ public final static char intVDTschematype[] = { DcwColumnInfo.VPF_COLUMN_INT, DcwColumnInfo.VPF_COLUMN_TEXT, DcwColumnInfo.VPF_COLUMN_TEXT, DcwColumnInfo.VPF_COLUMN_INT_OR_SHORT, DcwColumnInfo.VPF_COLUMN_TEXT }; /** expected schema lengths for int.vdt files */ public final static int intVDTschemalength[] = { 1, -1, -1, 1, -1 }; private void loadIntVDT() { try { String vdt = tablepath + Constants.intVDTTableName; if (BinaryFile.exists(vdt)) { DcwRecordFile intvdt = new DcwRecordFile(vdt); int cols[] = intvdt.lookupSchema(VDTColumnNames, true, intVDTschematype, intVDTschemalength, false); for (List l = new ArrayList(intvdt.getColumnCount()); intvdt.parseRow(l);) { String tab = (String) l.get(cols[0]); String attr = (String) l.get(cols[1]); int val = ((Number) l.get(cols[2])).intValue(); String desc = ((String) l.get(cols[3])).intern(); intvdtrec.put(new CoverageIntVdt(tab, attr, val), desc); } intvdt.close(); } } catch (FormatException f) { } } /** expected schema types for char.vdt files */ public final static char charVDTschematype[] = { DcwColumnInfo.VPF_COLUMN_INT, DcwColumnInfo.VPF_COLUMN_TEXT, DcwColumnInfo.VPF_COLUMN_TEXT, DcwColumnInfo.VPF_COLUMN_TEXT, DcwColumnInfo.VPF_COLUMN_TEXT }; /** expected schema lengths for char.vdt files */ public final static int charVDTschemalength[] = { 1, -1, -1, -1, -1 }; private void loadCharVDT() { try { String vdt = tablepath + Constants.charVDTTableName; if (BinaryFile.exists(vdt)) { DcwRecordFile charvdt = new DcwRecordFile(vdt); int cols[] = charvdt.lookupSchema(VDTColumnNames, true, charVDTschematype, charVDTschemalength, false); for (List l = new ArrayList(charvdt.getColumnCount()); charvdt.parseRow(l);) { String tab = (String) l.get(cols[0]); String attr = (String) l.get(cols[1]); String val = (String) l.get(cols[2]); String desc = ((String) l.get(cols[3])).intern(); charvdtrec.put(new CoverageCharVdt(tab, attr, val), desc); } charvdt.close(); } } catch (FormatException f) { } } private FeatureClassInfo[] internSchema(FeatureClassInfo[] fti, String foreign_key, String tablename) throws FormatException { FeatureClassInfo rv[] = new FeatureClassInfo[fti.length + 1]; System.arraycopy(fti, 0, rv, 0, fti.length); rv[fti.length] = new FeatureClassInfo(this, foreign_key.intern(), tablepath, tablename.intern()); return rv; } /** the columns of the fcs file we are interested in */ 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 }; /** * This method reads the feature class schema (fcs) file to * discover the inter-table relations (joins, in database * parlance). As a side effect, this method also sets the * appendDot member. */ private void internSchema() { internSchema(false); } /** * This method reads the feature class schema (fcs) file to * discover the inter-table relations (joins, in database * parlance). As a side effect, this method also sets the * appendDot member. The DCW option refers to if the DCW column * names should be used, for DCW data. This is only true if a * problem occurs, and then this method is called recursively. */ private void internSchema(boolean DCW) { // Figure out how files names should be constructed... boolean addSlash = true; // if (tablepath.endsWith(File.separator)) { if (tablepath.endsWith("/") || tablepath.endsWith(File.separator)) { addSlash = false; } try { String filename = tablepath + (addSlash ? "/" : "") + "fcs"; if (!BinaryFile.exists(filename)) { filename = filename + "."; appendDot = true; } DcwRecordFile fcs = new DcwRecordFile(filename); int[] fcscols = fcs.lookupSchema(DCW ? fcsColumnsDCW : fcsColumns, true); for (List fcsrec = new ArrayList(fcs.getColumnCount()); fcs.parseRow(fcsrec);) { String feature_class = (String) fcsrec.get(fcscols[0]); String table1 = (String) fcsrec.get(fcscols[1]); String foreign_key = (String) fcsrec.get(fcscols[2]); String table2 = (String) fcsrec.get(fcscols[3]); String primary_key = (String) fcsrec.get(fcscols[4]); internSchema(feature_class.toLowerCase(), table1.toLowerCase(), foreign_key.toLowerCase(), table2.toLowerCase(), primary_key.toLowerCase()); } fcs.close(); } catch (FormatException f) { if (!DCW) { internSchema(true); } else { System.out.println("CoverageTable: " + f.getMessage()); } } } private void internSchema(String feature_class, String table1, String foreign_key, String table2, String primary_key) { try { if (table1.equals("fac")) { areainfo = internSchema(areainfo, foreign_key, table2); } else if (table1.equals("edg")) { lineinfo = internSchema(lineinfo, foreign_key, table2); } else if (table1.equals("end")) { epointinfo = internSchema(epointinfo, foreign_key, table2); } else if (table1.equals("cnd")) { cpointinfo = internSchema(cpointinfo, foreign_key, table2); } else if (table1.equals("txt")) { textinfo = internSchema(textinfo, foreign_key, table2); } else if (table1.startsWith(feature_class) && (foreign_key.equals("end_id") || foreign_key.equals("cnd_id") || foreign_key.equals("fac_id") || foreign_key.equals("edg_id") || foreign_key.equals("txt_id"))) { if (Debug.debugging("vpf")) { Debug.output("CoverageTable: Found entry for: " + feature_class + ": " + table1 + "|" + foreign_key + "|" + table2 + "|" + primary_key); } FeatureClassInfo featureClass = new FeatureClassInfo(this, foreign_key.intern(), tablepath.intern(), table1.intern(), table2.intern(), foreign_key.intern()); featureClass.close(false); // releases file descriptors featureTypes.put(feature_class.intern(), featureClass); } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -