Package org.geotools.data.shapefile.index.quadtree

Examples of org.geotools.data.shapefile.index.quadtree.QuadTree


     * <code>UnsupportedOperationException</code> will be thrown.
     *
     * @see org.geotools.index.quadtree.IndexStore#load()
     */
    public QuadTree load(IndexFile indexfile, boolean useMemoryMapping) throws StoreException {
        QuadTree tree = null;

        try {
            if (LOGGER.isLoggable(Level.FINEST)) {
                LOGGER.finest("Opening QuadTree "
                        + this.file.getCanonicalPath());
            }

            final FileInputStream fis = new FileInputStream(file);
            final FileChannel channel = fis.getChannel();

            IndexHeader header = new IndexHeader(channel);

            ByteOrder order = byteToOrder(header.getByteOrder());
            ByteBuffer buf = ByteBuffer.allocate(8);
            buf.order(order);
            channel.read(buf);
            buf.flip();

            tree = new QuadTree(buf.getInt(), buf.getInt(), indexfile) {
                public void insert(int recno, Envelope bounds) {
                    throw new UnsupportedOperationException(
                            "File quadtrees are immutable");
                }

                public boolean trim() {
                    return false;
                }

                public void close() throws StoreException {
                    super.close();
                    try {
                        channel.close();
                        fis.close();
                    } catch (IOException e) {
                        throw new StoreException(e);
                    }
                }
            };

            tree.setRoot(FileSystemNode.readNode(0, null, channel, order, useMemoryMapping));

            LOGGER.finest("QuadTree opened");
        } catch (IOException e) {
            throw new StoreException(e);
        }
View Full Code Here


            throw new StoreException("Asked byte order '" + this.byteOrder
                    + "' must be 'NL' or 'NM'!");
        }

        IndexFile shpIndex = new IndexFile(shpFiles, 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());

        tree = new QuadTree(numRecs, max, bounds, shpIndex);
        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);
           
            if(leafSize > 0) {
                if (LOGGER.isLoggable(Level.FINE)) {
                    LOGGER.fine("Optimizing the tree (this might take some time)");
                }
                optimizeTree(tree, tree.getRoot(), 0, reader, shpIndex);
                if (LOGGER.isLoggable(Level.FINE)) {
                    LOGGER.fine("Tree optimized");
                }
            }
           
            if(LOGGER.isLoggable(Level.FINE)) {
                printStats(tree);
            }
            store.store(tree);
        } finally {
            tree.close();
        }
        return cnt;
    }
View Full Code Here

            } finally {
                shpFiles.unlockRead(treeURL, writer);
            }

            if (canCache) {
                QuadTree quadTree = openQuadTree();
                if (quadTree != null) {
                    LOGGER.warning("Experimental: loading in memory the quadtree for "
                            + shpFiles.get(SHP));
                    cachedTree = new CachedQuadTree(quadTree);
                    quadTree.close();
                }
            }
        }
        if (cachedTree != null) {
            if (!bbox.contains(cachedTree.getBounds())) {
                return cachedTree.search(bbox);
            } else {
                return null;
            }
        } else {
            try {
                QuadTree quadTree = openQuadTree();
                if ((quadTree != null) && !bbox.contains(quadTree.getRoot().getBounds())) {
                    tmp = quadTree.search(bbox);
                }
                if (tmp == null && quadTree != null) {
                    quadTree.close();
                }
            } catch (Exception e) {
                throw new DataSourceException("Error querying QuadTree", e);
            }
        }
View Full Code Here

TOP

Related Classes of org.geotools.data.shapefile.index.quadtree.QuadTree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.