Search in sources :

Example 1 with IndexedShapefileFeatureStore

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

the class ShapefileProvider method create.

public ShapefileFeatureStore create(final ParameterValueGroup params) throws DataStoreException {
    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) {
        // this should not happen as false was the default
        isMemoryMapped = Boolean.FALSE;
    }
    final ShpFiles shpFiles = new ShpFiles(uri);
    final boolean isLocal = shpFiles.isWritable();
    if (!isLocal || shpFiles.exists(ShpFileType.SHP)) {
        LOGGER.fine("File already exists: " + shpFiles.get(ShpFileType.SHP));
    }
    final boolean useMemoryMappedBuffer = isLocal && isMemoryMapped.booleanValue();
    final boolean createIndex = isCreateSpatialIndex.booleanValue() && isLocal;
    try {
        if (createIndex) {
            return new IndexedShapefileFeatureStore(uri, useMemoryMappedBuffer, true, IndexType.QIX, dbfCharset);
        } else {
            return new ShapefileFeatureStore(uri, useMemoryMappedBuffer, dbfCharset);
        }
    } catch (MalformedURLException mue) {
        throw new DataStoreException("Uri for shapefile malformed: " + uri, mue);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) DataStoreException(org.apache.sis.storage.DataStoreException) 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) URI(java.net.URI)

Example 2 with IndexedShapefileFeatureStore

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

the class LineLazySearchCollectionTest method setUp.

@Before
public void setUp() throws Exception {
    file = copyShapefiles("shapes/streams.shp");
    ds = new IndexedShapefileFeatureStore(file.toURI());
    ds.buildQuadTree(0);
    final Object[] v = 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)

Example 3 with IndexedShapefileFeatureStore

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

the class PointLazySearchCollectionTest method setUp.

@Before
public void setUp() throws Exception {
    file = copyShapefiles("shapes/archsites.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)

Example 4 with IndexedShapefileFeatureStore

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

the class IndexedFidReaderTest method testFindAllFids.

@Test
public void testFindAllFids() throws Exception {
    int expectedCount = 0;
    final Set<String> expectedFids = new LinkedHashSet<>();
    final IndexedShapefileFeatureStore ds = new IndexedShapefileFeatureStore(backshp.toURI(), true, true, IndexType.NONE, null);
    final FeatureIterator features = ds.getFeatureReader(new Query(ds.getNames().iterator().next()));
    while (features.hasNext()) {
        final Feature next = features.next();
        expectedCount++;
        expectedFids.add(FeatureExt.getId(next).getIdentifier());
    }
    features.close();
    assertTrue(expectedCount > 0);
    assertEquals(expectedCount, reader.getCount());
    for (String fid : expectedFids) {
        final long offset = reader.findFid(fid);
        assertFalse(-1 == offset);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) Query(org.geotoolkit.storage.feature.query.Query) IndexedShapefileFeatureStore(org.geotoolkit.data.shapefile.indexed.IndexedShapefileFeatureStore) Feature(org.opengis.feature.Feature) Test(org.junit.Test)

Example 5 with IndexedShapefileFeatureStore

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

the class IndexedFidReaderTest method testFindAllFidsReverseOrder.

@Test
public void testFindAllFidsReverseOrder() throws Exception {
    int expectedCount = 0;
    final Set<String> expectedFids = new TreeSet<>(Collections.reverseOrder());
    final IndexedShapefileFeatureStore ds = new IndexedShapefileFeatureStore(backshp.toURI(), true, true, IndexType.NONE, null);
    final FeatureIterator features = ds.getFeatureReader(new Query(ds.getNames().iterator().next()));
    while (features.hasNext()) {
        final Feature next = features.next();
        expectedCount++;
        expectedFids.add(FeatureExt.getId(next).getIdentifier());
    }
    features.close();
    assertTrue(expectedCount > 0);
    assertEquals(expectedCount, reader.getCount());
    assertFalse("findFid for archsites.5 returned -1", -1 == reader.findFid("archsites.5"));
    assertFalse("findFid for archsites.25 returned -1", -1 == reader.findFid("archsites.25"));
    for (String fid : expectedFids) {
        final long offset = reader.findFid(fid);
        assertNotNull(offset);
        // System.out.println(fid + "=" + offset + ", ");
        assertFalse("findFid for " + fid + " returned -1", -1 == offset);
    }
}
Also used : FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) Query(org.geotoolkit.storage.feature.query.Query) TreeSet(java.util.TreeSet) IndexedShapefileFeatureStore(org.geotoolkit.data.shapefile.indexed.IndexedShapefileFeatureStore) Feature(org.opengis.feature.Feature) Test(org.junit.Test)

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