public SpatialFile(SpatialFile other) { super(other); this.prjFile = other.getPrjFile(); this.suppFiles.addAll(other.getSuppFiles()); }
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 SpatialFile(SpatialFile other) { super(other); this.prjFile = other.getPrjFile(); this.suppFiles.addAll(other.getSuppFiles()); }
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 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 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 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()); }