idx
extension,
store relations between tiles and object identifiers that belong to
these tiles. A class and a tool example are provided to generate these
spatial index files. A generic tile loader is also provided to minimize
the amount of code needed to implement the load-on-demand mechanism
using Shapefiles.dbf
reader:
the IlvShapeFileIndex class and the IlvShapeSpatialIndex class. A utility class is also provided to generate
the spatial index for a given Shapefile: the IlvShapeFileTiler class.// Open the index file. IlvShapeFileIndex index = new IlvShapeFileIndex("example.shx"); // Open the corresponding Shapefile. IlvSHPReader shape = new IlvSHPReader("example.shp"); // Retrieve the feature for each index. int count = index.getRecordCount(); for(int i = 0; i < count; i++) IlvMapFeature f = shape.getFeatureAt(i);
// Open the spatial index file. IlvShapeSpatialIndex spatialIndex = new IlvShapeSpatialIndex("example.shx"); // Loop on all columns and rows. for(int c = 0; c < spatialindex.getColumnCount(); c++) { for(int r = 0; r < spatialindex.getRowCount(); r++) { // Retrieve the IDs of objects belonging to the tile at row ‘r’ and // column ‘c’. int[] ids = spatialindex.getIdArray(c, r); // Loop on these IDs and get the corresponding map feature. for(int i =0; i < ids.length; i++) { IlvMapFeature f = shape.getFeatureAt(i); } } }
IlvShapeFileTiler.CreateShapeSpatialIndex("example.shp", "example.idx", 5., 10.);
SpatialIndexFile
named example.idx
with
a tile size of width 5 and height 10. IlvShapeFileTiler.CreateShapeSpatialIndex("example.shp", "example.idx", 20, 30);
SpatialIndexFile
of
600 tiles, 20 columns and 30 rows.