Search in sources :

Example 1 with FileSystemIndexStore

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;
}
Also used : FileSystemIndexStore(org.geotoolkit.index.quadtree.fs.FileSystemIndexStore) QuadTree(org.geotoolkit.index.quadtree.QuadTree) ShapefileHeader(org.geotoolkit.data.shapefile.shp.ShapefileHeader) DataReader(org.geotoolkit.index.quadtree.DataReader) ShxReader(org.geotoolkit.data.shapefile.shx.ShxReader) Record(org.geotoolkit.data.shapefile.shp.ShapefileReader.Record) Envelope(org.locationtech.jts.geom.Envelope) StoreException(org.geotoolkit.index.quadtree.StoreException) DataStoreException(org.apache.sis.storage.DataStoreException)

Example 2 with FileSystemIndexStore

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;
}
Also used : FileSystemIndexStore(org.geotoolkit.index.quadtree.fs.FileSystemIndexStore)

Example 3 with FileSystemIndexStore

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);
    }
}
Also used : AccessManager(org.geotoolkit.data.shapefile.lock.AccessManager) FileSystemIndexStore(org.geotoolkit.index.quadtree.fs.FileSystemIndexStore) IndexDataReader(org.geotoolkit.data.shapefile.indexed.IndexDataReader) ShxReader(org.geotoolkit.data.shapefile.shx.ShxReader) ShpFiles(org.geotoolkit.data.shapefile.lock.ShpFiles) IndexDataReader(org.geotoolkit.data.shapefile.indexed.IndexDataReader) IOException(java.io.IOException) File(java.io.File)

Aggregations

FileSystemIndexStore (org.geotoolkit.index.quadtree.fs.FileSystemIndexStore)3 ShxReader (org.geotoolkit.data.shapefile.shx.ShxReader)2 File (java.io.File)1 IOException (java.io.IOException)1 DataStoreException (org.apache.sis.storage.DataStoreException)1 IndexDataReader (org.geotoolkit.data.shapefile.indexed.IndexDataReader)1 AccessManager (org.geotoolkit.data.shapefile.lock.AccessManager)1 ShpFiles (org.geotoolkit.data.shapefile.lock.ShpFiles)1 ShapefileHeader (org.geotoolkit.data.shapefile.shp.ShapefileHeader)1 Record (org.geotoolkit.data.shapefile.shp.ShapefileReader.Record)1 DataReader (org.geotoolkit.index.quadtree.DataReader)1 QuadTree (org.geotoolkit.index.quadtree.QuadTree)1 StoreException (org.geotoolkit.index.quadtree.StoreException)1 Envelope (org.locationtech.jts.geom.Envelope)1