use of org.geotoolkit.index.quadtree.fs.FileSystemIndexStore in project geotoolkit by Geomatys.
the class ShapeFileIndexer method buildQuadTree.
private int buildQuadTree(final AccessManager locker, final ShapefileReader reader, final Path file, final boolean verbose) throws IOException, StoreException {
byte order = 0;
if ((this.byteOrder == null) || this.byteOrder.equalsIgnoreCase("NM")) {
order = IndexHeader.NEW_MSB_ORDER;
} else if (this.byteOrder.equalsIgnoreCase("NL")) {
order = IndexHeader.NEW_LSB_ORDER;
} else {
throw new StoreException("Asked byte order '" + this.byteOrder + "' must be 'NL' or 'NM'!");
}
final ShxReader shpIndex = locker.getSHXReader(false);
QuadTree tree = null;
int cnt = 0;
int numRecs = shpIndex.getRecordCount();
ShapefileHeader header = reader.getHeader();
Envelope bounds = new Envelope(header.minX(), header.maxX(), header.minY(), header.maxY());
DataReader dr = new IndexDataReader(shpIndex);
tree = new QuadTree(numRecs, max, bounds);
try {
Record rec = null;
while (reader.hasNext()) {
rec = reader.nextRecord();
tree.insert(cnt++, new Envelope(rec.minX, rec.maxX, rec.minY, rec.maxY));
if (verbose && ((cnt % 1000) == 0)) {
System.out.print('.');
}
if (cnt % 100000 == 0)
System.out.print('\n');
}
if (verbose)
System.out.println("done");
FileSystemIndexStore store = new FileSystemIndexStore(file, order);
store.store(tree);
} finally {
tree.close();
}
return cnt;
}
use of org.geotoolkit.index.quadtree.fs.FileSystemIndexStore in project geotoolkit by Geomatys.
the class ShpFiles method getQIX.
public synchronized QuadTree getQIX() throws StoreException {
if (quadTree == null) {
if (!isWritable()) {
return null;
}
final URI treeURI = getURI(QIX);
try {
final Path treePath = IOUtilities.toPath(treeURI);
if (!Files.exists(treePath) || (Files.size(treePath) == 0)) {
return null;
}
if (qixStore == null) {
qixStore = new FileSystemIndexStore(treePath);
}
if (loadQuadTree) {
// we store the quad tree for reuse
quadTree = qixStore.load();
quadTree.loadAll();
return quadTree;
} else {
return qixStore.load();
}
} catch (IOException ex) {
LOGGER.log(Level.WARNING, "Failed to get quad tree.", ex);
return null;
}
}
return quadTree;
}
use of org.geotoolkit.index.quadtree.fs.FileSystemIndexStore in project geotoolkit by Geomatys.
the class LineLazySearchCollectionTest method openQuadTree.
public static Object[] openQuadTree(final File file) throws StoreException {
File qixFile = sibling(file, "qix");
FileSystemIndexStore store = new FileSystemIndexStore(qixFile);
try {
final ShpFiles shpFiles = new ShpFiles(qixFile);
final AccessManager locker = shpFiles.createLocker();
final ShxReader indexFile = locker.getSHXReader(false);
final DataReader dr = new IndexDataReader(indexFile);
return new Object[] { store.load(), dr };
} catch (IOException e) {
throw new StoreException(e);
}
}
Aggregations