ShapefileDataStoreFactory implements FileDataStoreFactorySpi { public DataStore createDataStore(Map<String, Serializable> params) throws IOException { URL url = lookup(URLP, params, URL.class); Boolean isMemoryMapped = lookup(MEMORY_MAPPED, params, Boolean.class); Boolean cacheMemoryMaps = lookup(CACHE_MEMORY_MAPS, params, Boolean.class); URI namespace = lookup(NAMESPACEP, params, URI.class); Charset dbfCharset = lookup(DBFCHARSET, params, Charset.class); TimeZone dbfTimeZone = lookup(DBFTIMEZONE, params, TimeZone.class); Boolean isCreateSpatialIndex = lookup(CREATE_SPATIAL_INDEX, params, Boolean.class); Boolean isEnableSpatialIndex = (Boolean) ENABLE_SPATIAL_INDEX.lookUp(params); if (isEnableSpatialIndex == null) { isEnableSpatialIndex = Boolean.TRUE; } File dir = DataUtilities.urlToFile(url); if (dir != null && dir.isDirectory()) { return new DirectoryDataStore(DataUtilities.urlToFile(url), new ShpFileStoreFactory( this, params)); } else { ShpFiles shpFiles = new ShpFiles(url); boolean isLocal = shpFiles.isLocal(); boolean useMemoryMappedBuffer = isLocal && isMemoryMapped.booleanValue(); boolean enableIndex = isEnableSpatialIndex.booleanValue() && isLocal; boolean createIndex = isCreateSpatialIndex.booleanValue() && enableIndex; ShapefileDataStore store = new ShapefileDataStore(url); if(namespace != null) { store.setNamespaceURI(namespace.toString()); } store.setMemoryMapped(useMemoryMappedBuffer); store.setBufferCachingEnabled(cacheMemoryMaps); store.setCharset(dbfCharset); store.setTimeZone(dbfTimeZone); store.setIndexed(enableIndex); store.setIndexCreationEnabled(createIndex); return store; } }  String getDisplayName(); String getDescription(); Param[] getParametersInfo(); boolean isAvailable(); Map<Key, ?> getImplementationHints(); DataStore createDataStore(Map<String, Serializable> params); DataStore createNewDataStore(Map<String, Serializable> params); @Override boolean canProcess(Map params); boolean canProcess(URL f); @Override String[] getFileExtensions(); @Override FileDataStore createDataStore(URL url); @Override String getTypeName(URL url); static final Param URLP; static final Param NAMESPACEP; static final Param MEMORY_MAPPED; static final Param CACHE_MEMORY_MAPS; static final Param FILE_TYPE; static final Param CREATE_SPATIAL_INDEX; static final Param DBFCHARSET; static final Param FSTYPE; static final Param DBFTIMEZONE; static final Param ENABLE_SPATIAL_INDEX; }
@Test public void testQueryCapabilities() throws Exception { URL url = TestData.url(STATE_POP); Map params = new KVP( URLP.key,url ); DataStore dataStore = factory.createDataStore( params ); Name typeName = dataStore.getNames().get(0); SimpleFeatureSource featureSource = dataStore.getFeatureSource( typeName); QueryCapabilities caps = featureSource.getQueryCapabilities(); SortBy[] sortBy = new SortBy[]{SortBy.NATURAL_ORDER,}; assertTrue( "Natural", caps.supportsSorting( sortBy )); SimpleFeatureType schema = featureSource.getSchema(); String attr = schema.getDescriptor(1).getLocalName(); sortBy[0] = ff.sort( attr, SortOrder.ASCENDING ); assertTrue( "Sort "+attr, caps.supportsSorting( sortBy )); sortBy[0] = ff.sort( "the_geom", SortOrder.ASCENDING ); assertFalse( "Cannot sort the_geom", caps.supportsSorting( sortBy )); }
@Test public void testEnableIndexParameter() throws Exception { Map<String, Serializable> params; ShapefileDataStore ds; URL remoteUrl = TestData.url(STATE_POP); File f = copyShapefiles(STATE_POP); URL localUrl = f.toURI().toURL(); params = map(URLP.key, remoteUrl, ENABLE_SPATIAL_INDEX.key, true); ds = (ShapefileDataStore) factory.createDataStore(params); assertNotNull("Null datastore should not be returned", ds); assertTrue("should be a non indexed shapefile", ds instanceof org.geotools.data.shapefile.ShapefileDataStore); ds.dispose(); params = map(URLP.key, localUrl); ds = (ShapefileDataStore) factory.createDataStore(params); assertNotNull("Null datastore should not be returned", ds); assertTrue(ds.isIndexed()); assertTrue(ds.isIndexCreationEnabled()); ds.dispose(); params = map(URLP.key, localUrl, ENABLE_SPATIAL_INDEX.key, false); ds = (ShapefileDataStore) factory.createDataStore(params); assertNotNull("Null datastore should not be returned", ds); assertFalse(ds.isIndexed()); assertFalse(ds.isIndexCreationEnabled()); ds.dispose(); params = map(URLP.key, localUrl, ENABLE_SPATIAL_INDEX.key, true); ds = (ShapefileDataStore) factory.createDataStore(params); assertNotNull("Null datastore should not be returned", ds); assertTrue(ds.isIndexed()); assertTrue(ds.isIndexCreationEnabled()); ds.dispose(); }