Changeset 33671 in osm for applications/editors/josm/plugins/cadastre-fr/src
- Timestamp:
- 2017-09-25T21:47:56+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/pci
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/pci/EdigeoPciImporter.java
r33642 r33671 13 13 import org.openstreetmap.josm.data.osm.DataSet; 14 14 import org.openstreetmap.josm.gui.io.importexport.OsmImporter; 15 import org.openstreetmap.josm.gui.layer.OsmDataLayer;16 15 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 17 16 import org.openstreetmap.josm.io.IllegalDataException; … … 24 23 25 24 static final ExtensionFileFilter EDIGEO_FILE_FILTER = new ExtensionFileFilter( 26 "thf ", "thf", tr("Cadastre Edigeo files") + " (*.thf)");25 "thf,tar.bz2", "thf", tr("Cadastre Edigeo files") + " (*.thf, *.tar.bz2)"); 27 26 28 27 protected File file; … … 38 37 public void importData(File file, ProgressMonitor progressMonitor) 39 38 throws IOException, IllegalDataException { 40 if (file != null) { 41 this.file = file; 42 } 39 this.file = file; 43 40 // Do not call super.importData because Compression.getUncompressedFileInputStream skips the first entry 44 41 try (InputStream in = new FileInputStream(file)) { … … 58 55 } 59 56 } 60 61 @Override62 protected OsmDataLayer createLayer(DataSet dataSet, File associatedFile, String layerName) {63 // FIXME: mapping pci => osm64 //DataSetUpdater.updateDataSet(dataSet, handler, associatedFile);65 return new OsmDataLayer(dataSet, layerName, associatedFile);66 }67 57 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/pci/EdigeoPciReader.java
r33665 r33671 2 2 package org.openstreetmap.josm.plugins.fr.cadastre.edigeo.pci; 3 3 4 import java.io.BufferedInputStream; 4 5 import java.io.File; 6 import java.io.FileOutputStream; 5 7 import java.io.IOException; 6 8 import java.io.InputStream; 9 import java.nio.file.Files; 7 10 import java.nio.file.Path; 8 11 import java.util.Arrays; … … 12 15 import java.util.Map.Entry; 13 16 17 import org.apache.commons.compress.archivers.tar.TarArchiveEntry; 18 import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; 19 import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; 20 import org.apache.commons.compress.utils.IOUtils; 14 21 import org.openstreetmap.josm.data.osm.DataSet; 15 22 import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy; … … 20 27 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF; 21 28 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileVEC; 29 import org.openstreetmap.josm.tools.Utils; 22 30 23 31 /** … … 180 188 181 189 DataSet parse(Path path, ProgressMonitor instance) throws IOException, ReflectiveOperationException { 182 DataSet data = new DataSet(); 183 data.setUploadPolicy(UploadPolicy.DISCOURAGED); 184 EdigeoFileTHF thf = new EdigeoFileTHF(path).read().fill(data); 185 data.setName(thf.getSupport().getBlockIdentifier()); 186 return data; 190 Path tmpDir = null; 191 Path thfPath = path; 192 try { 193 if (thfPath.toString().endsWith(".tar.bz2")) { 194 try (InputStream fin = Files.newInputStream(path); 195 BufferedInputStream in = new BufferedInputStream(fin); 196 BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(in); 197 TarArchiveInputStream tar = new TarArchiveInputStream(bzIn) 198 ) { 199 TarArchiveEntry entry; 200 tmpDir = Files.createTempDirectory(Utils.getJosmTempDir().toPath(), "cadastre"); 201 while ((entry = tar.getNextTarEntry()) != null) { 202 File file = tmpDir.resolve(entry.getName()).toFile(); 203 try (FileOutputStream out = new FileOutputStream(file)) { 204 if (IOUtils.copy(tar, out) < entry.getSize()) { 205 throw new IOException(String.format("Unable to write ''{0}'' entirely", file)); 206 } else if (file.toString().endsWith(".THF")) { 207 thfPath = file.toPath(); 208 } 209 } 210 } 211 } 212 } 213 DataSet data = new DataSet(); 214 data.setUploadPolicy(UploadPolicy.DISCOURAGED); 215 EdigeoFileTHF thf = new EdigeoFileTHF(thfPath).read().fill(data); 216 data.setName(thf.getSupport().getBlockIdentifier()); 217 return data; 218 } finally { 219 if (tmpDir != null) { 220 Utils.deleteDirectory(tmpDir.toFile()); 221 } 222 } 187 223 } 188 224
Note:
See TracChangeset
for help on using the changeset viewer.