format = DataFormat.lookup(file);
format = DataFormat.lookup(file);
DataFormat format = DataFormat.lookup(f);
DataFormat format = DataFormat.lookup(f);
/** Loads the available tables from this database. */ @Override public void prepare(ProgressMonitor m) throws IOException { tables = new ArrayList<Table>(); DataStoreFactorySpi factory = (DataStoreFactorySpi) DataStoreUtils.aquireFactory(parameters); if (factory == null) { throw new IOException("Unable to find data store for specified parameters"); } m.setTask("Loading tables"); DataStore store = factory.createDataStore(parameters); if (store == null) { throw new IOException("Unable to create data store from specified parameters"); } format = DataFormat.lookup(parameters); try { for (String typeName : store.getTypeNames()) { Table tbl = new Table(typeName, this); tbl.setFormat(format); tables.add(tbl); } } finally { // TODO: cache the datastore for subsquent calls store.dispose(); } }
/** * Loads the available tables from this database. */ @Override public void prepare(ProgressMonitor m) throws IOException { tables = new ArrayList<Table>(); DataStoreFactorySpi factory = (DataStoreFactorySpi) DataStoreUtils.aquireFactory(parameters); if (factory == null) { throw new IOException("Unable to find data store for specified parameters"); } m.setTask("Loading tables"); DataStore store = factory.createDataStore(parameters); if (store == null) { throw new IOException("Unable to create data store from specified parameters"); } format = DataFormat.lookup(parameters); try { for (String typeName : store.getTypeNames()) { Table tbl = new Table(typeName, this); tbl.setFormat(format); tables.add(tbl); } } finally { //TODO: cache the datastore for subsquent calls store.dispose(); } }
@Test public void testLookupShapefile() throws Exception { DataFormat format = DataFormat.lookup(new File(tmpDir(), "foo.shp")); assertNotNull("No format found for shape files", format); String name = format.getName(); assertEquals("Shapefile format not found", "Shapefile", name); }
@Test public void testLookupTiff() throws Exception { File dir = unpack("geotiff/EmissiveCampania.tif.bz2"); File tif = new File(dir, "EmissiveCampania.tif"); DataFormat format = DataFormat.lookup(tif); assertNotNull("No format found for tif", format); String name = format.getName(); assertEquals("Tif format not found", "GeoTIFF", name); }
@Test public void testLookupCSV() throws Exception { DataFormat format = DataFormat.lookup(new File(tmpDir(), "foo.csv")); assertNotNull("No format found for csv files", format); String name = format.getName(); assertEquals("CSV format not found", "CSV", name); }
@Test public void testLookupKML() throws Exception { File kmlFile = new File(tmpDir(), "foo.kml"); FileUtils.touch(kmlFile); DataFormat format = DataFormat.lookup(kmlFile); assertNotNull("No format found for kml files", format); String name = format.getName(); assertEquals("KML format not found", "KML", name); } }
@Override public void apply(ImportTask task, ImportData data) throws Exception { // let the transform run super.apply(task, data); // see if we need to update the layer definition, we just changed the CRS after all LayerInfo layer = task.getLayer(); ResourceInfo resource = layer.getResource(); String originalSRS = resource.getSRS(); // do so only if it's a direct import if (layer.getId() != null || resource == null || resource.getCatalog() == null) { return; } DataFormat format = DataFormat.lookup(((FileData) data).getFile()); List<ImportTask> tasks = format.list(data, resource.getCatalog(), new ProgressMonitor()); if (tasks == null || tasks.isEmpty()) { return; } LayerInfo updatedLayer = tasks.get(0).getLayer(); ResourceInfo updatedResource = updatedLayer.getResource(); String updatedSRS = updatedResource.getSRS(); // check if the layer srs is incompatible with the one we just reprojected to, update if // necessary if (originalSRS == null || (!originalSRS.equals(updatedSRS) && updatedSRS != null)) { resource.setSRS(updatedSRS); resource.setNativeCRS(updatedResource.getNativeCRS()); resource.setNativeBoundingBox(updatedResource.getNativeBoundingBox()); resource.setLatLonBoundingBox(updatedResource.getLatLonBoundingBox()); } }