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);
}
}
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()));
}
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()));
}
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);
}
}
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);
}
}
Aggregations