001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data.vpf;
017:
018: import java.io.File;
019: import java.io.IOException;
020: import java.util.Iterator;
021: import java.util.List;
022: import java.util.Vector;
023:
024: import org.geotools.data.vpf.file.VPFFile;
025: import org.geotools.data.vpf.file.VPFFileFactory;
026: import org.geotools.data.vpf.ifc.FileConstants;
027: import org.geotools.feature.Feature;
028: import org.geotools.feature.SchemaException;
029:
030: /**
031: * This class is not completely implemented due to a decision that the
032: * VPFDataStore shall correspond to the VPFLibrary class, not this class
033: *
034: * @author <a href="mailto:kobit@users.sourceforge.net">Artur Hefczyc</a>
035: * @author <a href="mailto:knuterik@onemap.org">Knut-Erik Johnsen</a>, Project
036: * OneMap
037: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/vpf/src/main/java/org/geotools/data/vpf/VPFDataBase.java $
038: * @version $Id: VPFDataBase.java 22482 2006-10-31 02:58:00Z desruisseaux $
039: */
040: public class VPFDataBase implements FileConstants {
041: /**
042: * The libraries in the database
043: */
044: private final List libraries = new Vector();
045:
046: /**
047: * Constructor
048: * @param directory A <code>File</code> representing the base directory of the database
049: * @throws IOException
050: * @throws SchemaException
051: */
052: public VPFDataBase(File directory) throws IOException,
053: SchemaException {
054: VPFFile vpfTable;
055: String vpfTableName;
056: Feature feature;
057: VPFLibrary library;
058:
059: // read libraries info
060: vpfTableName = new File(directory, LIBRARY_ATTTIBUTE_TABLE)
061: .toString();
062: vpfTable = VPFFileFactory.getInstance().getFile(vpfTableName);
063:
064: Iterator iter = vpfTable.readAllRows().iterator();
065:
066: while (iter.hasNext()) {
067: feature = (Feature) iter.next();
068:
069: try {
070: library = new VPFLibrary(feature, directory);
071: libraries.add(library);
072: } catch (java.io.FileNotFoundException ex) {
073: // This must be a partial data set - the library wasn't found so just ignore it
074: }
075: }
076:
077: // // read data base header info
078: // //this.directory = directory;
079: // String vpfTableName = new File(directory, DATABASE_HEADER_TABLE).toString();
080: // VPFFile vpfTable = VPFFileFactory.getInstance().getFile(vpfTableName);
081: // vpfTable.reset();
082: // Feature dataBaseInfo = (Feature) vpfTable.readFeature();
083: //// vpfTable.close();
084: //
085: // // read libraries info
086: // vpfTableName = new File(directory, LIBRARY_ATTTIBUTE_TABLE).toString();
087: // vpfTable = VPFFileFactory.getInstance().getFile(vpfTableName);
088: //
089: // Iterator iter = vpfTable.readAllRows().iterator();
090: // while(iter.hasNext()){
091: //
092: // }
093: //// vpfTable.close();
094: //
095: // TableRow[] libraries_tmp = (TableRow[]) list.toArray(new TableRow[list.size()]);
096: // libraries = new VPFLibrary[libraries_tmp.length];
097: //
098: // for (int i = 0; i < libraries_tmp.length; i++) {
099: // libraries[i] = new VPFLibrary(libraries_tmp[i], directory, this);
100: // }
101: }
102:
103: /**
104: * Returns the libraries that are in the database
105: * @return a <code>List</code> containing <code>VPFLibrary</code> objects
106: */
107: public List getLibraries() {
108: return libraries;
109: }
110:
111: /**
112: * Returns the minimum X value of the database
113: * @return a <code>double</code> value
114: */
115: public double getMinX() {
116: double result = Double.NaN;
117: Iterator iter = libraries.iterator();
118: VPFLibrary library;
119:
120: if (iter.hasNext()) {
121: library = (VPFLibrary) iter.next();
122: result = library.getXmin();
123: }
124:
125: while (iter.hasNext()) {
126: library = (VPFLibrary) iter.next();
127: result = Math.min(result, library.getXmin());
128: }
129:
130: return result;
131: }
132:
133: /**
134: * Returns the minimum X value of the database
135: * @return a <code>double</code> value
136: */
137: public double getMinY() {
138: double result = Double.NaN;
139: Iterator iter = libraries.iterator();
140: VPFLibrary library;
141:
142: if (iter.hasNext()) {
143: library = (VPFLibrary) iter.next();
144: result = library.getYmin();
145: }
146:
147: while (iter.hasNext()) {
148: library = (VPFLibrary) iter.next();
149: result = Math.min(result, library.getYmin());
150: }
151:
152: return result;
153: }
154:
155: /**
156: * Returns the minimum X value of the database
157: * @return a <code>double</code> value
158: */
159: public double getMaxX() {
160: double result = Double.NaN;
161: Iterator iter = libraries.iterator();
162: VPFLibrary library;
163:
164: if (iter.hasNext()) {
165: library = (VPFLibrary) iter.next();
166: result = library.getXmax();
167: }
168:
169: while (iter.hasNext()) {
170: library = (VPFLibrary) iter.next();
171: result = Math.max(result, library.getXmax());
172: }
173:
174: return result;
175: }
176:
177: /**
178: * Returns the minimum X value of the database
179: * @return a <code>double</code> value
180: */
181: public double getMaxY() {
182: double result = Double.NaN;
183: Iterator iter = libraries.iterator();
184: VPFLibrary library;
185:
186: if (iter.hasNext()) {
187: library = (VPFLibrary) iter.next();
188: result = library.getYmax();
189: }
190:
191: while (iter.hasNext()) {
192: library = (VPFLibrary) iter.next();
193: result = Math.max(result, library.getYmax());
194: }
195:
196: return result;
197: }
198:
199: /*
200: * (non-Javadoc)
201: * @see java.lang.Object#toString()
202: */
203: public String toString() {
204: return "VPF database with the following extents: \n"
205: + getMinX() + " " + getMinY() + " - " + getMaxX() + " "
206: + getMinY() + "\n";
207: }
208:
209: // public VPFFeatureClass getFeatureClass(String typename) {
210: // VPFFeatureClass tmp = null;
211: //
212: // for (int i = 0; i < libraries.length; i++) {
213: // tmp = libraries[i].getFeatureClass(typename);
214: //
215: // if (tmp != null) {
216: // return tmp;
217: // }
218: // }
219: //
220: // return null;
221: // }
222: }
|