Search in sources :

Example 6 with IndexedShapefileFeatureStore

use of org.geotoolkit.data.shapefile.indexed.IndexedShapefileFeatureStore in project geotoolkit by Geomatys.

the class ShapefileProvider method open.

/**
 * {@inheritDoc }
 */
@Override
public ShapefileFeatureStore open(final ParameterValueGroup params) throws DataStoreException {
    ensureCanProcess(params);
    final URI uri = (URI) params.parameter(PATH.getName().toString()).getValue();
    Boolean isMemoryMapped = (Boolean) params.parameter(MEMORY_MAPPED.getName().toString()).getValue();
    Charset dbfCharset = (Charset) params.parameter(DBFCHARSET.getName().toString()).getValue();
    Boolean isCreateSpatialIndex = (Boolean) params.parameter(CREATE_SPATIAL_INDEX.getName().toString()).getValue();
    if (isCreateSpatialIndex == null) {
        // should not be needed as default is TRUE
        isCreateSpatialIndex = Boolean.TRUE;
    }
    if (dbfCharset == null) {
        // this should not happen as Charset.forName("ISO-8859-1") was used
        // as the param default?
        dbfCharset = Charset.forName("ISO-8859-1");
    }
    if (isMemoryMapped == null) {
        isMemoryMapped = Boolean.FALSE;
    }
    // index loading hints
    final Boolean loadQix = (Boolean) params.parameter(LOAD_QIX.getName().toString()).getValue();
    final ShpFiles shpFiles;
    try {
        shpFiles = new ShpFiles(uri, (loadQix == null) ? false : loadQix);
    } catch (IllegalArgumentException ex) {
        throw new DataStoreException(ex.getMessage(), ex);
    }
    if (!shpFiles.exists(ShpFileType.SHP)) {
        throw new DataStoreException("Shapefile not found:" + shpFiles.get(ShpFileType.SHP));
    }
    final boolean isWritable = shpFiles.isWritable();
    final boolean useMemoryMappedBuffer = shpFiles.exists(ShpFileType.SHP) && isMemoryMapped;
    final boolean createIndex = isCreateSpatialIndex && isWritable;
    IndexType treeIndex = IndexType.NONE;
    if (isWritable) {
        if (createIndex) {
            // default
            treeIndex = IndexType.QIX;
        } else {
            // lets check and see if any index file is avaialble
            if (shpFiles.exists(ShpFileType.QIX)) {
                treeIndex = IndexType.QIX;
            }
        }
    }
    try {
        if (createIndex) {
            return new IndexedShapefileFeatureStore(uri, useMemoryMappedBuffer, createIndex, IndexType.QIX, dbfCharset);
        } else if (treeIndex != IndexType.NONE) {
            return new IndexedShapefileFeatureStore(uri, useMemoryMappedBuffer, false, treeIndex, dbfCharset);
        } else {
            return new ShapefileFeatureStore(uri, useMemoryMappedBuffer, dbfCharset);
        }
    } catch (MalformedURLException mue) {
        throw new DataStoreException("Url for shapefile malformed: " + uri, mue);
    }
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) MalformedURLException(java.net.MalformedURLException) ShpFiles(org.geotoolkit.data.shapefile.lock.ShpFiles) Charset(java.nio.charset.Charset) IndexedShapefileFeatureStore(org.geotoolkit.data.shapefile.indexed.IndexedShapefileFeatureStore) IndexedShapefileFeatureStore(org.geotoolkit.data.shapefile.indexed.IndexedShapefileFeatureStore) IndexType(org.geotoolkit.data.shapefile.indexed.IndexType) URI(java.net.URI)

Example 7 with IndexedShapefileFeatureStore

use of org.geotoolkit.data.shapefile.indexed.IndexedShapefileFeatureStore in project geotoolkit by Geomatys.

the class PolygonLazySearchCollectionTest method setUp.

@Before
public void setUp() throws Exception {
    file = copyShapefiles("shapes/statepop.shp");
    ds = new IndexedShapefileFeatureStore(file.toURI());
    ds.buildQuadTree(0);
    final Object[] v = LineLazySearchCollectionTest.openQuadTree(file);
    tree = (QuadTree) v[0];
    dr = (DataReader) v[1];
    crs = FeatureExt.getCRS(ds.getFeatureType(ds.getNames().iterator().next().toString()));
}
Also used : IndexedShapefileFeatureStore(org.geotoolkit.data.shapefile.indexed.IndexedShapefileFeatureStore) Before(org.junit.Before)

Aggregations

IndexedShapefileFeatureStore (org.geotoolkit.data.shapefile.indexed.IndexedShapefileFeatureStore)7 Before (org.junit.Before)3 MalformedURLException (java.net.MalformedURLException)2 URI (java.net.URI)2 Charset (java.nio.charset.Charset)2 DataStoreException (org.apache.sis.storage.DataStoreException)2 ShpFiles (org.geotoolkit.data.shapefile.lock.ShpFiles)2 FeatureIterator (org.geotoolkit.storage.feature.FeatureIterator)2 Query (org.geotoolkit.storage.feature.query.Query)2 Test (org.junit.Test)2 Feature (org.opengis.feature.Feature)2 LinkedHashSet (java.util.LinkedHashSet)1 TreeSet (java.util.TreeSet)1 IndexType (org.geotoolkit.data.shapefile.indexed.IndexType)1