|
From: <mic...@ri...> - 2007-03-08 10:24:29
|
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.=20
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 =3D 0;
if ((this.byteOrder =3D=3D null) || =
this.byteOrder.equalsIgnoreCase("NM")) {
order =3D IndexHeader.NEW_MSB_ORDER;
} else if (this.byteOrder.equalsIgnoreCase("NL")) {
order =3D IndexHeader.NEW_LSB_ORDER;
} else {
throw new StoreException("Asked byte order '" + =
this.byteOrder
+ "' must be 'NL' or 'NM'!");
}
String ext =3D =
this.fileName.substring(this.fileName.lastIndexOf('.'));
String idxFileName =3D this.fileName.substring(0,
this.fileName.length() - 4)
+ (ext.equals(".shp") ? ".shx" : ".SHX");
FileInputStream fisIdx =3D new FileInputStream(idxFileName);
FileChannel channelIdx =3D fisIdx.getChannel();
IndexFile shpIndex =3D new IndexFile(channelIdx);
QuadTree tree=3Dnull;
int cnt =3D 0;
try{
int numRecs =3D shpIndex.getRecordCount();
ShapefileHeader header =3D reader.getHeader();
Envelope bounds =3D new Envelope(header.minX(), header.maxX(),
header.minY(), header.maxY());
tree =3D new QuadTree(numRecs, bounds, shpIndex);
Record rec =3D null;
while (reader.hasNext()) {
rec =3D reader.nextRecord();
=20
/////Workarround
////because of wrong boundingbox at points
if(header.getShapeType()=3D=3DShapeType.POINT){
rec.maxX=3Drec.minX;
rec.maxY=3Drec.minY;
}
=20
tree.insert(cnt++,
new Envelope(rec.minX, rec.maxX, rec.minY, rec.maxY));
if (verbose && ((cnt % 500) =3D=3D 0)) {
System.out.print('.');
}
}
}finally{
channelIdx.close();
fisIdx.close();
shpIndex.close();
}
FileSystemIndexStore store =3D new FileSystemIndexStore(file, =
order);
store.store(tree);
return cnt;
}
/////////////////////////////////////////////////////////////////////////=
//////////////////
--
RIWA GmbH=20
Gesellschaft f=FCr Geoinformationen=20
Sitz der Gesellschaft : Zwingerstrasse 1, 87435 Kempten (Allg=E4u)
Registergericht : Amtsgericht Kempten, HRB 6480
Gesch=E4ftsf=FChrer : Dipl.-Ing. G=FCnter Kraus
|