public static FileData createFromFile(File file) throws IOException { if (file.isDirectory()) { return new Directory(file); } if (new VFSWorker().canHandle(file)) { return new Archive(file); } return new SpatialFile(file); } public File getFile() {
File file(ImportData data) { //try file based File f = null; if (data instanceof SpatialFile) { f = ((SpatialFile) data).getFile(); } if (data instanceof Directory) { f = ((Directory) data).getFile(); } return f; }
public SpatialFile(SpatialFile other) { super(other); this.prjFile = other.getPrjFile(); this.suppFiles.addAll(other.getSuppFiles()); }
/** * Creates a new spatial file. * * @param f The raw file. * @param format The spatial format of the file. */ protected SpatialFile newSpatialFile(File f, DataFormat format) { SpatialFile sf = new SpatialFile(f); sf.setFormat(format); return sf; }
@Override public void cleanup() throws IOException { File parentFolder = (file.isFile() ? file.getParentFile() : null); for (File file : allFiles()) { cleanupFile(file); } if (parentFolder != null && parentFolder.exists() && parentFolder.isDirectory()) { IOUtils.delete(parentFolder); } }
@Test public void testCreateContextSingleFile() throws Exception { File dir = unpack("shape/archsites_epsg_prj.zip"); SpatialFile file = new SpatialFile(new File(dir, "archsites.shp")); file.prepare(); ImportContext context = importer.createContext(file); assertEquals(1, context.getTasks().size()); ImportTask task = context.getTasks().get(0); assertEquals(file, task.getData()); }
public void testSingleSpatialFile() throws Exception { File dir = unpack("shape/archsites_epsg_prj.zip"); Directory d = new Directory(dir); d.prepare(); List<FileData> files = d.getFiles(); assertEquals(1, files.size()); assertTrue(files.get(0) instanceof SpatialFile); SpatialFile spatial = (SpatialFile) files.get(0); assertEquals("shp", FilenameUtils.getExtension(spatial.getFile().getName())); assertNotNull(spatial.getPrjFile().getName()); assertEquals("prj", FilenameUtils.getExtension(spatial.getPrjFile().getName())); assertEquals(2, spatial.getSuppFiles().size()); Set<String> exts = new HashSet<String>(Arrays.asList("shx", "dbf")); for (File supp : spatial.getSuppFiles()) { exts.remove(FilenameUtils.getExtension(supp.getName())); } assertTrue(exts.isEmpty()); }
public void fixPrjFile() throws IOException { CoordinateReferenceSystem crs = readPrjToCRS(); if (crs == null) { return; } try { CoordinateReferenceSystem epsgCrs = null; Integer epsgCode = EPSG_LOOKUP_CACHE.lookupEPSGCode(crs); if (epsgCode != null) { epsgCrs = CRS.decode("EPSG:" + epsgCode); } if (epsgCrs != null) { String epsgWKT = epsgCrs.toWKT(); FileUtils.writeStringToFile(getPrjFile(), epsgWKT); } } catch (FactoryException e) { throw (IOException) new IOException().initCause(e); } }
public CoordinateReferenceSystem readPrjToCRS() throws IOException { File prj = getPrjFile(); if (prj == null || !prj.exists()) { return null; } String wkt = FileUtils.readFileToString(prj); try { return CRS.parseWKT(wkt); } catch (Exception e) { throw (IOException) new IOException().initCause(e); } }
public void testMosaicAuxillaryFiles() throws Exception { File unpack = ImporterTestUtils.unpack("mosaic/bm.zip"); // all types of junk! String[] aux = new String[] {"aux", "rrd", "xml", "tif.aux.xml", "tfw"}; File[] tifs = unpack.listFiles(); for (int i = 0; i < tifs.length; i++) { File file = tifs[i]; for (int j = 0; j < aux.length; j++) { new File(unpack, file.getName().replace("tif", aux[j])).createNewFile(); } } Mosaic m = new Mosaic(unpack); m.prepare(); assertEquals(4, m.getFiles().size()); for (int i = 0; i < m.getFiles().size(); i++) { assertEquals("GeoTIFF", m.getFiles().get(1).getFormat().getName()); } // make sure the junk was actually picked up for (FileData f : m.getFiles()) { assertEquals(aux.length, ((SpatialFile) f).getSuppFiles().size()); } }
SpatialFile file = new SpatialFile(new File(dir, "archsites.shp")); file.prepare();
/** * Creates a new spatial file. * * @param f The raw file. * @param format The spatial format of the file. */ protected SpatialFile newSpatialFile(File f, DataFormat format) { SpatialFile sf = new SpatialFile(f); sf.setFormat(format); return sf; }
public void fixPrjFile() throws IOException { CoordinateReferenceSystem crs = readPrjToCRS(); if (crs == null) { return; } try { CoordinateReferenceSystem epsgCrs = null; Integer epsgCode = EPSG_LOOKUP_CACHE.lookupEPSGCode(crs); if (epsgCode != null) { epsgCrs = CRS.decode("EPSG:" + epsgCode); } if (epsgCrs != null) { String epsgWKT = epsgCrs.toWKT(); FileUtils.writeStringToFile(getPrjFile(), epsgWKT); } } catch (FactoryException e) { throw (IOException) new IOException().initCause(e); } }
public CoordinateReferenceSystem readPrjToCRS() throws IOException { File prj = getPrjFile(); if (prj == null || !prj.exists()) { return null; } String wkt = FileUtils.readFileToString(prj); try { return CRS.parseWKT(wkt); } catch (Exception e) { throw (IOException) new IOException().initCause(e); } }
fixPrjFile(); } catch (Exception e) { LOGGER.log(Level.WARNING, "Error fixing prj file", e);
public static FileData createFromFile(File file) throws IOException { if (file.isDirectory()) { return new Directory(file); } if (new VFSWorker().canHandle(file)) { return new Archive(file); } return new SpatialFile(file); }
SpatialFile file = new SpatialFile(new File(dir, "archsites.shp")); file.prepare(); file = new SpatialFile(new File(dir, "archsites.shp")); file.prepare();