BufferedReader reader = null; try { ds = DataStoreFinder.getDataStore(filters); if (ds == null) { final String warning =
public DataStore dataStore(Name name) { String localName = name.getLocalPart(); DataStore ds = map.get(localName); if (ds != null) return ds; try { Map<String, Serializable> params = getMapFromPropetryLocation(localName); ds = DataStoreFinder.getDataStore(params); } catch (IOException ex) { log.log(Level.SEVERE, ex.getMessage(), ex); return null; } map.put(localName, ds); return ds; }
public GTDataStoreFootprintProvider( Map<String, Serializable> params, String typeName, Filter filter) throws IOException { store = DataStoreFinder.getDataStore(params); if (store == null) { throw new IOException("Coould not create footprint data store from params: " + params); } if (typeName != null) { this.featureSource = store.getFeatureSource(typeName); } else { this.featureSource = store.getFeatureSource("footprints"); } this.filter = filter; }
/** * Builds a datastore from a property file configuration, using GeoTools default convention as * well as ImageMosaic own one */ public static DataStore getDataStore(Properties configuration) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException { // first try out the default GeoTools approach final DataStore dataStore = DataStoreFinder.getDataStore(configuration); if (dataStore == null) { // use ImageMosaic bizarre own way final String spiClass = (String) configuration.get("SPI"); DataStoreFactorySpi spi = (DataStoreFactorySpi) Class.forName(spiClass).newInstance(); Map<String, Serializable> datastoreParams = Utils.filterDataStoreParams(configuration, spi); return spi.createDataStore(datastoreParams); } return null; }
/** * Load a quick repository from a properties file. * * <p>This is useful for test cases; the format is: * * <pre><code> * nameA=param=value,param2=value2,... * nameB=param=value,param2=value2,... * </code></pre> * * @throws IOException * @throws FileNotFoundException */ public void load(File propertiesFile) throws Exception { Properties properties = new Properties(); properties.load(new FileInputStream(propertiesFile)); for (Iterator i = properties.entrySet().iterator(); i.hasNext(); ) { Map.Entry<String, String> entry = (Map.Entry) i.next(); String name = (String) entry.getKey(); String definition = (String) entry.getValue(); Map<String, Serializable> params = definition(definition); DataStore dataStore = DataStoreFinder.getDataStore(params); register(name, dataStore); } }
private SimpleFeatureIterator getFeatureIterator() throws IOException { try { Map<String, Object> map = new HashMap<String, Object>(); map.put("url", shapeFileUrl); DataStore shapefile = DataStoreFinder.getDataStore(map); int index = shapeFileUrl.getPath().lastIndexOf('/'); int startIndex = (index == -1) ? 0 : (index + 1); index = shapeFileUrl.getPath().lastIndexOf('.'); int endIndex = (index == -1) ? shapeFileUrl.getPath().length() : index; String layerName = shapeFileUrl.getPath().substring(startIndex, endIndex); SimpleFeatureSource contents = shapefile.getFeatureSource(layerName); featureColl = contents.getFeatures(); total = featureColl.size(); logTotalInfo(); return featureColl.features(); } catch (IOException ex) { logError(ex, "Cannot open shape file"); throw ex; } }
public void createSchema(SimpleFeatureType featureType) throws IOException { File f = new File(cache.directory, featureType.getTypeName() + ".shp"); Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put("url", URLs.fileToUrl(f)); params.put("filetype", "shapefile"); DataStore ds = null; try { ds = DataStoreFinder.getDataStore(params); if (ds != null) { ds.createSchema(featureType); ds.dispose(); cache.refreshCacheContents(); } } catch (Exception e) { throw (IOException) new IOException("Error creating new data store").initCause(e); } if (ds == null) { throw new IOException("Could not find the shapefile data store in the classpath"); } }
public void testGetDataStore() throws IOException { DataStore dataStore; Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put(MOCK_DS_PARAM_KEY, MockUnavailableDataStoreFactory.class); dataStore = DataStoreFinder.getDataStore(params); assertNull(dataStore); params.put(MOCK_DS_PARAM_KEY, MockDataStoreFactory.class); dataStore = DataStoreFinder.getDataStore(params); assertSame(MOCK_DATASTORE, dataStore); }
public void testJNDIDataSource() throws Exception { ((JDBCJNDITestSetup) setup).setupJNDIEnvironment(getDataStoreFactory()); HashMap params = new HashMap(); String dbtype = setup.createDataStoreFactory().getDatabaseID(); params.put(JDBCDataStoreFactory.NAMESPACE.key, "http://www.geotools.org/test"); params.put(JDBCDataStoreFactory.DBTYPE.key, dbtype); params.put(JDBCJNDIDataStoreFactory.JNDI_REFNAME.key, "ds"); JDBCDataStore dataStore = null; try { dataStore = (JDBCDataStore) DataStoreFinder.getDataStore(params); try (Connection con = dataStore.getDataSource().getConnection()) { assertTrue(con != null); assertFalse(con.isClosed()); } } finally { if (dataStore != null) { dataStore.dispose(); } } }
@SuppressWarnings({ "rawtypes" }) public static DataStore getDataStore(Map connectionParams) { try { final DataStore dataStore = DataStoreFinder.getDataStore(connectionParams); return dataStore; } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } return null; }
private Shapefile(File file, double bufferDistance) { this.bufferDistance = bufferDistance; try { Map<String, Serializable> map = new HashMap<>(); map.put("url", file.toURI().toURL()); datastore = DataStoreFinder.getDataStore(map); } catch (IOException e) { throw new RuntimeException(e); } }
@Override protected void connect() throws Exception { // create the test harness if (setup == null) { setup = createTestSetup(); } setup.setFixture(fixture); setup.setUp(); // initialize the database setup.initializeDatabase(); // initialize the data setup.setUpData(); // create the dataStore HashMap params = createDataStoreFactoryParams(); try { HashMap temp = (HashMap) params.clone(); temp.putAll(fixture); dataStore = (JDBCDataStore) DataStoreFinder.getDataStore(temp); } catch (Exception e) { // ignore } if (dataStore == null) { JDBCDataStoreFactory factory = setup.createDataStoreFactory(); dataStore = factory.createDataStore(params); } setup.setUpDataStore(dataStore); dialect = dataStore.getSQLDialect(); }
public static DataStore fileToDataStore(File file, String encoding) throws IOException { Map<String, Object> map = new HashMap<String, Object>(); try { map.put("url", file.toURI().toURL()); } catch (MalformedURLException e) { throw new IOException(e); } map.put(ShapefileDataStoreFactory.DBFCHARSET.getName(), encoding); return DataStoreFinder.getDataStore(map); }
public static DataStore fileToDataStore(File file, String encoding) throws IOException { Map<String, Object> map = new HashMap<String, Object>(); try { map.put("url", file.toURI().toURL()); } catch (MalformedURLException e) { throw new IOException(e); } map.put(ShapefileDataStoreFactory.DBFCHARSET.getName(), encoding); return DataStoreFinder.getDataStore(map); }
@SuppressWarnings("unchecked") private SimpleFeatureSource getFeatureSource(final URL shpfile) throws IOException { Map params = new HashMap<String, String>(); params.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key, "false"); params.put(ShapefileDataStoreFactory.URLP.key, shpfile); DataStore ds = DataStoreFinder.getDataStore(params); return ds.getFeatureSource(ds.getTypeNames()[0]); }
@Override public void run() { try { store = DataStoreFinder.getDataStore(params); refreshTable(); gui_progress.setString(BUNDLE.getString("waiting")); } catch (IOException ex) { store = null; gui_progress.setString(BUNDLE.getString("error")); } } };
@Override public void run() { try { store = DataStoreFinder.getDataStore(params); refreshTable(); gui_progress.setString(BUNDLE.getString("waiting")); } catch (IOException ex) { store = null; gui_progress.setString(BUNDLE.getString("error")); } } };
protected void setupDataStore() { Properties props = getFixture(); Map<Object, Object> params = props; try { datastore = DataStoreFinder.getDataStore(params); } catch (IOException e) { } if (datastore == null) { throw new RuntimeException("failed to create dataStore with \n " + props); } }
@Test public void testDataStoreFinder() throws Exception { Map<String, ? extends Serializable> params; DataStore dataStore; params = ImmutableMap.of(); dataStore = DataStoreFinder.getDataStore(params); assertNull(dataStore); params = ImmutableMap.of(REPOSITORY.key, repoDirectory); dataStore = DataStoreFinder.getDataStore(params); assertNotNull(dataStore); assertTrue(dataStore instanceof GeoGigDataStore); }
@Test public void featureStoreExample() throws Exception { Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put("file", statesfile); DataStore store = DataStoreFinder.getDataStore(params); SimpleFeatureSource featureSource = store.getFeatureSource("locations"); assertTrue("Modification not supported", (featureSource instanceof SimpleFeatureStore)); assertTrue("Temp files being left behind", cleanedup()); }