use of org.geotoolkit.data.shapefile.fix.IndexedFidReader in project geotoolkit by Geomatys.
the class AccessManager method getFIXReader.
public IndexedFidReader getFIXReader(final RecordNumberTracker tracker) throws IOException {
final URI url = files.getURI(ShpFileType.FIX);
final ReadableByteChannel rbc = toClosingChannel(files.getReadChannel(url), false);
final IndexedFidReader reader = new IndexedFidReader(url, rbc, tracker);
readEntries.add(new AccessEntry(ShpFileType.FIX, url, reader));
return reader;
}
use of org.geotoolkit.data.shapefile.fix.IndexedFidReader in project geotoolkit by Geomatys.
the class IndexedFidWriterTest method testRemoveCounting.
@Test
public void testRemoveCounting() throws Exception {
final AccessManager locker = shpFiles.createLocker();
IndexedFidWriter.generate(backshp.toURI().toURL());
initWriter();
writer.next();
writer.remove();
writer.next();
writer.remove();
writer.next();
writer.remove();
while (writer.hasNext()) {
writer.next();
writer.write();
}
close();
IndexedFidReader reader = locker.getFIXReader(null);
try {
assertEquals(3, reader.getRemoves());
} finally {
reader.close();
}
// remove some more features
initWriter();
writer.next();
writer.next();
writer.next();
writer.remove();
writer.next();
writer.remove();
writer.next();
writer.next();
writer.next();
writer.remove();
while (writer.hasNext()) {
writer.next();
writer.write();
}
close();
reader = locker.getFIXReader(null);
try {
assertEquals(6, reader.getRemoves());
} finally {
reader.close();
}
}
use of org.geotoolkit.data.shapefile.fix.IndexedFidReader in project geotoolkit by Geomatys.
the class FidIndexerTest method testGenerate.
/*
* Test method for 'org.geotoolkit.index.fid.FidIndexer.generate(URL)'
*/
@Test
public void testGenerate() throws Exception {
final ShpFiles shpFiles = new ShpFiles(backshp.toURI().toURL());
IndexedFidWriter.generate(shpFiles);
final AccessManager locker = shpFiles.createLocker();
final IndexedShapefileFeatureStore ds = new IndexedShapefileFeatureStore(backshp.toURI(), false, false, IndexType.NONE, null);
long features = ds.getCount(new Query(ds.getNames().iterator().next()));
final IndexedFidReader reader = locker.getFIXReader(null);
try {
assertEquals(features, reader.getCount());
int i = 1;
while (reader.hasNext()) {
assertEquals(shpFiles.getTypeName() + "." + i, reader.next());
assertEquals(shpFiles.getTypeName() + "." + i, i - 1, reader.currentSHXIndex());
i++;
}
assertEquals(features, i - 1);
} finally {
reader.close();
}
}
use of org.geotoolkit.data.shapefile.fix.IndexedFidReader in project geotoolkit by Geomatys.
the class IndexedShapefileFeatureStore method queryFidIndex.
/**
* Uses the Fid index to quickly lookup the shp offset and the record number
* for the list of fids
*
* @param fids
* the fids of the features to find. If the set is sorted by alphabet the performance is likely to be better.
* @return a list of Data objects
*/
private CloseableCollection<ShpData> queryFidIndex(final Set<String> idsSet) throws IOException {
if (!indexUseable(FIX)) {
return null;
}
final AccessManager locker = shpFiles.createLocker();
final IndexedFidReader reader = locker.getFIXReader(null);
final CloseableCollection<ShpData> records = new CloseableArrayList(idsSet.size());
try {
final ShxReader shx = locker.getSHXReader(useMemoryMappedBuffer);
try {
for (String fid : idsSet) {
long recno = reader.findFid(fid);
if (recno == -1) {
if (getLogger().isLoggable(Level.FINEST)) {
getLogger().finest("fid " + fid + " not found in index, continuing with next queried fid...");
}
continue;
}
try {
ShpData data = new ShpData((int) (recno + 1), (long) shx.getOffsetInBytes((int) recno));
if (getLogger().isLoggable(Level.FINEST)) {
getLogger().finest("fid " + fid + " found for record #" + data.getValue(0) + " at index file offset " + data.getValue(1));
}
records.add(data);
} catch (Exception e) {
throw new IOException(e);
}
}
} finally {
shx.close();
}
} finally {
reader.close();
}
return records;
}
Aggregations