/** * Constructs a VPF Database from a path to the Database Header table. This initializes the Database Header Table * and the Library Attribute Table. * * @param filePath the path to the Database Header Table. * * @return a new Database from the specified Database Header Table path. * * @throws ArgumentException if the file path is null or empty. */ public static VPFDatabase fromFile(String filePath) { if (WWUtil.isEmpty(filePath)) { String message = Logging.getMessage("nullValue.FilePathIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } File file = new File(filePath); if (!file.exists()) { String message = Logging.getMessage("generic.FileNotFound", filePath); Logging.logger().severe(message); throw new WWRuntimeException(message); } // Database tables. VPFBufferedRecordData dht = VPFUtils.readTable(file); if (dht == null) { String message = Logging.getMessage("VPF.DatabaseHeaderTableMissing"); throw new WWRuntimeException(message); } VPFBufferedRecordData lat = VPFUtils.readTable( new File(file.getParent(), VPFConstants.LIBRARY_ATTRIBUTE_TABLE)); if (lat == null) { String message = Logging.getMessage("VPF.LibraryAttributeTableMissing"); throw new WWRuntimeException(message); } VPFDatabase database = new VPFDatabase(file.getParent()); database.setDatabaseHeaderTable(dht); database.setLibraryAttributeTable(lat); // Database metadata attributes. VPFRecord record = dht.getRecord(1); if (record != null) { VPFUtils.checkAndSetValue(record, "database_name", AVKey.DISPLAY_NAME, database); VPFUtils.checkAndSetValue(record, "database_desc", AVKey.DESCRIPTION, database); } // Database Libraries. Collection <VPFLibrary> col = createLibraries(database, lat); if (col != null) { database.setLibraries(col); } return(database); }
protected VPFFeature createSimpleFeature(VPFFeatureClass featureClass, VPFRecord featureRow, Iterable <String> attributeKeys) { // Feature has a direct 1:1 relation to the primitive table. if (this.tile != null && !matchesTile(featureRow, this.tile)) { return(null); } VPFRelation featureToPrimitive = this.getFeatureToPrimitiveRelation(featureClass); if (featureToPrimitive == null) { return(null); } int primitiveId = asInt(featureRow.getValue(featureToPrimitive.getTable1Key())); VPFPrimitiveData.PrimitiveInfo primitiveInfo = this.primitiveData.getPrimitiveInfo( featureToPrimitive.getTable2(), primitiveId); return(this.createFeature(featureClass, featureRow, attributeKeys, primitiveInfo.getBounds(), new int[] { primitiveId })); }
protected VPFFeature createFeature(VPFFeatureClass featureClass, VPFRecord featureRow, Iterable <String> attributeKeys, VPFBoundingBox bounds, int[] primitiveIds) { VPFFeature feature = new VPFFeature(featureClass, featureRow.getId(), bounds, primitiveIds); this.setFeatureAttributes(featureRow, attributeKeys, feature); return(feature); }
protected VPFFeature doCreateSimpleFeature(VPFFeatureClass featureClass, VPFRecord featureRow, VPFBufferedRecordData joinTable, Iterable <String> attributeKeys) { if (joinTable != null) { return(this.createCompoundSimpleFeature(featureClass, featureRow, joinTable, attributeKeys)); } else { return(this.createSimpleFeature(featureClass, featureRow, attributeKeys)); } }
/** * Returns the extent ("xmin", "ymin", "xmax", "ymax") for the specified row as a {@link VPFBoundingBox}. * * @param record the record to extract the bound attributes from. * * @return extent of the specified row. */ public static VPFBoundingBox getExtent(VPFRecord record) { if (record == null) { String message = Logging.getMessage("nullValue.RecordIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } return(new VPFBoundingBox( ((Number)record.getValue("xmin")).doubleValue(), ((Number)record.getValue("ymin")).doubleValue(), ((Number)record.getValue("xmax")).doubleValue(), ((Number)record.getValue("ymax")).doubleValue())); }
//**************************************************************// //******************** Winged-Edge Face Construction *********// //**************************************************************// /** * Given a row from the ring primitive table, navigate the ring and edge primitive tables to construct a new {@link * VPFPrimitiveData.Ring}. * * @param row the ring primitive row. * @param edgeInfoArray the edge primitive data. * * @return a new Ring. */ protected VPFPrimitiveData.Ring buildRing(VPFRecord row, VPFPrimitiveData.PrimitiveInfo[] edgeInfoArray) { int faceId = ((Number)row.getValue("face_id")).intValue(); int startEdgeId = ((Number)row.getValue("start_edge")).intValue(); VPFWingedEdgeTraverser traverser = new VPFWingedEdgeTraverser(); // Traverse the ring to collect the number of edges which define the ring. final int numEdges = traverser.traverseRing(faceId, startEdgeId, edgeInfoArray, null); final int[] idArray = new int[numEdges]; final int[] orientationArray = new int[numEdges]; // Traverse the ring again, but this time populate an entry for the primitiveID and orientation data stuctures // for each edge. traverser.traverseRing(faceId, startEdgeId, edgeInfoArray, new VPFWingedEdgeTraverser.EdgeTraversalListener() {
public VPFFeatureClassSchema[] getFeatureClasses(FileFilter featureTableFilter) { if (featureTableFilter == null) { String message = Logging.getMessage("nullValue.FilterIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } // List the file names in the coverage directory matching the specified feature table file filter. String[] names = WWIO.listChildFilenames(new File(this.getFilePath()), featureTableFilter); if (names == null) { return(null); } int numFeatures = names.length; VPFFeatureClassSchema[] desc = new VPFFeatureClassSchema[numFeatures]; for (int i = 0; i < numFeatures; i++) { String featureTableName = names[i]; String className = WWIO.replaceSuffix(featureTableName, ""); String type = null; // If the Feature Class Attriute Table is available, then use it to determine the feature type for the // specified class. if (this.featureClassAttributeTable != null) { VPFRecord record = this.featureClassAttributeTable.getRecord("fclass", className); if (record != null) { type = (String)record.getValue("type"); } } // Otherwise, determine the feature type is based on the feature table extension. if (type == null) { type = VPFUtils.getFeatureTypeName(featureTableName); } desc[i] = new VPFFeatureClassSchema(className, VPFFeatureType.fromTypeName(type), featureTableName); } return(desc); }
protected void buildEdgePrimitives(VPFCoverage coverage, VPFTile tile, VPFPrimitiveData primitiveData) { VPFBufferedRecordData edgeTable = this.createPrimitiveTable(coverage, tile, VPFConstants.EDGE_PRIMITIVE_TABLE); if (edgeTable == null || edgeTable.getNumRecords() == 0) { return; } VPFBufferedRecordData mbrTable = this.createPrimitiveTable(coverage, tile, VPFConstants.EDGE_BOUNDING_RECTANGLE_TABLE); if (mbrTable == null) { return; } int numEdges = edgeTable.getNumRecords(); VPFPrimitiveData.EdgeInfo[] edgeInfo = new VPFPrimitiveData.EdgeInfo[numEdges]; VecBufferSequence coords = (VecBufferSequence)edgeTable.getRecordData( "coordinates").getBackingData(); foreach (VPFRecord row in edgeTable) { int id = row.getId(); VPFRecord mbrRow = mbrTable.getRecord(id); edgeInfo[VPFBufferedRecordData.indexFromId(id)] = new VPFPrimitiveData.EdgeInfo( getNumber(row.getValue("edge_type")), getId(row.getValue("start_node")), getNumber(row.getValue("end_node")), getId(row.getValue("left_face")), getId(row.getValue("right_face")), getId(row.getValue("left_edge")), getId(row.getValue("right_edge")), isEdgeOnTileBoundary(row), VPFUtils.getExtent(mbrRow)); } primitiveData.setPrimitiveInfo(VPFConstants.EDGE_PRIMITIVE_TABLE, edgeInfo); primitiveData.setPrimitiveCoords(VPFConstants.EDGE_PRIMITIVE_TABLE, coords); }
public static void checkAndSetValue(VPFRecord record, String paramName, String paramKey, AVList parameters) { if (record == null) { String message = Logging.getMessage("nullValue.RecordIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (paramName == null) { String message = Logging.getMessage("nullValue.ParameterNameIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (paramKey == null) { String message = Logging.getMessage("nullValue.ParameterKeyIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (params == null) { String message = Logging.getMessage("nullValue.ParamsIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (record.hasValue(paramName)) { Object o = record.getValue(paramName); if (o != null) { parameters.setValue(paramKey, o); } } }
/** * Constructs a VPF Coverage from a specified VPF Library and coverage name. This initializes the Coverage's Feature * Class Schema table, the Feature Class Attribute table, the Character Value Description table, the Integer Value * Descrption table, and the Symbol Related Attribute table. * * @param library the Library which the Coverage resides in. * @param name the Coverage's name. * * @return a new Coverage from the specified Library with the specified name. * * @throws ArgumentException if the library is null, or if the name is null or empty. */ public static VPFCoverage fromFile(VPFLibrary library, String name) { if (library == null) { String message = Logging.getMessage("nullValue.LibraryIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (WWUtil.isEmpty(name)) { String message = Logging.getMessage("nullValue.NameIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } File file = new File(library.getFilePath(), name); if (!file.exists()) { String message = Logging.getMessage("generic.FileNotFound", file.getPath()); Logging.logger().severe(message); throw new WWRuntimeException(message); } // Coverage tables. VPFBufferedRecordData fcs = VPFUtils.readTable(new File(file, VPFConstants.FEATURE_CLASS_SCHEMA_TABLE)); if (fcs == null) { String message = Logging.getMessage("VPF.FeatureClassSchemaTableMissing"); throw new WWRuntimeException(message); } VPFBufferedRecordData fca = VPFUtils.readTable( new File(file, VPFConstants.FEATURE_CLASS_ATTRIBUTE_TABLE)); VPFBufferedRecordData char_vdt = VPFUtils.readTable( new File(file, VPFConstants.CHARACTER_VALUE_DESCRIPTION_TABLE)); VPFBufferedRecordData int_vdt = VPFUtils.readTable( new File(file, VPFConstants.INTEGER_VALUE_DESCRIPTION_TABLE)); VPFBufferedRecordData symbol_rat = VPFUtils.readTable( new File(file, "symbol" + VPFConstants.RELATED_ATTRIBUTE_TABLE)); VPFCoverage coverage = new VPFCoverage(library); coverage.setFeatureClassSchemaTable(fcs); coverage.setFeatureClassAttributeTable(fca); coverage.setCharacterValueDescriptionTable(char_vdt); coverage.setIntegerValueDescriptionTable(int_vdt); coverage.setSymbolRelatedAttributeTable(symbol_rat); // Coverage metadata attributes. VPFRecord record = library.getCoverageAttributeTable().getRecord("coverage_name", name); if (record != null) { VPFUtils.checkAndSetValue(record, "coverage_name", AVKey.DISPLAY_NAME, coverage); VPFUtils.checkAndSetValue(record, "description", AVKey.DESCRIPTION, coverage); } return(coverage); }
protected VPFFeature createCompoundSimpleFeature(VPFFeatureClass featureClass, VPFRecord featureRow, VPFBufferedRecordData joinTable, Iterable <String> attributeKeys) { // Feature has a direct 1:* relation to the primitive table through a join table. // Query the number of primitives which match the feature. Object o = this.getPrimitiveIds(featureClass, featureRow, joinTable, null, true); if (o == null || !(o is Integer)) { return(null); } int numPrimitives = (Integer)o; if (numPrimitives < 1) { return(null); } // Gather the actual primitive ids matching the feature. int[] primitiveIds = new int[numPrimitives]; VPFBoundingBox bounds = (VPFBoundingBox)this.getPrimitiveIds(featureClass, featureRow, joinTable, primitiveIds, false); return(this.createFeature(featureClass, featureRow, attributeKeys, bounds, primitiveIds)); }
/** * Constructs a VPF Library from the specified VPF Database and library name. This initializes the Library Header * Table, the Coverage Attribute Table, and the Geographic Reference Table. * * @param database the Database which the Library resides in. * @param name the Library's name. * * @return a new Library from the specified Database with the specified name. * * @throws ArgumentException if the database is null, or if the name is null or empty. */ public static VPFLibrary fromFile(VPFDatabase database, String name) { if (database == null) { String message = Logging.getMessage("nullValue.DatabaseIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (WWUtil.isEmpty(name)) { String message = Logging.getMessage("nullValue.NameIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } File file = new File(database.getFilePath(), name); if (!file.exists()) { String message = Logging.getMessage("generic.FileNotFound", file.getPath()); Logging.logger().severe(message); throw new WWRuntimeException(message); } // Library tables. VPFBufferedRecordData lht = VPFUtils.readTable(new File(file, VPFConstants.LIBRARY_HEADER_TABLE)); if (lht == null) { String message = Logging.getMessage("VPF.LibraryHeaderTableMissing"); throw new WWRuntimeException(message); } VPFBufferedRecordData cat = VPFUtils.readTable(new File(file, VPFConstants.COVERAGE_ATTRIBUTE_TABLE)); if (cat == null) { String message = Logging.getMessage("VPF.CoverageAttributeTableMissing"); throw new WWRuntimeException(message); } VPFBufferedRecordData grt = VPFUtils.readTable(new File(file, VPFConstants.GEOGRAPHIC_REFERENCE_TABLE)); if (grt == null) { String message = Logging.getMessage("VPF.GeographicReferenceTableMissing"); throw new WWRuntimeException(message); } VPFLibrary library = new VPFLibrary(database); library.setLibraryHeaderTable(lht); library.setCoverageAttributeTable(cat); library.setGeographicReferenceTable(grt); // Library metadata attributes. VPFRecord record = database.getLibraryAttributeTable().getRecord("library_name", name); if (record != null) { library.bounds = VPFUtils.getExtent(record); } record = lht.getRecord(1); if (record != null) { VPFUtils.checkAndSetValue(record, "library_name", AVKey.DISPLAY_NAME, library); VPFUtils.checkAndSetValue(record, "description", AVKey.DESCRIPTION, library); } // Library Coverages. Collection <VPFCoverage> col = createCoverages(library, cat); if (col != null) { library.setCoverages(col); } // Library tiles. VPFCoverage cov = library.getCoverage(VPFConstants.TILE_REFERENCE_COVERAGE); if (cov != null) { VPFTile[] tiles = createTiles(cov); if (tiles != null) { library.setTiles(tiles); } else { String message = Logging.getMessage("VPF.NoTilesInTileReferenceCoverage"); Logging.logger().warning(message); } } // Coverage tiled attributes. foreach (VPFCoverage coverage in library.getCoverages()) { bool tiled = isCoverageTiled(library, coverage); coverage.setTiled(tiled); } return(library); }
protected void buildFacePrimitives(VPFCoverage coverage, VPFTile tile, VPFPrimitiveData primitiveData) { VPFBufferedRecordData faceTable = this.createPrimitiveTable(coverage, tile, VPFConstants.FACE_PRIMITIVE_TABLE); if (faceTable == null) { return; } VPFBufferedRecordData mbrTable = this.createPrimitiveTable(coverage, tile, VPFConstants.FACE_BOUNDING_RECTANGLE_TABLE); if (mbrTable == null) { return; } VPFBufferedRecordData ringTable = this.createPrimitiveTable(coverage, tile, VPFConstants.RING_TABLE); if (ringTable == null) { return; } VPFPrimitiveData.PrimitiveInfo[] edgeInfo = primitiveData.getPrimitiveInfo(VPFConstants.EDGE_PRIMITIVE_TABLE); int numFaces = faceTable.getNumRecords(); VPFPrimitiveData.FaceInfo[] faceInfo = new VPFPrimitiveData.FaceInfo[numFaces]; foreach (VPFRecord faceRow in faceTable) { int faceId = faceRow.getId(); VPFRecord mbrRow = mbrTable.getRecord(faceId); // Face ID 1 is reserved for the "universe face", which does not have any associated geometry. if (faceId == 1) { continue; } // The first ring primitive associated with the face primitive defines the outer ring. The face primitive must // at least contain coordinates for an outer ring. int ringId = ((Number)faceRow.getValue("ring_ptr")).intValue(); VPFRecord ringRow = ringTable.getRecord(ringId); VPFPrimitiveData.Ring outerRing = this.buildRing(ringRow, edgeInfo); // The ring table maintains an order relationship for its rows. The first record of a new face id will always // be defined as the outer ring. Any repeating records with an identical face value will define inner rings. ArrayList <VPFPrimitiveData.Ring> innerRingList = new ArrayList <VPFPrimitiveData.Ring>(); for (ringId = ringId + 1; ringId <= ringTable.getNumRecords(); ringId++) { ringRow = ringTable.getRecord(ringId); // Break on the first ring primitive row which isn't associated with the face. Because the ring rows // maintain an ordering with respect to face id, there will be no other ring rows corresponding to this // face. if (faceId != getId(ringRow.getValue("face_id"))) { break; } VPFPrimitiveData.Ring innerRing = this.buildRing(ringRow, edgeInfo); if (innerRing != null) { innerRingList.add(innerRing); } } VPFPrimitiveData.Ring[] innerRings = new VPFPrimitiveData.Ring[innerRingList.size()]; innerRingList.toArray(innerRings); faceInfo[VPFBufferedRecordData.indexFromId(faceId)] = new VPFPrimitiveData.FaceInfo( outerRing, innerRings, VPFUtils.getExtent(mbrRow)); } primitiveData.setPrimitiveInfo(VPFConstants.FACE_PRIMITIVE_TABLE, faceInfo); }