Changeset 30738 in osm for applications/editors/josm/plugins/opendata/modules
- Timestamp:
- 2014-10-19T01:27:04+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/hydrologie/EauxDeSurfaceHandler.java
r30731 r30738 14 14 import java.util.regex.Pattern; 15 15 16 import org.openstreetmap.josm.Main; 16 17 import org.openstreetmap.josm.data.osm.DataSet; 17 18 import org.openstreetmap.josm.plugins.opendata.core.io.archive.DefaultArchiveHandler; … … 23 24 private static final String ZIP_PATTERN = "FR(.*)_SW"; 24 25 private static final String SHP_PATTERN = "FR_(.*)_SWB_.W_20......"; 25 26 26 27 private static final class WaterAgency { 27 28 public final String code; … … 34 35 } 35 36 } 36 37 37 38 private static final WaterAgency[] waterAgencies = new WaterAgency[]{ 38 39 new WaterAgency("A", "Escaut Somme", "Escaut-Somme-30381967"), … … 49 50 new WaterAgency("L", "La Réunion", "Réunion-30381991"), 50 51 }; 51 52 52 53 public EauxDeSurfaceHandler() { 53 54 setName("Eaux de surface"); 54 55 setArchiveHandler(new InternalZipHandler()); 55 56 } 56 57 57 58 @Override 58 59 public boolean acceptsFilename(String filename) { … … 63 64 return result; 64 65 } 65 66 66 67 @Override 67 68 public boolean acceptsUrl(String url) { … … 91 92 // TODO Auto-generated method stub 92 93 } 93 94 94 95 @Override 95 96 public List<Pair<String, URL>> getDataURLs() { … … 106 107 107 108 private Pair<String, URL> getDownloadURL(WaterAgency a) throws MalformedURLException { 108 return new Pair<>("SurfaceWater_"+a.name, new URL("http://www.rapportage.eaufrance.fr/sites/default/files/SIG/FR"+a.code+"_SW.zip")); 109 return new Pair<>("SurfaceWater_"+a.name, 110 new URL("http://www.rapportage.eaufrance.fr/sites/default/files/SIG/FR"+a.code+"_SW.zip")); 109 111 } 110 112 111 113 private class InternalZipHandler extends DefaultArchiveHandler { 112 114 @Override 113 115 public void notifyTempFileWritten(File file) { 114 if (file.getName().matches(SHP_PATTERN.replace("(.*)", "F")+"\\.prj")) {// Adour-Garonne .prj files cannot be parsed because they do not contain quotes...115 try{116 ;116 // Adour-Garonne .prj files cannot be parsed because they do not contain quotes... 117 if (file.getName().matches(SHP_PATTERN.replace("(.*)", "F")+"\\.prj")) { 118 try (BufferedReader reader = new BufferedReader(new FileReader(file))) { 117 119 String line = reader.readLine(); 118 reader.close();119 120 if (!line.contains("\"")) { 120 121 for (String term : new String[]{"GCS_ETRS_1989", "D_ETRS_1989", "GRS_1980", "Greenwich", "Degree"}) { 121 122 line = line.replace(term, "\""+term+"\""); 122 123 } 123 BufferedWriter writer = new BufferedWriter(new FileWriter(file)) ;124 writer.write(line); 125 writer.close();124 try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { 125 writer.write(line); 126 } 126 127 } 127 128 } catch (Exception e) { 128 e.printStackTrace();129 Main.error(e); 129 130 } 130 131 }
Note:
See TracChangeset
for help on using the changeset viewer.