Hello,

I am quite new in the geotools usergroup. First of all I want to say that 
geotools is a really nice library with very interesting and useful functions.

In my actual project i worked with the indexed shapefile datastore. 

In my tests the reading of point shapefile data seemed to be quite slow when 
using the quadtree-index. When I searched for a solution I debugged the class 
"ShapeFileIndexer.java". I found out that the BoundingBox of the of the points 
was wrong.
Maybe someone wants to check out if it is really a bug or if the shapefiles 
itself make the problems. They where generated with a software called FME.

The following workaround in the ShapeFileIndexer.java solved my problems (Look 
for the comment "Workaround":

///////////////////////////////////////////////////////////////////////////////////////////////////////
    private int buildQuadTree(ShapefileReader reader, File file, 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'!");
        }

        String ext = this.fileName.substring(this.fileName.lastIndexOf('.'));

        String idxFileName = this.fileName.substring(0,
                this.fileName.length() - 4)
            + (ext.equals(".shp") ? ".shx" : ".SHX");

        FileInputStream fisIdx = new FileInputStream(idxFileName);
        FileChannel channelIdx = fisIdx.getChannel();
        IndexFile shpIndex = new IndexFile(channelIdx);
        QuadTree tree=null;
        int cnt = 0;
        try{
        int numRecs = shpIndex.getRecordCount();
        ShapefileHeader header = reader.getHeader();
        Envelope bounds = new Envelope(header.minX(), header.maxX(),
                header.minY(), header.maxY());

        tree = new QuadTree(numRecs, bounds, shpIndex);

        Record rec = null;

        while (reader.hasNext()) {
            rec = reader.nextRecord();
            
            /////Workarround
                ////because of wrong boundingbox at points
            if(header.getShapeType()==ShapeType.POINT){
                rec.maxX=rec.minX;
                rec.maxY=rec.minY;
            }
            
            tree.insert(cnt++,
                new Envelope(rec.minX, rec.maxX, rec.minY, rec.maxY));

            if (verbose && ((cnt % 500) == 0)) {
                System.out.print('.');
            }
        }
        }finally{
        channelIdx.close();
        fisIdx.close();
        shpIndex.close();
        }
        FileSystemIndexStore store = new FileSystemIndexStore(file, order);
        store.store(tree);

        return cnt;
    }
///////////////////////////////////////////////////////////////////////////////////////////
--
RIWA GmbH 
Gesellschaft für Geoinformationen 
Sitz der Gesellschaft : Zwingerstrasse 1, 87435 Kempten (Allgäu)
Registergericht : Amtsgericht Kempten, HRB 6480
Geschäftsführer : Dipl.-Ing. Günter Kraus


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to