Changeset 30908 in osm for applications/editors/josm
- Timestamp:
- 2015-01-11T21:50:45+01:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/opendata
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/administration/GeoFlaHandler.java
r30731 r30908 8 8 9 9 import org.apache.commons.lang3.text.WordUtils; 10 import org.openstreetmap.josm.Main; 10 11 import org.openstreetmap.josm.data.coor.EastNorth; 11 12 import org.openstreetmap.josm.data.coor.LatLon; … … 18 19 import org.openstreetmap.josm.tools.Pair; 19 20 21 /** 22 * Handler for GeoFla 2.0. Compatibility for previous version 1.1 has been dropped. 23 * See http://professionnels.ign.fr/sites/default/files/DC_GEOFLA_2-0.pdf 24 */ 20 25 public class GeoFlaHandler extends DataGouvDataSetHandler { 21 26 27 private static final String ADMIN_LEVEL = "admin_level"; 28 29 /** 30 * Constructs a new {@code GeoFlaHandler}. 31 */ 22 32 public GeoFlaHandler() { 23 super();24 33 setName("GEOFLA®"); 25 34 getShpHandler().setPreferMultipolygonToSimpleWay(true); … … 27 36 setLocalPortalURL("http://professionnels.ign.fr/geofla#tab-3"); 28 37 } catch (MalformedURLException e) { 29 e.printStackTrace();38 Main.error(e); 30 39 } 31 40 } … … 74 83 p.put("name", deptName); 75 84 } else if (isCommuneFile(filename)) { 76 p.put("name", WordUtils.capitalizeFully(getAndRemoveIgnoreCase(p, "NOM_COM M")));85 p.put("name", WordUtils.capitalizeFully(getAndRemoveIgnoreCase(p, "NOM_COM"))); 77 86 replace(p, "INSEE_COM", "ref:INSEE"); 78 87 } 88 getAndRemoveIgnoreCase(p, "NOM_REG"); 89 replace(p, "POPULATION", "population"); 79 90 p.put("boundary", "administrative"); 80 91 String nature = getIgnoreCase(p, "Nature"); 81 92 if ("Frontière internationale".equalsIgnoreCase(nature) || "Limite côtière".equalsIgnoreCase(nature)) { 82 p.put( "admin_level", "2");93 p.put(ADMIN_LEVEL, "2"); 83 94 } else if ("Limite de région".equalsIgnoreCase(nature)) { 84 p.put( "admin_level", "4");95 p.put(ADMIN_LEVEL, "4"); 85 96 } else if (isDepartementFile(filename) || "Limite de département".equalsIgnoreCase(nature)) { 86 p.put( "admin_level", "6");97 p.put(ADMIN_LEVEL, "6"); 87 98 } else if(isArrondissementFile(filename) || "Limite d'arrondissement".equalsIgnoreCase(nature)) { 88 p.put( "admin_level", "7");99 p.put(ADMIN_LEVEL, "7"); 89 100 } else if(isCommuneFile(filename)) { 90 p.put( "admin_level", "8");101 p.put(ADMIN_LEVEL, "8"); 91 102 } 92 103 if (p instanceof Relation) { … … 97 108 Node centroid = new Node(llCentroid); 98 109 ds.addPrimitive(centroid); 99 //centroid.put("name", p.get("name"));100 110 if (p instanceof Relation) { 101 111 ((Relation) p).addMember(new RelationMember("centroid", centroid)); … … 106 116 Node chefLieu = new Node(llChefLieu); 107 117 ds.addPrimitive(chefLieu); 108 //chefLieu.put("Code_chf", getAndRemoveIgnoreCase(p, "Code_chf", "Code_Chef_Lieu"));109 118 String name = WordUtils.capitalizeFully(getAndRemoveIgnoreCase(p, "Nom_chf", "Nom_Chef_lieu")); 110 if (isArrondissementFile(filename)) { 111 p.put("name", name); 112 } 113 chefLieu.put("name", name); 119 if (name != null) { 120 if (isArrondissementFile(filename)) { 121 p.put("name", name); 122 } 123 chefLieu.put("name", name); 124 } 125 String population = p.get("population"); 126 if (population != null) { 127 try { 128 int pop = Integer.parseInt(population); 129 if (pop < 2000) { 130 chefLieu.put("place", "village"); 131 } else if (pop < 100000) { 132 chefLieu.put("place", "town"); 133 } else { 134 chefLieu.put("place", "city"); 135 } 136 } catch (NumberFormatException e) { 137 Main.warn("Invalid population: "+population); 138 } 139 } 114 140 if (p instanceof Relation) { 115 141 ((Relation) p).addMember(new RelationMember("admin_centre", chefLieu)); … … 166 192 dptCode = "976"; 167 193 } else { 168 System.err.println("Unknown French department: "+dptName);169 } 170 } 171 return getLatLonByDptCode(new EastNorth(Double.parseDouble(x) *100.0, Double.parseDouble(y)*100.0), dptCode, false);194 Main.error("Unknown French department: "+dptName); 195 } 196 } 197 return getLatLonByDptCode(new EastNorth(Double.parseDouble(x), Double.parseDouble(y)), dptCode, false); 172 198 } catch (NumberFormatException e) { 173 System.err.println(e.getMessage());199 Main.error(e); 174 200 } 175 201 } … … 178 204 179 205 private Pair<String, URL> getGeoflaURL(String name, String urlSuffix) throws MalformedURLException { 180 return new Pair<>(name, new URL("http ://professionnels.ign.fr/sites/default/files/"+urlSuffix));206 return new Pair<>(name, new URL("https://wxs-telechargement.ign.fr/oikr5jryiph0iwhw36053ptm/telechargement/inspire/"+urlSuffix)); 181 207 } 182 208 … … 185 211 List<Pair<String, URL>> result = new ArrayList<>(); 186 212 try { 187 result.add(getGeoflaURL("Départements France métropolitaine et Corse", "GEOFLADept_FR_Corse_AV_L93.zip")); 188 result.add(getGeoflaURL("Départements France entière", "FR_DOM_Mayotte_shp_WGS84.zip")); 189 // FIXME: tar.gz files 190 /*result.add(getGeoflaURL("Communes France métropolitaine", "531/266/5312664/GEOFLA_1-1_SHP_LAMB93_FR-ED111.tar.gz")); 191 result.add(getGeoflaURL("Communes Guadeloupe", "531/265/5312650/GEOFLA_1-1_SHP_UTM20W84_GP-ED111.tar.gz")); 192 result.add(getGeoflaURL("Communes Martinique", "531/265/5312653/GEOFLA_1-1_SHP_UTM20W84_MQ-ED111.tar.gz")); 193 result.add(getGeoflaURL("Communes Guyane", "531/265/5312657/GEOFLA_1-1_SHP_UTM22RGFG95_GF-ED111.tar.gz")); 194 result.add(getGeoflaURL("Communes Réunion", "531/266/5312660/GEOFLA_1-1_SHP_RGR92UTM40S_RE-ED111.tar.gz")); 195 result.add(getGeoflaURL("Communes Mayotte", "531/275/5312753/GEOFLA_1-1_SHP_RGM04UTM38S_YT-ED111.tar.gz"));*/ 213 // Communes 214 result.add(getGeoflaURL("2014 Communes France Métropolitaine", "GEOFLA_THEME-COMMUNE_2014_GEOFLA_2-0_COMMUNE_SHP_LAMB93_FXX_2014-12-05/file/GEOFLA_2-0_COMMUNE_SHP_LAMB93_FXX_2014-12-05.7z")); 215 result.add(getGeoflaURL("2014 Communes Guadeloupe", "GEOFLA_THEME-COMMUNE_2014_GEOFLA_2-0_COMMUNE_SHP_UTM20W84GUAD_D971_2014-12-08/file/GEOFLA_2-0_COMMUNE_SHP_UTM20W84GUAD_D971_2014-12-08.7z")); 216 result.add(getGeoflaURL("2014 Communes Martinique", "GEOFLA_THEME-COMMUNE_2014_GEOFLA_2-0_COMMUNE_SHP_UTM20W84MART_D972_2014-12-08/file/GEOFLA_2-0_COMMUNE_SHP_UTM20W84MART_D972_2014-12-08.7z")); 217 result.add(getGeoflaURL("2014 Communes Guyane", "GEOFLA_THEME-COMMUNE_2014_GEOFLA_2-0_COMMUNE_SHP_UTM22RGFG95_D973_2014-12-05/file/GEOFLA_2-0_COMMUNE_SHP_UTM22RGFG95_D973_2014-12-05.7z")); 218 result.add(getGeoflaURL("2014 Communes Réunion", "GEOFLA_THEME-COMMUNE_2014_GEOFLA_2-0_COMMUNE_SHP_RGR92UTM40S_D974_2014-12-05/file/GEOFLA_2-0_COMMUNE_SHP_RGR92UTM40S_D974_2014-12-05.7z")); 219 result.add(getGeoflaURL("2014 Communes Mayotte", "GEOFLA_THEME-COMMUNE_2014_GEOFLA_2-0_COMMUNE_SHP_RGM04UTM38S_D976_2014-12-05/file/GEOFLA_2-0_COMMUNE_SHP_RGM04UTM38S_D976_2014-12-05.7z")); 220 // Cantons 221 result.add(getGeoflaURL("2014 Cantons France Métropolitaine", "GEOFLA_THEME-CANTON_2014_GEOFLA_2-0_CANTON_SHP_LAMB93_FXX_2014-12-05/file/GEOFLA_2-0_CANTON_SHP_LAMB93_FXX_2014-12-05.7z")); 222 result.add(getGeoflaURL("2014 Cantons Guadeloupe", "GEOFLA_THEME-CANTON_2014_GEOFLA_2-0_CANTON_SHP_UTM20W84GUAD_D971_2014-12-08/file/GEOFLA_2-0_CANTON_SHP_UTM20W84GUAD_D971_2014-12-08.7z")); 223 result.add(getGeoflaURL("2014 Cantons Martinique", "GEOFLA_THEME-CANTON_2014_GEOFLA_2-0_CANTON_SHP_UTM20W84MART_D972_2014-12-08/file/GEOFLA_2-0_CANTON_SHP_UTM20W84MART_D972_2014-12-08.7z")); 224 result.add(getGeoflaURL("2014 Cantons Guyane", "GEOFLA_THEME-CANTON_2014_GEOFLA_2-0_CANTON_SHP_UTM22RGFG95_D973_2014-12-05/file/GEOFLA_2-0_CANTON_SHP_UTM22RGFG95_D973_2014-12-05.7z")); 225 result.add(getGeoflaURL("2014 Cantons Réunion", "GEOFLA_THEME-CANTON_2014_GEOFLA_2-0_CANTON_SHP_RGR92UTM40S_D974_2014-12-05/file/GEOFLA_2-0_CANTON_SHP_RGR92UTM40S_D974_2014-12-05.7z")); 226 result.add(getGeoflaURL("2014 Cantons Mayotte", "GEOFLA_THEME-CANTON_2014_GEOFLA_2-0_CANTON_SHP_RGM04UTM38S_D976_2014-12-05/file/GEOFLA_2-0_CANTON_SHP_RGM04UTM38S_D976_2014-12-05.7z")); 227 // Arrondissements 228 result.add(getGeoflaURL("2014 Arrondissements France Métropolitaine", "GEOFLA_THEME-ARRONDISSEMENT_2014_GEOFLA_2-0_ARRONDISSEMENT_SHP_LAMB93_FXX_2014-12-05/file/GEOFLA_2-0_ARRONDISSEMENT_SHP_LAMB93_FXX_2014-12-05.7z")); 229 result.add(getGeoflaURL("2014 Arrondissements Guadeloupe", "GEOFLA_THEME-ARRONDISSEMENT_2014_GEOFLA_2-0_ARRONDISSEMENT_SHP_UTM20W84GUAD_D971_2014-12-08/file/GEOFLA_2-0_ARRONDISSEMENT_SHP_UTM20W84GUAD_D971_2014-12-08.7z")); 230 result.add(getGeoflaURL("2014 Arrondissements Martinique", "GEOFLA_THEME-ARRONDISSEMENT_2014_GEOFLA_2-0_ARRONDISSEMENT_SHP_UTM20W84MART_D972_2014-12-08/file/GEOFLA_2-0_ARRONDISSEMENT_SHP_UTM20W84MART_D972_2014-12-08.7z")); 231 result.add(getGeoflaURL("2014 Arrondissements Guyane", "GEOFLA_THEME-ARRONDISSEMENT_2014_GEOFLA_2-0_ARRONDISSEMENT_SHP_UTM22RGFG95_D973_2014-12-05/file/GEOFLA_2-0_ARRONDISSEMENT_SHP_UTM22RGFG95_D973_2014-12-05.7z")); 232 result.add(getGeoflaURL("2014 Arrondissements Réunion", "GEOFLA_THEME-ARRONDISSEMENT_2014_GEOFLA_2-0_ARRONDISSEMENT_SHP_RGR92UTM40S_D974_2014-12-05/file/GEOFLA_2-0_ARRONDISSEMENT_SHP_RGR92UTM40S_D974_2014-12-05.7z")); 233 // Départements 234 result.add(getGeoflaURL("2014 Départements France Métropolitaine", "GEOFLA_THEME-DEPARTEMENTS_2014_GEOFLA_2-0_DEPARTEMENT_SHP_LAMB93_FXX_2014-12-05/file/GEOFLA_2-0_DEPARTEMENT_SHP_LAMB93_FXX_2014-12-05.7z")); 235 result.add(getGeoflaURL("2014 Départements Guadeloupe", "GEOFLA_THEME-DEPARTEMENTS_2014_GEOFLA_2-0_DEPARTEMENT_SHP_UTM20W84GUAD_D971_2014-12-08/file/GEOFLA_2-0_DEPARTEMENT_SHP_UTM20W84GUAD_D971_2014-12-08.7z")); 236 result.add(getGeoflaURL("2014 Départements Martinique", "GEOFLA_THEME-DEPARTEMENTS_2014_GEOFLA_2-0_DEPARTEMENT_SHP_UTM20W84MART_D972_2014-12-08/file/GEOFLA_2-0_DEPARTEMENT_SHP_UTM20W84MART_D972_2014-12-08.7z")); 237 result.add(getGeoflaURL("2014 Départements Guyane", "GEOFLA_THEME-DEPARTEMENTS_2014_GEOFLA_2-0_DEPARTEMENT_SHP_UTM22RGFG95_D973_2014-12-05/file/GEOFLA_2-0_DEPARTEMENT_SHP_UTM22RGFG95_D973_2014-12-05.7z")); 238 result.add(getGeoflaURL("2014 Départements Réunion", "GEOFLA_THEME-DEPARTEMENTS_2014_GEOFLA_2-0_DEPARTEMENT_SHP_RGR92UTM40S_D974_2014-12-05/file/GEOFLA_2-0_DEPARTEMENT_SHP_RGR92UTM40S_D974_2014-12-05.7z")); 239 result.add(getGeoflaURL("2014 Départements Mayotte", "GEOFLA_THEME-DEPARTEMENTS_2014_GEOFLA_2-0_DEPARTEMENT_SHP_RGM04UTM38S_D976_2014-12-05/file/GEOFLA_2-0_DEPARTEMENT_SHP_RGM04UTM38S_D976_2014-12-05.7z")); 196 240 } catch (MalformedURLException e) { 197 e.printStackTrace();241 Main.error(e); 198 242 } 199 243 return result; -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/SevenZipReader.java
r30738 r30908 33 33 34 34 private final IInArchive archive = new Handler(); 35 35 36 36 public SevenZipReader(InputStream in, AbstractDataSetHandler handler, boolean promptUser) throws IOException { 37 37 super(handler, handler != null ? handler.getArchiveHandler() : null, promptUser); … … 41 41 Utils.copyStream(in, out); 42 42 } 43 try (IInStream random = new MyRandomAccessFile(tmpFile.getPath(), "r")) { 44 if (archive.Open(random) != 0) { 45 String message = "Unable to open 7z archive: "+tmpFile.getPath(); 46 Main.warn(message); 47 if (!tmpFile.delete()) { 48 tmpFile.deleteOnExit(); 49 } 50 throw new IOException(message); 43 // random must be kept open for later extracting 44 @SuppressWarnings("resource") 45 IInStream random = new MyRandomAccessFile(tmpFile.getPath(), "r"); 46 if (archive.Open(random) != 0) { 47 String message = "Unable to open 7z archive: "+tmpFile.getPath(); 48 Main.warn(message); 49 random.close(); 50 if (!tmpFile.delete()) { 51 tmpFile.deleteOnExit(); 51 52 } 53 throw new IOException(message); 52 54 } 53 55 } 54 55 public static DataSet parseDataSet(InputStream in, AbstractDataSetHandler handler, ProgressMonitor instance, boolean promptUser) 56 57 public static DataSet parseDataSet(InputStream in, AbstractDataSetHandler handler, ProgressMonitor instance, boolean promptUser) 56 58 throws IOException, XMLStreamException, FactoryConfigurationError, JAXBException { 57 59 return new SevenZipReader(in, handler, promptUser).parseDoc(instance); 58 60 } 59 61 60 public static Map<File, DataSet> parseDataSets(InputStream in, AbstractDataSetHandler handler, ProgressMonitor instance, boolean promptUser) 62 public static Map<File, DataSet> parseDataSets(InputStream in, AbstractDataSetHandler handler, ProgressMonitor instance, boolean promptUser) 61 63 throws IOException, XMLStreamException, FactoryConfigurationError, JAXBException { 62 64 return new SevenZipReader(in, handler, promptUser).parseDocs(instance); … … 68 70 } 69 71 70 @Override protected void extractArchive(File temp, List<File> candidates) throws IOException, FileNotFoundException { 72 @Override 73 protected void extractArchive(File temp, List<File> candidates) throws IOException, FileNotFoundException { 71 74 archive.Extract(null, -1, IInArchive.NExtract_NAskMode_kExtract, new ExtractCallback(archive, temp, candidates)); 75 archive.close(); 72 76 } 73 77 74 78 private class ExtractCallback extends ArchiveExtractCallback { 75 79 private final List<File> candidates; 76 80 77 81 public ExtractCallback(IInArchive archive, File tempDir, List<File> candidates) { 78 82 Init(archive); … … 81 85 } 82 86 83 @Override 87 @Override 84 88 public int GetStream(int index, OutputStream[] outStream, int askExtractMode) throws IOException { 85 89 int res = super.GetStream(index, outStream, askExtractMode);
Note:
See TracChangeset
for help on using the changeset viewer.