Search in sources :

Example 26 with AccessManager

use of org.geotoolkit.data.shapefile.lock.AccessManager in project geotoolkit by Geomatys.

the class IndexedFidWriter method generate.

/**
 * Generates the FID index file for the shpFiles
 */
public static void generate(final ShpFiles shpFiles) throws IOException {
    LOGGER.log(Level.FINE, "Generating fids for {0}", shpFiles.get(SHP));
    final AccessManager locker = shpFiles.createLocker();
    ShxReader indexFile = null;
    StorageFile file = locker.getStorageFile(FIX);
    try {
        indexFile = locker.getSHXReader(false);
        // writer closes channel for you.
        final IndexedFidWriter writer = locker.getFIXWriter(file);
        for (int i = 0, j = indexFile.getRecordCount(); i < j; i++) {
            writer.next();
        }
    } finally {
        try {
            locker.disposeReaderAndWriters();
            locker.replaceStorageFiles();
        } finally {
            if (indexFile != null) {
                indexFile.close();
            }
        }
    }
}
Also used : AccessManager(org.geotoolkit.data.shapefile.lock.AccessManager) ShxReader(org.geotoolkit.data.shapefile.shx.ShxReader) StorageFile(org.geotoolkit.data.shapefile.lock.StorageFile)

Aggregations

AccessManager (org.geotoolkit.data.shapefile.lock.AccessManager)26 ShpFiles (org.geotoolkit.data.shapefile.lock.ShpFiles)13 Test (org.junit.Test)11 ShapefileReader (org.geotoolkit.data.shapefile.shp.ShapefileReader)10 IOException (java.io.IOException)9 DataStoreException (org.apache.sis.storage.DataStoreException)8 StorageFile (org.geotoolkit.data.shapefile.lock.StorageFile)6 Geometry (org.locationtech.jts.geom.Geometry)5 AttributeType (org.opengis.feature.AttributeType)5 URL (java.net.URL)4 UnsupportedQueryException (org.apache.sis.storage.UnsupportedQueryException)4 ShpData (org.geotoolkit.data.shapefile.indexed.IndexDataReader.ShpData)4 ShxReader (org.geotoolkit.data.shapefile.shx.ShxReader)4 Closeable (java.io.Closeable)3 File (java.io.File)3 MalformedURLException (java.net.MalformedURLException)3 DbaseFileHeader (org.geotoolkit.data.dbf.DbaseFileHeader)3 DbaseFileReader (org.geotoolkit.data.dbf.DbaseFileReader)3 IndexedFidReader (org.geotoolkit.data.shapefile.fix.IndexedFidReader)3 JTSEnvelope2D (org.geotoolkit.geometry.jts.JTSEnvelope2D)3